forked from devhub-ai/devhub
-
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.
feat: implement post detail view and enhance recommendations display
- Loading branch information
Showing
12 changed files
with
305 additions
and
96 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 |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { useEffect, useState } from 'react' | ||
import axios from 'axios' | ||
import { Button } from "@/components/ui/button" | ||
import { ChevronUp, ChevronDown, MessageCircle } from "lucide-react" | ||
import { | ||
AlertDialog, | ||
AlertDialogCancel, | ||
AlertDialogContent, | ||
AlertDialogHeader, | ||
AlertDialogTrigger, | ||
} from "@/components/ui/alert-dialog" | ||
import { Cross1Icon } from "@radix-ui/react-icons"; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
const backendUrl = import.meta.env.VITE_BACKEND_URL || 'http://localhost:5000' | ||
|
||
interface Post { | ||
_id: string | ||
author_username: string | ||
author_profileImage: string | ||
description: string | ||
tags: string | ||
image_link?: string | ||
upvotes: number | ||
downvotes: number | ||
created_at: string | ||
comments: Comment[] | ||
} | ||
|
||
interface Comment { | ||
_id: string | ||
post_id: string | ||
user_username: string | ||
text: string | ||
created_at: string | ||
} | ||
|
||
const ShowPostByID = () => { | ||
const { postId } = useParams<{ postId: string }>(); | ||
const [post, setPost] = useState<Post | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchPost = () => { | ||
axios.get(`${backendUrl}/posts/${postId}`) | ||
.then(response => { | ||
setPost(response.data); | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching post:', error); | ||
}); | ||
}; | ||
fetchPost(); | ||
}, [postId]); | ||
|
||
if (!post) { | ||
return <div>Loading...</div>; | ||
} | ||
return ( | ||
<div className="max-w-2xl mx-auto space-y-0 md:space-y-8"> | ||
<div key={post._id} className="bg-background shadow-lg md:rounded-lg overflow-hidden border"> | ||
<div className="flex items-center border-b p-4"> | ||
<div className="h-10 w-10 rounded-full overflow-hidden"> | ||
<img src={post.author_profileImage} alt={post.author_username} /> | ||
</div> | ||
<div className="ml-3"> | ||
<p className="text-sm font-medium">{post.author_username}</p> | ||
<p className="text-xs text-muted-foreground"> | ||
Posted {new Date(post.created_at).toLocaleDateString()} | ||
</p> | ||
</div> | ||
</div> | ||
{post.image_link && ( | ||
<img | ||
src={post.image_link} | ||
alt="Post image" | ||
className="w-full h-96 object-cover mb-1 border-b" | ||
/> | ||
)} | ||
<div className="flex items-center gap-4 ml-1"> | ||
<Button | ||
variant="ghost" | ||
size="sm" | ||
className="flex items-center gap-1" | ||
> | ||
<ChevronUp className="h-5 w-5" /> | ||
<span>{post.upvotes}</span> | ||
</Button> | ||
<Button | ||
variant="ghost" | ||
size="sm" | ||
className="flex items-center gap-1" | ||
> | ||
<ChevronDown className="h-5 w-5" /> | ||
<span>{post.downvotes}</span> | ||
</Button> | ||
<AlertDialog> | ||
<AlertDialogTrigger asChild> | ||
<Button variant="ghost" size="sm" className="flex items-center gap-1"> | ||
<MessageCircle className="h-5 w-5" /> | ||
<span>{post.comments ? post.comments.length : 0}</span> | ||
</Button> | ||
</AlertDialogTrigger> | ||
|
||
<AlertDialogContent className="grid gap-6 sm:w-80"> | ||
<AlertDialogHeader> | ||
<div className='flex items-center'> | ||
<AlertDialogHeader className='text-2xl'>Comments</AlertDialogHeader> | ||
<div className='flex-grow'></div> | ||
<AlertDialogCancel> | ||
<Cross1Icon className='h-3 w-3' /> | ||
</AlertDialogCancel> | ||
</div> | ||
</AlertDialogHeader> | ||
|
||
{/* Set max height and make it scrollable if needed */} | ||
<div className="max-h-56 overflow-y-auto"> | ||
{/* Reverse the comments to display the latest on top */} | ||
{post.comments && post.comments.slice().reverse().map((comment: Comment) => ( | ||
<div key={comment._id} className="flex items-start gap-2 mb-4"> | ||
<div className="h-8 w-8"> | ||
<img src="/placeholder.svg?height=32&width=32" alt={comment.user_username} /> | ||
</div> | ||
<div> | ||
<p className="text-sm font-medium">{comment.user_username}</p> | ||
<p className="text-sm">{comment.text}</p> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
</div> | ||
<div className='p-4'> | ||
<p className="text-sm mb-2">{post.description}</p> | ||
<div className="flex flex-wrap gap-2 mb-2"> | ||
{JSON.parse(post.tags).map((tag: string, index: number) => ( | ||
<span | ||
key={index} | ||
className="bg-primary/10 text-primary text-xs px-2 py-1 rounded-full" | ||
> | ||
#{tag} | ||
</span> | ||
))} | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default ShowPostByID |
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
42 changes: 0 additions & 42 deletions
42
client/src/components/Recomendations/RecomendationSidebar.tsx
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { cn } from "@/lib/utils"; | ||
|
||
interface MarqueeProps { | ||
className?: string; | ||
reverse?: boolean; | ||
pauseOnHover?: boolean; | ||
children?: React.ReactNode; | ||
vertical?: boolean; | ||
repeat?: number; | ||
[key: string]: any; | ||
} | ||
|
||
export default function Marquee({ | ||
className, | ||
reverse, | ||
pauseOnHover = false, | ||
children, | ||
vertical = false, | ||
repeat = 4, | ||
...props | ||
}: MarqueeProps) { | ||
return ( | ||
<div | ||
{...props} | ||
className={cn( | ||
"group flex overflow-hidden p-2 [--duration:40s] [--gap:1rem] [gap:var(--gap)]", | ||
{ | ||
"flex-row": !vertical, | ||
"flex-col": vertical, | ||
}, | ||
className, | ||
)} | ||
> | ||
{Array(repeat) | ||
.fill(0) | ||
.map((_, i) => ( | ||
<div | ||
key={i} | ||
className={cn("flex shrink-0 justify-around [gap:var(--gap)]", { | ||
"animate-marquee flex-row": !vertical, | ||
"animate-marquee-vertical flex-col": vertical, | ||
"group-hover:[animation-play-state:paused]": pauseOnHover, | ||
"[animation-direction:reverse]": reverse, | ||
})} | ||
> | ||
{children} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.