-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create a public profile for collection contributors (#404)
* feat: create a public profile for collection contributors * fix: prefetch published items for member * feat: add a back button to member profile
- Loading branch information
Showing
7 changed files
with
193 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; | ||
import { ParsedUrlQuery } from 'querystring'; | ||
|
||
import * as React from 'react'; | ||
import { DehydratedState } from 'react-query'; | ||
|
||
import { Api, DATA_KEYS, configureQueryClient } from '@graasp/query-client'; | ||
|
||
import Wrapper from '../../src/components/common/Wrapper'; | ||
import Member from '../../src/components/pages/Member'; | ||
import { QUERY_CLIENT_OPTIONS } from '../../src/config/queryClient'; | ||
|
||
const MemberPage = ({ | ||
dehydratedState, | ||
id, | ||
}: InferGetServerSidePropsType<typeof getServerSideProps>) => { | ||
return ( | ||
<Wrapper dehydratedState={dehydratedState}> | ||
<Member id={id} /> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
type Props = { | ||
dehydratedState: DehydratedState; | ||
id?: string; | ||
}; | ||
|
||
interface Params extends ParsedUrlQuery { | ||
id: string; | ||
} | ||
|
||
// This gets called on every request | ||
export const getServerSideProps: GetServerSideProps<Props, Params> = async ({ | ||
params, | ||
}) => { | ||
const id = params?.id; | ||
const { queryClient, dehydrate, axios } = | ||
configureQueryClient(QUERY_CLIENT_OPTIONS); | ||
if (id) { | ||
// prefetch data in query client | ||
await queryClient.prefetchQuery(DATA_KEYS.buildItemKey(id), () => | ||
Promise.all([ | ||
Api.getMember({ id }, { ...QUERY_CLIENT_OPTIONS, axios }).then( | ||
(data) => { | ||
return JSON.parse(JSON.stringify(data)); | ||
}, | ||
), | ||
Api.getPublishedItemsForMember(id, { | ||
...QUERY_CLIENT_OPTIONS, | ||
axios, | ||
}).then((data) => { | ||
return JSON.parse(JSON.stringify(data)); | ||
}), | ||
]), | ||
); | ||
} | ||
|
||
// Pass data to the page via props | ||
return { props: { id, dehydratedState: dehydrate(queryClient) } }; | ||
}; | ||
|
||
export default MemberPage; |
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,111 @@ | ||
import dynamic from 'next/dynamic'; | ||
|
||
import { useContext } from 'react'; | ||
|
||
import { Box, Stack, Typography } from '@mui/material'; | ||
|
||
import { Context } from '@graasp/sdk'; | ||
|
||
import { APP_AUTHOR } from '../../config/constants'; | ||
import { useLibraryTranslation } from '../../config/i18n'; | ||
import { ERROR_UNEXPECTED_ERROR_CODE } from '../../config/messages'; | ||
import { MENU_BUTTON_ID } from '../../config/selectors'; | ||
import LIBRARY from '../../langs/constants'; | ||
import { QueryClientContext } from '../QueryClientContext'; | ||
import CollectionsGrid from '../collection/CollectionsGrid'; | ||
import BackButton from '../common/BackButton'; | ||
import Error from '../common/Error'; | ||
import Seo from '../common/Seo'; | ||
import useHeader from '../layout/useHeader'; | ||
|
||
interface Props { | ||
id?: string; | ||
} | ||
|
||
const Main = dynamic(() => import('@graasp/ui').then((mod) => mod.Main), { | ||
ssr: false, | ||
}); | ||
|
||
const Avatar = dynamic(() => import('@graasp/ui').then((mod) => mod.Avatar), { | ||
ssr: false, | ||
}); | ||
|
||
const Member = ({ id }: Props) => { | ||
const { hooks } = useContext(QueryClientContext); | ||
const { data, isLoading: isMemberInfoLoading, isError } = hooks.useMember(id); | ||
const { data: memberPublishedItems, isLoading } = | ||
hooks.usePublishedItemsForMember(id); | ||
|
||
const { leftContent, rightContent } = useHeader(); | ||
const { t } = useLibraryTranslation(); | ||
|
||
if (isError) { | ||
return ( | ||
<Main | ||
context={Context.Library} | ||
headerLeftContent={leftContent} | ||
headerRightContent={rightContent} | ||
> | ||
<Box id={id} p={5}> | ||
<Error code={ERROR_UNEXPECTED_ERROR_CODE} /> | ||
</Box> | ||
</Main> | ||
); | ||
} | ||
return ( | ||
<> | ||
<Seo | ||
title={t(LIBRARY.GRAASP_LIBRARY)} | ||
description={t(LIBRARY.GRAASP_LIBRARY_DESCRIPTION)} | ||
author={APP_AUTHOR} | ||
/> | ||
<Main | ||
context={Context.Library} | ||
menuButtonId={MENU_BUTTON_ID} | ||
headerLeftContent={leftContent} | ||
headerRightContent={rightContent} | ||
> | ||
<Stack | ||
maxWidth="xl" | ||
marginX="auto" | ||
alignItems="flex-start" | ||
justifyItems="flex-start" | ||
justifySelf="center" | ||
marginTop={2} | ||
padding={3} | ||
> | ||
<BackButton /> | ||
|
||
<Box sx={{ display: 'flex', my: 3, gap: 2, alignItems: 'center' }}> | ||
<Avatar | ||
alt={t(LIBRARY.AVATAR_ALT, { name: data?.name })} | ||
isLoading={isMemberInfoLoading} | ||
component="avatar" | ||
maxWidth={120} | ||
maxHeight={120} | ||
variant="circular" | ||
sx={{ width: 90, height: 90, fontSize: '2.5rem' }} | ||
/> | ||
<Box> | ||
<Typography variant="h5">{data?.name}</Typography> | ||
{/* Bio goes there */} | ||
{/* <Typography variant="body1"></Typography> */} | ||
</Box> | ||
</Box> | ||
<Box flexGrow={1}> | ||
<Typography variant="h6" fontWeight="bold" sx={{ mb: 4 }}> | ||
{t(LIBRARY.PUBLISHED_COLLECTIONS)} | ||
</Typography> | ||
|
||
<CollectionsGrid | ||
collections={memberPublishedItems} | ||
isLoading={isLoading} | ||
/> | ||
</Box> | ||
</Stack> | ||
</Main> | ||
</> | ||
); | ||
}; | ||
|
||
export default Member; |
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