Skip to content

Commit

Permalink
Merge commit '4d3e149a5373e8491ed9645f4b613c69ca0d3886' into feature/#57
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 committed Jun 24, 2023
2 parents 150f424 + 4d3e149 commit bcbb72c
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 121 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"ress": "^5.0.2",
"sharp": "^0.32.1",
"swr": "^2.1.5",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@stylelint/postcss-css-in-js": "^0.38.0",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 18 additions & 11 deletions src/components/DashBoard/MyAchieves.tsx
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} />;
};
4 changes: 2 additions & 2 deletions src/components/DashBoard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export const DashBoard: FC = () => {
<Center>
<h2>Your recent achievement</h2>
</Center>
<Center>
<div>
<MyAchieves />
</Center>
</div>
</div>
</Layout>
</>
Expand Down
76 changes: 76 additions & 0 deletions src/components/MissionList.tsx
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>
);
};
74 changes: 3 additions & 71 deletions src/pages/missions.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import { css } from '@emotion/react';
import {
Card,
Overlay,
RingProgress,
Skeleton,
Text,
useMantineTheme,
} from '@mantine/core';
import { IconCheck } from '@tabler/icons-react';
import { RingProgress, useMantineTheme } from '@mantine/core';
import type { NextPage } from 'next';
import Link from 'next/link';
import useSWR from 'swr';
import { Description } from '@/components/Description';
import { Layout } from '@/components/Layout';
import { MissionList } from '@/components/MissionList';
import { useUserInfo } from '@/hooks/useUserInfo';
import { fetcher } from '@/lib/fetcher';
import { getApiBaseUrl } from '@/lib/getApiBaseUrl';
Expand Down Expand Up @@ -63,67 +55,7 @@ const Missions: NextPage = () => {
/>
)}
</h1>
<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>
<MissionList missions={missions} user={user} />
</div>
</Layout>
</>
Expand Down
Loading

0 comments on commit bcbb72c

Please sign in to comment.