-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01b60f7
commit f968a84
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
`; |