-
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.
add trash page and adjust data fetching to fit trash requirements
- Loading branch information
1 parent
ba6c05c
commit e007c25
Showing
12 changed files
with
330 additions
and
20 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
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,87 @@ | ||
import { Metadata } from "next"; | ||
|
||
import { | ||
Table, | ||
TableBody, | ||
TableCaption, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "@/components/ui/table"; | ||
import { getAllNotes } from "@/helpers/notes/getAllNotes"; | ||
|
||
import NotesPagination from "../notes-pagination"; | ||
import RestoreButton from "./restore-button"; | ||
|
||
type Props = { | ||
params: {}; | ||
searchParams: { page?: string }; | ||
}; | ||
|
||
export const metadata: Metadata = { | ||
title: "Trash bin", | ||
}; | ||
|
||
export default async function TrashPage({ searchParams }: Props) { | ||
const currentPage = searchParams.page ? parseInt(searchParams.page) : 1; | ||
|
||
const { count, notes, totalPages } = | ||
(await getAllNotes({ | ||
page: currentPage, | ||
paginate: true, | ||
results: "deleted", | ||
})) ?? {}; | ||
|
||
return ( | ||
<main className="px-6 py-4"> | ||
<div> | ||
<h5 className="font-bold">Trash bin</h5> | ||
</div> | ||
<Table className="mt-4"> | ||
<TableCaption> | ||
A list of your discarded notes (showing {notes?.length ?? 0} of{" "} | ||
{count}) | ||
</TableCaption> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead>Action</TableHead> | ||
<TableHead className="w-[200px]">Title</TableHead> | ||
<TableHead className="w-[300px]">Snippet</TableHead> | ||
<TableHead className="text-right">Updated</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody className="whitespace-nowrap"> | ||
{notes?.map((note) => ( | ||
<TableRow key={note.id}> | ||
<TableCell> | ||
<RestoreButton noteId={note.id} /> | ||
</TableCell> | ||
<TableCell> | ||
{note.title.length > 20 | ||
? note.title.slice(0, 20) + "..." | ||
: note.title} | ||
</TableCell> | ||
<TableCell> | ||
{note.content.length > 50 | ||
? note.content.slice(0, 50) + "..." | ||
: note.content} | ||
</TableCell> | ||
<TableCell className="text-right"> | ||
{new Date(note.updatedAt).toLocaleString()} | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
<NotesPagination | ||
type="trash" | ||
currentPage={currentPage} | ||
totalPages={totalPages} | ||
/> | ||
</main> | ||
); | ||
} | ||
|
||
export const dynamic = "force-dynamic"; | ||
export const fetchCache = "force-no-store"; |
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,26 @@ | ||
"use client"; | ||
|
||
import { ResetIcon } from "@radix-ui/react-icons"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { restoreNote } from "@/helpers/notes/restoreNote"; | ||
|
||
type Props = { | ||
noteId: string; | ||
}; | ||
|
||
export default function RestoreButton({ noteId }: Props) { | ||
const router = useRouter(); | ||
|
||
async function handleRestore() { | ||
await restoreNote(noteId); | ||
router.refresh(); | ||
} | ||
|
||
return ( | ||
<Button variant="outline" size="icon" onClick={handleRestore}> | ||
<ResetIcon /> | ||
</Button> | ||
); | ||
} |
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,33 @@ | ||
"use client"; | ||
|
||
/* eslint-disable react/prop-types */ | ||
/* eslint-disable react/no-unknown-property */ | ||
|
||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"; | ||
import * as React from "react"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
const TooltipProvider = TooltipPrimitive.Provider; | ||
|
||
const Tooltip = TooltipPrimitive.Root; | ||
|
||
const TooltipTrigger = TooltipPrimitive.Trigger; | ||
|
||
const TooltipContent = React.forwardRef< | ||
React.ElementRef<typeof TooltipPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content> | ||
>(({ className, sideOffset = 4, ...props }, ref) => ( | ||
<TooltipPrimitive.Content | ||
ref={ref} | ||
sideOffset={sideOffset} | ||
className={cn( | ||
"animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 overflow-hidden rounded-md bg-slate-900 px-3 py-1.5 text-xs text-slate-50 dark:bg-slate-50 dark:text-slate-900", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TooltipContent.displayName = TooltipPrimitive.Content.displayName; | ||
|
||
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger }; |
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
Oops, something went wrong.