Skip to content

Commit

Permalink
これでOK
Browse files Browse the repository at this point in the history
  • Loading branch information
nasubi-dev committed Sep 1, 2024
1 parent 87aaeef commit 7aea6c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
36 changes: 20 additions & 16 deletions src/pages/achievements/[id]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type ReactElement } from "react";
import useSWR from "swr";
// import useSWRImmutable from "swr/immutable";
import useSWRImmutable from "swr/immutable";
import { match } from "ts-pattern";
import { useAchievements } from "@/hooks/db/achievements";
import { useTeam } from "@/hooks/teams";
Expand All @@ -11,31 +10,36 @@ import { type Achievement } from "@/types/post-data/achievements";
export default function Page(): ReactElement {
const { id } = useParams("/achievements/:id");
const { fetch } = useAchievements(useTeam);
const swrAchievement = useSWR("achievement", fetchAchievement);
const swrAchievement = useSWRImmutable("achievement", fetchAchievement);

async function fetchAchievement(): Promise<Achievement> {
async function fetchAchievement(): Promise<Achievement[]> {
const achievements = await fetch();

if (achievements == null) throw new Error("No unlockedAchievements found.");

const achievement = achievements.find((a) => a.id === Number(id));

if (achievement == null) throw new Error("No achievement found.");

return achievement;
return achievements;
}

return match(swrAchievement)
.with(S.Loading, () => <p>Loading...</p>)
.with(S.Success, ({ data }) => (
<div>
<h1>name: {data.name}</h1>
<p>id: {data.id}</p>
<p>description: {data.description}</p>
<p>icon: {data.icon}</p>
<p>createdAt: {String(data.createdAt)}</p>
<p>updatedAt: {String(data.updatedAt)}</p>
<p>tags: {data.tags.map((tag) => tag.name).join(", ")}</p>
{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.map((tag) => tag.name).join(", ")}</p>
</div>
);
}
return null;
})}
</div>
))
.otherwise(({ error }) => {
Expand Down
1 change: 0 additions & 1 deletion src/pages/members/[id]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type ReactElement } from "react";
import useSWR from "swr";
import useSWRImmutable from "swr/immutable";
import { match } from "ts-pattern";
import { useTeam } from "@/hooks/teams";
Expand Down

0 comments on commit 7aea6c2

Please sign in to comment.