Skip to content

Commit

Permalink
Corrections after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mikozet committed Sep 7, 2023
1 parent 5596fd1 commit 3eb5c94
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 48 deletions.
15 changes: 4 additions & 11 deletions src/components/ActivityIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,26 @@ import React from 'react';
import { useSelector } from 'react-redux';
import { Link } from 'react-router-dom';

import core from '~/services/core';
import { CATEGORIES } from '~/store/activity/reducers';
import { IconNotification } from '~/styles/icons';
const newsItems = core.news;

const DashboardActivityIcon = () => {
const { categories, lastSeenAt, news } = useSelector((state) => {
return state.activity;
});

const NEWS = Symbol.for('NEWS');
const categoriesWithNews = { ...categories, ...{ [NEWS]: newsItems } };
let CATEGORIES_WITH_NEWS = [...CATEGORIES];
CATEGORIES_WITH_NEWS.push(NEWS);

// Is there any pending transactions?
const isPending = CATEGORIES_WITH_NEWS.find((category) => {
return !!categoriesWithNews[category].activities.find((activity) => {
const isPending = CATEGORIES.find((category) => {
return !!categories[category].activities.find((activity) => {
return activity.isPending;
});
});

// Count how many activities we haven't seen yet
const count = CATEGORIES_WITH_NEWS.reduce((acc, category) => {
const count = CATEGORIES.reduce((acc, category) => {
return (
acc +
categoriesWithNews[category].activities.reduce((itemAcc, activity) => {
categories[category].activities.reduce((itemAcc, activity) => {
return activity.createdAt > lastSeenAt ? itemAcc + 1 : itemAcc;
}, 0)
);
Expand Down
7 changes: 4 additions & 3 deletions src/components/ActivityStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const ActivityStreamList = ({
acc,
{
data,
id,
hash,
createdAt,
type,
Expand Down Expand Up @@ -140,7 +141,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 Expand Up @@ -176,8 +177,8 @@ const ActivityStreamList = ({
ActivityStream.propTypes = {
activities: PropTypes.array.isRequired,
filterType: PropTypes.string,
isLoadingInitial: PropTypes.bool.isRequired,
isLoadingMore: PropTypes.bool.isRequired,
isLoadingInitial: PropTypes.bool,
isLoadingMore: PropTypes.bool,
isMoreAvailable: PropTypes.bool.isRequired,
lastSeenAt: PropTypes.string,
lastUpdatedAt: PropTypes.string,
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
19 changes: 0 additions & 19 deletions src/components/ActivityStreamWithTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, { Fragment, useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { generatePath, useHistory } from 'react-router-dom';

import { IconMegaphone } from '../styles/icons';
import { ACTIVITIES_PATH } from '~/routes';

import ActivityStream from '~/components/ActivityStream';
Expand All @@ -17,7 +16,6 @@ import DialogExportStatement from '~/components/DialogExportStatement';
import Popover from '~/components/Popover';
import TabNavigation from '~/components/TabNavigation';
import TabNavigationAction from '~/components/TabNavigationAction';
import { useQuery } from '~/hooks/url';
import { useIsOrganization } from '~/hooks/username';
import core from '~/services/core';
import translate from '~/services/locale';
Expand All @@ -39,7 +37,6 @@ import {
} from '~/utils/constants';

const { ActivityFilterTypes } = core.activity;
const { activities: newsActivities } = core.news;

const DEFAULT_CATEGORY = ActivityFilterTypes.CONNECTIONS;

Expand Down Expand Up @@ -79,9 +76,6 @@ const useStyles = makeStyles(() => ({
filterItemActive: {
fontWeight: 700,
},
tabNavigationContainer: {
marginBottom: '43px',
},
}));

const QUERY_FILTER_MAP = {
Expand All @@ -102,12 +96,6 @@ const ActivityStreamWithTabs = ({ basePath = ACTIVITIES_PATH }) => {
const history = useHistory();
const [dialogOpen, setDialogOpen] = useState(false);

const { category } = useQuery();
const preselectedCategory =
category in QUERY_FILTER_MAP
? QUERY_FILTER_MAP[category]
: DEFAULT_CATEGORY;

const [categorySetByUser, setCategorySetByUser] = useState(false);
const [filterTransactionsIndex, setFilterTransactionIndex] = useState(0);
const [filterTransactionsType, setFilterTransactionType] = useState(
Expand Down Expand Up @@ -229,13 +217,6 @@ const ActivityStreamWithTabs = ({ basePath = ACTIVITIES_PATH }) => {
handleFilterSelection(null, category);
}
}, [handleFilterSelection]);
const handleLoadMoreNews = () => {};
const isLoadingMoreNews = false;
const isMoreAvailableNews = false;

const newNewsActivities = newsActivities.reduceRight((acc, activity) => {
return activity.createdAt > lastSeenAt ? acc + 1 : acc;
}, 0);

const filterBtnHandler = (event) => {
setAnchorEl(event.currentTarget);
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
15 changes: 6 additions & 9 deletions src/store/activity/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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 @@ -116,22 +115,20 @@ function mergeNews(currentActivities, newActivities) {
.reduce((acc, activity) => {
// Reformat object
const newActivity = Object.assign({}, initialStateActivity, {
createdAt: activity.createdAt
? DateTime.fromSeconds(activity.time).toISO()
: activity.date,
createdAt: activity.createdAt ? activity.createdAt : activity.date,
data: {
date: activity.date,
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 @@ -141,8 +138,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 3eb5c94

Please sign in to comment.