generated from cp-20/nextjs-with-mantine-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '4d3e149a5373e8491ed9645f4b613c69ca0d3886' into feature/#57
- Loading branch information
Showing
7 changed files
with
210 additions
and
121 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import { Flex, Loader } from '@mantine/core'; | ||
import { Loader } from '@mantine/core'; | ||
import type { FC } from 'react'; | ||
import { MissionPanel } from '@/components/DashBoard/MissionPanel'; | ||
import useSWR from 'swr'; | ||
import { MissionList } from '@/components/MissionList'; | ||
import { useUserInfo } from '@/hooks/useUserInfo'; | ||
import { fetcher } from '@/lib/fetcher'; | ||
import { getApiBaseUrl } from '@/lib/getApiBaseUrl'; | ||
import type { GetMissionsResponse } from '@/schema/schema'; | ||
|
||
export const MyAchieves: FC = () => { | ||
const { data, error } = useUserInfo(); | ||
const { data: user, error } = useUserInfo(); | ||
const { data: missions } = useSWR<GetMissionsResponse>( | ||
`${getApiBaseUrl()}/missions`, | ||
fetcher, | ||
); | ||
|
||
if (data == undefined) return <Loader variant="oval" />; | ||
if (user == undefined || missions === undefined) | ||
return <Loader variant="oval" />; | ||
|
||
if (error !== undefined) return <div>Something went wrong</div>; | ||
|
||
return ( | ||
<Flex wrap="wrap" gap="xs" p="lg"> | ||
{data.achieves.map((missionId) => ( | ||
<MissionPanel key={missionId} missionId={missionId} /> | ||
))} | ||
</Flex> | ||
); | ||
const achieves = missions | ||
? missions.filter((mission) => user.achieves.includes(mission.id)) | ||
: undefined; | ||
|
||
return <MissionList missions={achieves} />; | ||
}; |
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,76 @@ | ||
import { css } from '@emotion/react'; | ||
import { Card, Overlay, useMantineTheme, Text, Skeleton } from '@mantine/core'; | ||
import { IconCheck } from '@tabler/icons-react'; | ||
import Link from 'next/link'; | ||
import type { FC } from 'react'; | ||
import type { GetMissionResponse, GetUserResponse } from '@/schema/schema'; | ||
|
||
export type MissionListProps = { | ||
missions?: GetMissionResponse[]; | ||
user?: GetUserResponse; | ||
}; | ||
|
||
export const MissionList: FC<MissionListProps> = ({ missions, user }) => { | ||
const theme = useMantineTheme(); | ||
|
||
return ( | ||
<div | ||
css={css` | ||
display: grid; | ||
margin-top: ${theme.spacing.md}; | ||
gap: 16px; | ||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); | ||
`} | ||
> | ||
{missions | ||
? missions.map((mission) => ( | ||
<Link | ||
href={`/missions/${mission.id}`} | ||
key={mission.id} | ||
css={css` | ||
color: inherit; | ||
text-decoration: none; | ||
`} | ||
> | ||
<Card | ||
shadow="xs" | ||
padding="lg" | ||
css={css` | ||
transition: all 0.2s; | ||
&:hover { | ||
box-shadow: ${theme.shadows.sm}; | ||
opacity: 0.8; | ||
} | ||
`} | ||
> | ||
{user?.achieves.includes(mission.id) && ( | ||
<Overlay | ||
css={css` | ||
display: grid; | ||
background-color: ${theme.fn.rgba(theme.white, 0.8)}; | ||
color: ${theme.colors.lime[5]}; | ||
place-items: center; | ||
`} | ||
> | ||
<IconCheck size="5rem" /> | ||
</Overlay> | ||
)} | ||
<Text fw="500" lineClamp={1} className="mission-title"> | ||
{mission.name} | ||
</Text> | ||
<Text | ||
color="dimmed" | ||
lineClamp={2} | ||
h="3rem" | ||
className="mission-description" | ||
> | ||
{mission.description} | ||
</Text> | ||
</Card> | ||
</Link> | ||
)) | ||
: new Array(3).fill(0).map((_, i) => <Skeleton h={90} key={i} />)} | ||
</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
Oops, something went wrong.