import * as React from 'react'; import List from '@mui/material/List'; import ListItem from '@mui/material/ListItem'; import ListItemButton from '@mui/material/ListItemButton'; import ListItemText from '@mui/material/ListItemText'; import IconButton from '@mui/material/IconButton'; import { executeEvent } from '../../utils/events'; import { Box, Typography } from '@mui/material'; import { Spacer } from '../../common/Spacer'; import { CustomLoader } from '../../common/CustomLoader'; import VisibilityIcon from '@mui/icons-material/Visibility'; export const ListOfThreadPostsWatched = () => { const [posts, setPosts] = React.useState([]); const [loading, setLoading] = React.useState(true); const getPosts = async () => { try { await new Promise((res, rej) => { window .sendMessage('getThreadActivity', {}) .then((response) => { if (!response?.error) { if (!response) { res(null); return; } const uniquePosts = response.reduce((acc, current) => { const x = acc.find( (item) => item?.thread?.threadId === current?.thread?.threadId ); if (!x) { return acc.concat([current]); } else { return acc; } }, []); setPosts(uniquePosts); res(uniquePosts); return; } rej(response.error); }) .catch((error) => { rej(error.message || 'An error occurred'); // TODO translate }); }); } catch (error) { } finally { setLoading(false); } }; React.useEffect(() => { getPosts(); }, []); return ( New Thread Posts: {loading && posts.length === 0 && ( )} {!loading && posts.length === 0 && ( Nothing to display )} {posts?.length > 0 && ( {posts?.map((post) => { return ( { executeEvent('openThreadNewPost', { data: post, }); }} disablePadding secondaryAction={ } > ); })} )} ); };