Skip to content

Commit

Permalink
スコアがないお題の処理
Browse files Browse the repository at this point in the history
  • Loading branch information
harata-t committed Nov 14, 2024
1 parent 4602157 commit 9b0c853
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
8 changes: 3 additions & 5 deletions app/src/app/api/score/assignment/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export async function GET(req: NextRequest) {
include: { user: true, assignment: true },
});

if (!scores[0].assignment){
return new Response(JSON.stringify({ message: "Not Found" }), {
status: 404,
if (!scores[0]?.assignment){
return new Response(JSON.stringify({}), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
Expand All @@ -37,8 +37,6 @@ export async function GET(req: NextRequest) {
where: { id: scores[0].assignment.wordId },
});



const scoreDetails: ScoreDetail[] = scores.map((score) => {
if(!score.assignment){
return {
Expand Down
5 changes: 3 additions & 2 deletions app/src/app/ranking/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ export default function RankingPage() {
const response = await fetch("api/assignment/today");
const data: todayAssignment[] = await response.json();
setTopics(data);
setSelectedTopic(data[0].assignmentId);
if (data.length > 0) {
setSelectedTopic(data[0].assignmentId); // 初期値を設定
}
} catch (error) {
console.error("Error fetching topics:", error);
}
};

fetchTopics();
}, []);

Expand Down
15 changes: 14 additions & 1 deletion app/src/components/view/ranking/RankingListToday.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,26 @@ const RankingListToday: React.FC<{ selectedTopic: number }> = ({
}
};

fetchData(getDate());
if (selectedTopic !== 0) {
fetchData(getDate());
}
}, [selectedTopic, getDate]);

if (isLoading) {
return <LoadingSpinner />;
}

if (!Array.isArray(data) || data.length === 0) {
return (
<div
className="flex items-center justify-center h-40 text-lg text-orange-500"
>
まだ投稿がありません!<br />
1位になれるかも!
</div>
);
}

return (
<div className="mt-4 space-y-4">
{data.map((item, index) => {
Expand Down

0 comments on commit 9b0c853

Please sign in to comment.