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 pull request #64 from traP-jp/feature/49
🚧 MyAchievesをgridで表示させつつMissionsページと共通化
- Loading branch information
Showing
4 changed files
with
92 additions
and
83 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 |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import { Flex, Loader } from '@mantine/core'; | ||
import { Loader } from '@mantine/core'; | ||
import type { FC } from 'react'; | ||
import useSWR from 'swr'; | ||
import { MissionPanel } from '@/components/DashBoard/MissionPanel'; | ||
import { MissionList } from '@/components/MissionList'; | ||
import { fetcher } from '@/lib/fetcher'; | ||
import { getApiBaseUrl } from '@/lib/getApiBaseUrl'; | ||
import type { GetUserResponse } from '@/schema/schema'; | ||
import type { GetMissionsResponse, GetUserResponse } from '@/schema/schema'; | ||
|
||
export const MyAchieves: FC = () => { | ||
const { data } = useSWR<GetUserResponse>( | ||
`${getApiBaseUrl()}/users/me`, | ||
fetcher, | ||
); | ||
const { data: missions } = useSWR<GetMissionsResponse>( | ||
`${getApiBaseUrl()}/missions`, | ||
fetcher, | ||
); | ||
const achieves = missions | ||
? missions.filter((mission) => data?.achieves.includes(mission.id)) | ||
: undefined; | ||
|
||
if (data == undefined) return <Loader variant="oval" />; | ||
|
||
return ( | ||
<Flex wrap="wrap" gap="xs" p="lg"> | ||
{data.achieves.map((missionId) => ( | ||
<MissionPanel key={missionId} missionId={missionId} /> | ||
))} | ||
</Flex> | ||
); | ||
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