Skip to content

Commit

Permalink
Recognise duplicates based on id, add title from response
Browse files Browse the repository at this point in the history
  • Loading branch information
mikozet committed Sep 5, 2023
1 parent bf603a8 commit 6cf1280
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/components/ActivityStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const ActivityStreamList = ({
acc,
{
data,
id,
hash,
createdAt,
type,
Expand Down Expand Up @@ -134,7 +135,7 @@ const ActivityStreamList = ({
? DateTime.fromISO(lastSeenAt) > DateTime.fromISO(createdAt)
: true;

const key = hash || transactionHash;
const key = hash || transactionHash || id;

const createdAtDate =
createdAt || DateTime.fromSeconds(timestamp).toISO();
Expand Down
4 changes: 1 addition & 3 deletions src/components/ActivityStreamItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const ActivityStreamItem = (props) => {
} = props.type !== 'NEWS' ? formatMessage(props) : props;

if (!formattedDate) {
// // TODO which one? data.createdAt || data.date
formattedDate = DateTime.fromISO(
props.data.createdAt || props.data.date,
).toFormat('dd.LL.yyyy');
Expand Down Expand Up @@ -143,8 +142,7 @@ const ActivityStreamItem = (props) => {
...data,
actor,
})
: // TODO remove || 'This is test title'
data.title?.en || 'This is test title';
: data.title?.en;
}, [actor, data, messageId]);

return (
Expand Down
4 changes: 1 addition & 3 deletions src/store/activity/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export function loadMoreActivitiesNews(options = {}) {

function checkForDuplicates(item) {
for (const newsItem of currentNews) {
if (newsItem.data.date === item.date) {
if (newsItem.id === item.id) {
return false;
}
}
Expand All @@ -386,7 +386,6 @@ export function loadMoreActivitiesNews(options = {}) {
let filteredNewsData = [];
let filterDuplicateNewsData = [];
let noMoreRecords = false;
let loopCounter = 0;

do {
let data = await core.news.getLatestNews(offset, PAGE_SIZE);
Expand All @@ -409,7 +408,6 @@ export function loadMoreActivitiesNews(options = {}) {
}

// we have values till present which are not duplicates - we add them to newsData which we want to display
// newsData.push(...filteredNewsData);
newsData.push(...filterDuplicateNewsData);
offset += PAGE_SIZE;
} while (!noMoreRecords && newsData.length < PAGE_SIZE);
Expand Down
11 changes: 5 additions & 6 deletions src/store/activity/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function mergeActivities(currentActivities, newActivities) {
const newActivity = Object.assign({}, initialStateActivity, {
createdAt: DateTime.fromSeconds(activity.timestamp).toISO(),
data: activity.data,
txHash: activity.transactionHash,
type: activity.type,
});

Expand Down Expand Up @@ -123,14 +122,14 @@ function mergeNews(currentActivities, newActivities) {
iconId: activity.iconId,
isActive: activity.isActive,
message: activity.message,
title: activity.title,
},
type: 'NEWS',
id: activity.id,
});

newActivity.hash = generateHash(newActivity);

const duplicateItem = currentActivities.find(
(item) => item.hash === newActivity.hash,
(item) => item.id === newActivity.id,
);
if (!duplicateItem) {
acc.push(newActivity);
Expand All @@ -140,8 +139,8 @@ function mergeNews(currentActivities, newActivities) {
}, [])
.concat(currentActivities)
.sort((itemA, itemB) => {
return DateTime.fromISO(itemB.createdAt) <
DateTime.fromISO(itemA.createdAt)
return DateTime.fromISO(itemB.data.date) <
DateTime.fromISO(itemA.data.date)
? -1
: 1;
});
Expand Down

0 comments on commit 6cf1280

Please sign in to comment.