Skip to content

Commit

Permalink
Save
Browse files Browse the repository at this point in the history
  • Loading branch information
mikozet committed Aug 11, 2023
1 parent 4868364 commit 497f743
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 171 deletions.
89 changes: 45 additions & 44 deletions src/components/ActivityIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,55 @@ import { IconNotification } from '~/styles/icons';
const newsItems = core.news;

const DashboardActivityIcon = () => {
const { categories, lastSeenAt } = useSelector((state) => {
return state.activity;
});
// const { categories, lastSeenAt } = 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);
// 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) => {
return activity.isPending;
});
});
// // Is there any pending transactions?
// const isPending = CATEGORIES_WITH_NEWS.find((category) => {
// return !!categoriesWithNews[category].activities.find((activity) => {
// return activity.isPending;
// });
// });

// Count how many activities we haven't seen yet
const count = CATEGORIES_WITH_NEWS.reduce((acc, category) => {
return (
acc +
categoriesWithNews[category].activities.reduce((itemAcc, activity) => {
return activity.createdAt > lastSeenAt ? itemAcc + 1 : itemAcc;
}, 0)
);
}, 0);
// // Count how many activities we haven't seen yet
// const count = CATEGORIES_WITH_NEWS.reduce((acc, category) => {
// return (
// acc +
// categoriesWithNews[category].activities.reduce((itemAcc, activity) => {
// return activity.createdAt > lastSeenAt ? itemAcc + 1 : itemAcc;
// }, 0)
// );
// }, 0);

return (
<IconButton
aria-label="Activities"
component={Link}
edge="end"
size="large"
to="/activities"
>
{isPending ? (
<CircularProgress size={28} />
) : (
<Badge
badgeContent={count}
color="primary"
max={99}
overlap="rectangular"
>
<IconNotification style={{ fontSize: 28 }} />
</Badge>
)}
</IconButton>
);
// return (
// <IconButton
// aria-label="Activities"
// component={Link}
// edge="end"
// size="large"
// to="/activities"
// >
// {isPending ? (
// <CircularProgress size={28} />
// ) : (
// <Badge
// badgeContent={count}
// color="primary"
// max={99}
// overlap="rectangular"
// >
// <IconNotification style={{ fontSize: 28 }} />
// </Badge>
// )}
// </IconButton>
// );
return <></>;
};

export default DashboardActivityIcon;
22 changes: 21 additions & 1 deletion src/components/ActivityStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import makeStyles from '@mui/styles/makeStyles';
import clsx from 'clsx';
import { DateTime } from 'luxon';
import PropTypes from 'prop-types';
import React, { Fragment, useMemo, useState } from 'react';
import React, { Fragment, useEffect, useMemo, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router-dom';

Expand Down Expand Up @@ -111,6 +111,7 @@ const ActivityStream = ({

useUpdateLoop(
async () => {
console.log('LOOP');
await dispatch(checkFinishedActivities({ isCheckingOnlyPending: false }));
await dispatch(checkPendingActivities());
},
Expand All @@ -119,6 +120,25 @@ const ActivityStream = ({
},
);

useEffect(() => {
async function fetchNews() {
console.log('I am here in news2');
try {
// debugger;
// const newsActivities = await core.news.getLatestNews({ limit: 10 });
const newsActivities = await core.utils.requestAPI({
path: ['news'],
method: 'GET',
data: {},
});
console.log('newsActivities2', newsActivities);
} catch (error) {
console.log('error3', error);
}
}
fetchNews();
}, []);

return (
<Fragment>
{!isLoading && (
Expand Down
20 changes: 10 additions & 10 deletions src/components/ActivityStreamWithTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ const ActivityStreamWithTabs = ({ basePath = ACTIVITIES_PATH }) => {
handleFilterSelection(null, category);
}
}, [handleFilterSelection]);
const handleLoadMoreNews = () => {};
const isLoadingMoreNews = false;
const isMoreAvailableNews = false;
// const handleLoadMoreNews = () => {};
// const isLoadingMoreNews = false;
// const isMoreAvailableNews = false;

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

const filterBtnHandler = (event) => {
setAnchorEl(event.currentTarget);
Expand Down Expand Up @@ -279,7 +279,7 @@ const ActivityStreamWithTabs = ({ basePath = ACTIVITIES_PATH }) => {
label={translate('ActivityStreamWithTabs.bodyFilterConnections')}
value={ActivityFilterTypes.CONNECTIONS}
/>
<TabNavigationAction
{/* <TabNavigationAction
icon={<IconMegaphone />}
itemsCounter={
preselectedCategory !== 'News' && newNewsActivities
Expand All @@ -288,7 +288,7 @@ const ActivityStreamWithTabs = ({ basePath = ACTIVITIES_PATH }) => {
}
label={translate('ActivityStreamWithTabs.bodyFilterNews')}
value={'News'}
/>
/> */}
</TabNavigation>
<Box className={classes.actionsContainer}>
<Box className={classes.filterContainer}>
Expand Down Expand Up @@ -356,15 +356,15 @@ const ActivityStreamWithTabs = ({ basePath = ACTIVITIES_PATH }) => {
/>
)}
{/* TODO merge(?) NewsFeed with ActivityStream depending on API */}
{preselectedCategory === 'News' && (
{/* {preselectedCategory === 'News' && (
<NewsFeed
isLoading={isLoadingMoreNews}
isMoreAvailable={isMoreAvailableNews}
lastSeenAt={lastSeenAt}
news={newsActivities}
onLoadMore={handleLoadMoreNews}
></NewsFeed>
)}
)} */}
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/TabNavigationAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const useStyles = makeStyles((theme) => ({
},
},
'&.MuiTab-labelIcon': {
minHeight: 'auto',
// minHeight: 'auto',
paddingBottom: '3px',

'& .MuiTab-wrapper > *:first-child': {
Expand Down
174 changes: 92 additions & 82 deletions src/services/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const core = new CirclesCore(web3, {
});

async function requestCore(moduleName, method, options) {
// why here I do not see core.news which throws an error
return await core[moduleName][method](getAccount(), options);
}

Expand Down Expand Up @@ -300,88 +301,97 @@ const activity = {

// News module
const news = {
activities: [
{
createdAt: '2023-02-05T22:14:01.714+04:00',
id: '1',
isPending: false,
title: 'We have some problems! In two lines, in two lines ',
text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
url: 'https://market.joincircles.net/',
date: '15.05.2022',
icon: 'IconHeartWithExclamationMark',
},
{
createdAt: '2023-02-05T22:12:03.214+04:00',
id: '2',
isPending: false,
title: 'Welcome to Circles!',
text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
url: 'https://market.joincircles.net/',
date: '15.05.2022',
icon: 'IconCirclesLogoLight',
},
{
createdAt: '2023-02-05T22:12:01.000+04:00',
id: '3',
isPending: false,
title: 'New Features!',
text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
url: 'https://market.joincircles.net/',
date: '15.05.2022',
icon: 'IconExclamationAndQuestionMark',
},
{
createdAt: '2023-02-04T12:24:46.000+04:00',
id: '4',
isPending: false,
title: 'We have some problems! In two lines, in two lines ',
text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
url: 'https://market.joincircles.net/',
date: '15.05.2022',
icon: 'IconExclamationAndQuestionMark',
},
{
createdAt: '2023-02-04T12:21:31.000+04:00',
id: '5',
isPending: false,
title: '2We have some problems! In two lines, in two lines ',
text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
url: 'https://market.joincircles.net/',
date: '15.05.2022',
icon: 'IconHeartWithExclamationMark',
},
{
createdAt: '2023-02-03T15:27:33.000+04:00',
id: '6',
isPending: false,
title: '2Welcome to Circles!',
text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
url: 'https://market.joincircles.net/',
date: '15.05.2022',
icon: 'IconCirclesLogoLight',
},
{
createdAt: '2023-02-03T15:25:38.000+04:00',
id: '7',
isPending: false,
title: '2New Features!',
text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
url: 'https://market.joincircles.net/',
date: '15.05.2022',
icon: 'IconExclamationAndQuestionMark',
},
{
createdAt: '2023-02-03T15:02:27.000+04:00',
id: '8',
isPending: false,
title: '2We have some problems! In two lines',
text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
url: 'https://market.joincircles.net/',
date: '15.05.2022',
icon: 'IconExclamationAndQuestionMark',
},
],
getLatestNews: async (afterDate, isActive, limit, offset) => {
return await requestCore('news', 'getLatestNews', {
afterDate,
isActive,
limit,
offset,
});
},

// activities: [
// {
// createdAt: '2023-02-05T22:14:01.714+04:00',
// id: '1',
// isPending: false,
// title: 'We have some problems! In two lines, in two lines ',
// text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
// url: 'https://market.joincircles.net/',
// date: '15.05.2022',
// icon: 'IconHeartWithExclamationMark',
// },
// {
// createdAt: '2023-02-05T22:12:03.214+04:00',
// id: '2',
// isPending: false,
// title: 'Welcome to Circles!',
// text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
// url: 'https://market.joincircles.net/',
// date: '15.05.2022',
// icon: 'IconCirclesLogoLight',
// },
// {
// createdAt: '2023-02-05T22:12:01.000+04:00',
// id: '3',
// isPending: false,
// title: 'New Features!',
// text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
// url: 'https://market.joincircles.net/',
// date: '15.05.2022',
// icon: 'IconExclamationAndQuestionMark',
// },
// {
// createdAt: '2023-02-04T12:24:46.000+04:00',
// id: '4',
// isPending: false,
// title: 'We have some problems! In two lines, in two lines ',
// text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
// url: 'https://market.joincircles.net/',
// date: '15.05.2022',
// icon: 'IconExclamationAndQuestionMark',
// },
// {
// createdAt: '2023-02-04T12:21:31.000+04:00',
// id: '5',
// isPending: false,
// title: '2We have some problems! In two lines, in two lines ',
// text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
// url: 'https://market.joincircles.net/',
// date: '15.05.2022',
// icon: 'IconHeartWithExclamationMark',
// },
// {
// createdAt: '2023-02-03T15:27:33.000+04:00',
// id: '6',
// isPending: false,
// title: '2Welcome to Circles!',
// text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
// url: 'https://market.joincircles.net/',
// date: '15.05.2022',
// icon: 'IconCirclesLogoLight',
// },
// {
// createdAt: '2023-02-03T15:25:38.000+04:00',
// id: '7',
// isPending: false,
// title: '2New Features!',
// text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
// url: 'https://market.joincircles.net/',
// date: '15.05.2022',
// icon: 'IconExclamationAndQuestionMark',
// },
// {
// createdAt: '2023-02-03T15:02:27.000+04:00',
// id: '8',
// isPending: false,
// title: '2We have some problems! In two lines',
// text: '<p>Lorem ipsum text...</p><p>Lorem ipsum text </p>',
// url: 'https://market.joincircles.net/',
// date: '15.05.2022',
// icon: 'IconExclamationAndQuestionMark',
// },
// ],
};
// Organization module

Expand Down
Loading

0 comments on commit 497f743

Please sign in to comment.