Skip to content

Commit

Permalink
#46 Add initial activity feed page
Browse files Browse the repository at this point in the history
  • Loading branch information
danielemery committed Jul 21, 2024
1 parent 01b60f7 commit f968a84
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export default function NavigationBar({
</Link>
{isAuthenticated && (
<>
<Link className='hidden lg:block' to='/feed'>
<NavigationBarItem>Activity</NavigationBarItem>
</Link>
{canUploadQuiz && (
<Link className='hidden lg:block' to='/quiz/create'>
<NavigationBarItem>Upload Quiz</NavigationBarItem>
Expand Down
2 changes: 2 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import QuizDetails from './QuizDetails';
import { useQuizlord } from './QuizlordProvider';
import Button from './components/Button';
import Loader from './components/Loader';
import ActivityFeed from './pages/feed/ActivityFeed';
import QuizList from './pages/list/QuizList';
import QuizStatistics from './pages/statistics/QuizStatistics';
import { userCanPerformAction } from './services/authorization';
Expand Down Expand Up @@ -55,6 +56,7 @@ export function App() {
<Route path='/quiz/:id' element={<QuizDetails />} />
<Route path='/quiz/:id/enter' element={<EnterQuizResults />} />
<Route path='/stats' element={<QuizStatistics />} />
<Route path='/feed' element={<ActivityFeed />} />
</Routes>
)}
</div>
Expand Down
26 changes: 26 additions & 0 deletions src/hooks/useActivityFeed.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useQuery } from '@apollo/client';

import { ACTIVITY_FEED } from '../queries/feed';

// TODO this should be generated from the GraphQL schema
export interface RecentActivityItem {
date: Date;
text: string;
action?: {
name: string;
link: string;
};
}

export function useActivityFeed(): {
loading: boolean;
data: { activityFeed: RecentActivityItem[] } | undefined;
refetch: () => void;
} {
const { loading, data, refetch } = useQuery(ACTIVITY_FEED, {
fetchPolicy: 'network-only',
notifyOnNetworkStatusChange: true,
});

return { loading, data, refetch };
}
21 changes: 21 additions & 0 deletions src/pages/feed/ActivityFeed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Loader from '../../components/Loader';
import { formatDate } from '../../helpers';
import { useActivityFeed } from '../../hooks/useActivityFeed.hook';

export default function ActivityFeed() {
const { data, loading } = useActivityFeed();

if (loading || !data) {
return <Loader message='Loading recent activities...' />;
}

return (
<ul>
{data?.activityFeed.map((activity) => (
<li className='mt-4'>
<strong>{formatDate(activity.date)}:</strong> {activity.text}
</li>
))}
</ul>
);
}
14 changes: 14 additions & 0 deletions src/queries/feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { gql } from '@apollo/client';

export const ACTIVITY_FEED = gql`
query GetActivityFeed {
activityFeed {
date
action {
link
name
}
text
}
}
`;

0 comments on commit f968a84

Please sign in to comment.