generated from warmachine028/github-super-starter-kit
-
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.
- Loading branch information
1 parent
5fa32ad
commit 24666f4
Showing
8 changed files
with
164 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { CommentData } from '@/types' | ||
import { useState } from 'react' | ||
import { DeleteCommentDialog } from '.' | ||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '../ui/dropdown-menu' | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip' | ||
import { Button } from '../ui/button' | ||
import { CircleCheckBig, Info, MoreHorizontal, Trash2, TriangleAlert } from 'lucide-react' | ||
import { cn } from '@/lib/utils' | ||
|
||
interface CommentMoreButtonProps { | ||
comment: CommentData | ||
className?: string | ||
} | ||
|
||
const CommentMoreButton = ({ comment, className }: CommentMoreButtonProps) => { | ||
const [showDeleteDialog, setShowDeleteDialog] = useState(false) | ||
return ( | ||
<TooltipProvider> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button size="icon" variant="ghost" className={cn(className, 'data-[state=open]:opacity-100')}> | ||
<MoreHorizontal className="size-5 text-muted-foreground" /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end"> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<DropdownMenuItem onClick={() => setShowDeleteDialog(true)}> | ||
<span className="flex items-center gap-3 text-destructive"> | ||
<Trash2 className="size-4" /> | ||
Delete | ||
</span> | ||
</DropdownMenuItem> | ||
</TooltipTrigger> | ||
<TooltipContent side="left"> | ||
<p>Destructive action</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<DropdownMenuItem> | ||
<span className="flex items-center gap-3 text-success"> | ||
<CircleCheckBig className="size-4" /> | ||
Success | ||
</span> | ||
</DropdownMenuItem> | ||
</TooltipTrigger> | ||
<TooltipContent side="left"> | ||
<p>Success action</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<DropdownMenuItem> | ||
<span className="flex items-center gap-3 text-info"> | ||
<Info className="size-4" /> | ||
Info | ||
</span> | ||
</DropdownMenuItem> | ||
</TooltipTrigger> | ||
<TooltipContent side="left"> | ||
<p>Info action</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<DropdownMenuItem> | ||
<span className="flex items-center gap-3 text-warning"> | ||
<TriangleAlert className="size-4" /> | ||
Warning | ||
</span> | ||
</DropdownMenuItem> | ||
</TooltipTrigger> | ||
<TooltipContent side="left"> | ||
<p>Warning action</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
<DeleteCommentDialog | ||
comment={comment} | ||
open={showDeleteDialog} | ||
onClose={() => setShowDeleteDialog(false)} | ||
/> | ||
</TooltipProvider> | ||
) | ||
} | ||
|
||
CommentMoreButton.displayName = 'CommentMoreButton' | ||
|
||
export default CommentMoreButton |
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 |
---|---|---|
|
@@ -62,4 +62,6 @@ const Comments = ({ post }: CommentProps) => { | |
) | ||
} | ||
|
||
Comments.displayName = 'Comments' | ||
|
||
export default Comments |
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,52 @@ | ||
'use client' | ||
|
||
import { CommentData } from '@/types' | ||
import { useDeleteCommentMutation } from '@/hooks' | ||
import { Dialog, DialogHeader, DialogContent, DialogTitle, DialogDescription, DialogFooter } from '../ui/dialog' | ||
import { LoadingButton } from '@/components' | ||
import { Button } from '../ui/button' | ||
|
||
interface DeleteCommentDialogProps { | ||
comment: CommentData | ||
open: boolean | ||
onClose: () => void | ||
} | ||
|
||
const DeleteCommentDialog = ({ comment, open, onClose }: DeleteCommentDialogProps) => { | ||
const mutation = useDeleteCommentMutation() | ||
|
||
const handleOpenChange = (open: boolean) => { | ||
if (!open || mutation.isPending) { | ||
onClose() | ||
} | ||
} | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={handleOpenChange}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Delete comment?</DialogTitle> | ||
<DialogDescription> | ||
Are you sure you want to delete this comment? This action can't be undone. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<LoadingButton | ||
variant="destructive" | ||
onClick={() => mutation.mutate(comment.id, { onSuccess: onClose })} | ||
loading={mutation.isPending} | ||
> | ||
Delete | ||
</LoadingButton> | ||
<Button variant="outline" onClick={onClose} disabled={mutation.isPending}> | ||
Cancel | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} | ||
|
||
DeleteCommentDialog.displayName = 'DeleteCommentDialog' | ||
|
||
export default DeleteCommentDialog |
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,3 +1,5 @@ | ||
export { default as Comments } from './Comments' | ||
export { default as Input } from './Input' | ||
export { default as Comment } from './Comment' | ||
export { default as CommentMoreButton } from './CommentMoreButton' | ||
export { default as DeleteCommentDialog } from './DeleteCommentDialog' |
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
24666f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-book – ./
next-book-pritam.vercel.app
nextife.vercel.app
next-book-git-main-pritam-kundu.vercel.app
next-book-15.vercel.app
next-boook.vercel.app
nextifly.vercel.app
next-book-pritam-kundu.vercel.app