Skip to content

Commit

Permalink
Save
Browse files Browse the repository at this point in the history
  • Loading branch information
mikozet committed Aug 30, 2023
1 parent 3b8f215 commit 5114c3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions src/store/activity/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ import { formatCirclesValue } from '~/utils/format';

const { ActivityTypes, ActivityFilterTypes } = core.activity;

export const PAGE_SIZE = 2;
export const PAGE_SIZE = 10;

// function generateHash(activity) {
// const date = activity.createdAt || activity.date;
// const value = `${date}${activity.message.en}`;
// return web3.utils.sha3(value);
// }

function generateHash(activity) {
const date = activity.createdAt || activity.date;
const value = `${date}${activity.message.en}`;
const hash = activity?.txHash || activity?.createdAt || activity?.date;
const value = `${hash}${activity.type?.toString()}`;
return web3.utils.sha3(value);
}

Expand Down Expand Up @@ -384,7 +390,7 @@ export function loadMoreActivitiesNews(options = {}) {

function checkForDuplicates(item) {
for (const newsItem of currentNews) {
if (newsItem.hash === item.hash) {
if (newsItem.data.id === item.id) {
return false; // value is duplicate we do not want it
}
}
Expand Down Expand Up @@ -418,25 +424,29 @@ export function loadMoreActivitiesNews(options = {}) {

if (data.length === 0) {
noMoreRecords = true;
return;
break;
}

// we want only values till present time not future
filteredNewsData = data?.filter(tillNow);

// add hash to items so we can filter for duplicates
for (const filteredNewsDataItem of filteredNewsData) {
if (!filteredNewsDataItem.hash) {
filteredNewsDataItem.hash = generateHash(filteredNewsDataItem);
if (!filteredNewsDataItem.id) {
// filteredNewsDataItem.hash = generateHash(filteredNewsDataItem);
filteredNewsDataItem.id = filteredNewsDataItem.date;
}
}
console.log('filteredNewsData', filteredNewsData);

// we have some values in table as well and we do not want duplicates so we filter
filterDuplicateNewsData = filteredNewsData.filter(checkForDuplicates);
debugger;
console.log('filterDuplicateNewsData', filterDuplicateNewsData);
console.log('currentNews', currentNews);

// we have values till present which are not duplicates - we add them to newsData which we want to display
newsData.push(...filterDuplicateNewsData);
newsData.push(...filteredNewsData);
// newsData.push(...filterDuplicateNewsData);
console.log('newsData', newsData);
offset += PAGE_SIZE;
loopCounter += 1;
Expand All @@ -461,6 +471,8 @@ export function loadMoreActivitiesNews(options = {}) {
console.log('liveRefresh', liveRefresh);
console.log('currentOffset', currentOffset);

// debugger;

dispatch({
type: ActionTypes.ACTIVITIES_NEWS_LOAD_MORE_SUCCESS,
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/store/activity/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function mergeActivities(currentActivities, newActivities) {
});

// Generate a hash so we can compare it
newActivity.hash = generateHash(newActivity);
// newActivity.hash = generateHash(newActivity);

// Check if item already exists (maybe we've added it manually as a
// pending task and now it got mined!
Expand Down

0 comments on commit 5114c3f

Please sign in to comment.