-
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.
* #46 Add initial activity feed page * #46 Update activity feed POC to match new schema * Add npm start alias for npm run dev * #46 Simplify the design of the activity feed * #46 Change the style of the feed to use cards * #46 Add activity feed link to mobile nav * #46 Fix attribute formatting
- Loading branch information
1 parent
01b60f7
commit 196c3fb
Showing
7 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,25 @@ | ||
import { useQuery } from '@apollo/client'; | ||
|
||
import { ACTIVITY_FEED } from '../queries/feed'; | ||
import { User } from '../types/user'; | ||
|
||
// TODO this should be generated from the GraphQL schema | ||
export interface RecentActivityItem { | ||
date: Date; | ||
text: string; | ||
resourceId: string; | ||
users: User[]; | ||
} | ||
|
||
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,38 @@ | ||
import { intlFormatDistance } from 'date-fns'; | ||
|
||
import Loader from '../../components/Loader'; | ||
import { userIdentifier } from '../../helpers'; | ||
import { RecentActivityItem, useActivityFeed } from '../../hooks/useActivityFeed.hook'; | ||
|
||
export default function ActivityFeed() { | ||
const { data, loading } = useActivityFeed(); | ||
|
||
if (loading || !data) { | ||
return <Loader message='Loading recent activities...' />; | ||
} | ||
|
||
return ( | ||
<div> | ||
{data?.activityFeed.map((activity) => ( | ||
<ActivityCard key={activity.resourceId} recentlyActivityItem={activity} /> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export function ActivityCard({ recentlyActivityItem }: { recentlyActivityItem: RecentActivityItem }) { | ||
return ( | ||
<div className='bg-white m-2 p-2 rounded-lg border-solid border-2'> | ||
<div> | ||
<div className='flex justify-between'> | ||
<div className='font-bold'>{recentlyActivityItem.users.map((u) => userIdentifier(u)).join(', ')}</div> | ||
<i className='hidden lg:block'>{intlFormatDistance(recentlyActivityItem.date, new Date())}</i> | ||
</div> | ||
</div> | ||
<div>{recentlyActivityItem.text}</div> | ||
<div className='lg:hidden'> | ||
<i>{intlFormatDistance(recentlyActivityItem.date, new Date())}</i> | ||
</div> | ||
</div> | ||
); | ||
} |
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,15 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
export const ACTIVITY_FEED = gql` | ||
query GetActivityFeed { | ||
activityFeed { | ||
date | ||
text | ||
resourceId | ||
users { | ||
name | ||
} | ||
} | ||
} | ||
`; |