-
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 #155 from /issues/151
Issues/151
- Loading branch information
Showing
3 changed files
with
103 additions
and
55 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
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 |
---|---|---|
@@ -1,47 +1,88 @@ | ||
import { Flex } from "@radix-ui/themes"; | ||
import { Box, Flex, Text } from "@radix-ui/themes"; | ||
import { type ReactElement } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import styled from "styled-components"; | ||
import useSWRImmutable from "swr/immutable"; | ||
import { match } from "ts-pattern"; | ||
import { ErrorScreen } from "@/components/ErrorScreen"; | ||
import { Info } from "@/components/achievements/Info"; | ||
import { RecentUnlockedCard } from "@/components/achievements/RecentUnlockedCard"; | ||
import { MemberCard } from "@/components/member/Card"; | ||
import { useAchievements } from "@/hooks/db/achievements"; | ||
import { useUnlockedAchievements } from "@/hooks/db/unlocked-achievements"; | ||
import { useTeam } from "@/hooks/teams"; | ||
import { S } from "@/lib/consts"; | ||
import { fetchMembersAndUnlockedAchievementsAndAchievements } from "@/lib/utils/fetchers"; | ||
import { handleSWRError } from "@/lib/utils/swr"; | ||
|
||
// export default function Page(): ReactElement { | ||
// const { id } = useParams("/achievements/:id"); | ||
// const { fetch } = useAchievements(useTeam); | ||
// const swrAchievement = useSWRImmutable("achievements", fetch); | ||
|
||
// return match(swrAchievement) | ||
// .with(S.Loading, () => <p>Loading...</p>) | ||
// .with(S.Success, ({ data }) => ( | ||
// <div> | ||
// {data.map((d) => { | ||
// if (d.id === Number(id)) { | ||
// return ( | ||
// <div key={d.id}> | ||
// <h1>name: {d.name}</h1> | ||
// <p>id: {d.id}</p> | ||
// <p>description: {d.description}</p> | ||
// <p>icon: {d.icon}</p> | ||
// <p>createdAt: {String(d.createdAt)}</p> | ||
// <p>updatedAt: {String(d.updatedAt)}</p> | ||
// <p>tags: {d.tags.join(", ")}</p> | ||
// </div> | ||
// ); | ||
// } | ||
// return null; | ||
// })} | ||
// </div> | ||
// )) | ||
// .otherwise(({ data, error }) => ( | ||
// <ErrorScreen error={handleSWRError(data, error)} /> | ||
// )); | ||
// } | ||
const BoxStyle = styled(Box)` | ||
margin: 0 auto; | ||
height: 80vh; | ||
overflow: scroll; | ||
`; | ||
|
||
export default function Page(): ReactElement { | ||
return ( | ||
<Flex> | ||
<Info /> | ||
<Flex overflow="scroll" width="100%"> | ||
<RecentUnlockedCard /> | ||
</Flex> | ||
</Flex> | ||
const { id } = useParams(); | ||
const { fetchMembers } = useTeam(); | ||
const { fetch: fetchAchievements } = useAchievements(useTeam); | ||
const { fetch: fetchUnlockedAchievements } = useUnlockedAchievements(useTeam); | ||
const swrMembersAndUnlockedAchievementsAndAchievements = useSWRImmutable( | ||
"membersAndUnlockedAchievementsAndAchievements", | ||
async () => | ||
await fetchMembersAndUnlockedAchievementsAndAchievements( | ||
fetchMembers, | ||
fetchAchievements, | ||
fetchUnlockedAchievements, | ||
), | ||
); | ||
|
||
return match(swrMembersAndUnlockedAchievementsAndAchievements) | ||
.with(S.Loading, () => <p>Loading...</p>) | ||
.with( | ||
S.Success, | ||
({ data: { members, achievements, unlockedAchievements } }) => ( | ||
<> | ||
{achievements.map((a) => { | ||
if (a.id === Number(id)) { | ||
const rateOfUnlocked = unlockedAchievements.filter( | ||
(ua) => ua.achievementID === a.id, | ||
).length; | ||
|
||
const thisAchievementUnlockedMembers = members.filter((m) => | ||
unlockedAchievements.some( | ||
(ua) => | ||
ua.achievementID === a.id && ua.memberEmail === m.email, | ||
), | ||
); | ||
return ( | ||
<Flex key={a.id} gap="9"> | ||
<Info | ||
key={a.id} | ||
icon={a.icon} | ||
name={a.name} | ||
rateOfUnlocked={rateOfUnlocked} | ||
tags={a.tags} | ||
/> | ||
<div> | ||
<Box mt="20vh" /> | ||
<BoxStyle> | ||
<Text size="8" weight="bold"> | ||
最近解除したメンバー | ||
</Text> | ||
<Box mt="1rem" /> | ||
{thisAchievementUnlockedMembers.map((m) => ( | ||
<MemberCard key={m.email} member={m} /> | ||
))} | ||
</BoxStyle> | ||
</div> | ||
</Flex> | ||
); | ||
} | ||
return null; | ||
})} | ||
</> | ||
), | ||
) | ||
.otherwise(({ data, error }) => ( | ||
<ErrorScreen error={handleSWRError(data, error)} /> | ||
)); | ||
} |