-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||
Check warning on line 2 in frontend/src/components/Comment.tsx GitHub Actions / build
|
||
import { UserSummary } from "@/services/api/semanticBrowseSchemas"; | ||
|
||
|
||
interface Comment { | ||
author: UserSummary; | ||
upvoteCount: number; | ||
content: string; | ||
createdAt: string; | ||
} | ||
|
||
export const Comment = ({ | ||
comment : {author, upvoteCount, content, createdAt}, | ||
}: { | ||
comment: Comment; | ||
}) => { | ||
return ( | ||
<div className="flex flex-col self-stretch "> | ||
<Card className="flex flex-1 flex-col bg-gray-100 pt-16"> | ||
<CardHeader className="py-2"> | ||
<div className="flex justify-between"> | ||
<div className="flex gap-2 items-center"> | ||
<img src={author.profilePicture} alt="Author" className="w-16 h-16 mr-2 rounded-full" /> | ||
<p className="text-lg font-medium text-gray-900">{author.username}</p> | ||
</div> | ||
<div className="flex gap-2"> | ||
<p className="text-sm text-gray-500">{createdAt}</p> | ||
<p className="text-sm text-gray-500">{upvoteCount} Upvotes</p> | ||
</div> | ||
</div> | ||
</CardHeader> | ||
<CardContent className="flex flex-1 flex-col justify-between gap-2"> | ||
<p className="text-sm text-gray-500">{content} </p> | ||
</CardContent> | ||
</Card> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useState } from "react"; | ||
Check warning on line 1 in frontend/src/routes/commentsPage.tsx GitHub Actions / build
|
||
import { Comment } from "../components/Comment"; | ||
import { FullscreenLoading } from "../components/FullscreenLoading"; | ||
import { Alert, AlertDescription, AlertTitle } from "../components/ui/alert"; | ||
import { AlertCircle, ArrowLeft } from "lucide-react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useGetCommentsForRecipe } from "../services/api/semanticBrowseComponents"; | ||
import { renderError } from "../services/api/semanticBrowseFetcher"; | ||
|
||
export const Comments = () => { | ||
const navigate = useNavigate(); | ||
const { data: commentData, isLoading, error } = useGetCommentsForRecipe({ | ||
pathParams: { recipeId: 123 }, // Update the recipeId with the actual recipeId | ||
}); | ||
|
||
if (isLoading) { | ||
return <FullscreenLoading overlay />; | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<div className="container flex flex-col gap-2 py-8"> | ||
<Alert variant="destructive"> | ||
<AlertCircle className="h-4 w-4" /> | ||
<AlertTitle>Error</AlertTitle> | ||
<AlertDescription>{renderError(error)}</AlertDescription> | ||
</Alert> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="container flex flex-col gap-2 py-8"> | ||
<div className="flex justify-between items-center"> | ||
<ArrowLeft className="cursor-pointer h-6 w-6 text-gray-700" onClick={() => navigate("/")} /> | ||
<h1 className="text-2xl font-bold mx-auto">Comments</h1> | ||
</div> | ||
<div className="mt-4 grid grid-cols-1 gap-8"> | ||
{commentData?.data?.reverse().map((comment) => ( | ||
<Comment | ||
key={comment.id} | ||
comment={comment} | ||
/> | ||
))} | ||
</div> | ||
</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
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