Skip to content

Commit

Permalink
add a refresh button to /admin/manage/irasuto
Browse files Browse the repository at this point in the history
Signed-off-by: Vu Van Dung <me@joulev.dev>
  • Loading branch information
joulev committed Dec 22, 2023
1 parent c9e6ac5 commit 498ae9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/admin/manage/irasuto/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { Collage } from "~/components/irasuto/collage";
import { Card } from "~/components/ui/card";
import { getPhotos } from "~/lib/irasuto/get-photos";

import { RefreshButton } from "./refresh";

export default async function Page() {
const photos = await getPhotos();
return (
<main className="container">
<Card className="p-0">
<Collage photos={photos} allowDelete />
</Card>
<div className="fixed bottom-12 left-1/2 -translate-x-1/2">
<RefreshButton />
</div>
</main>
);
}
8 changes: 8 additions & 0 deletions src/app/admin/manage/irasuto/refresh-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use server";

import { revalidateTag } from "next/cache";

// eslint-disable-next-line @typescript-eslint/require-await -- Server actions must be async
export async function refreshIrasuto() {
revalidateTag("photos");
}
17 changes: 17 additions & 0 deletions src/app/admin/manage/irasuto/refresh.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use client";

import { RotateCcw } from "~/components/icons";
import { Button } from "~/components/ui/button";
import { useTransitionWithNProgress } from "~/lib/hooks/use-transition-with-nprogress";

import { refreshIrasuto } from "./refresh-action";

export function RefreshButton() {
const startTransition = useTransitionWithNProgress();
const refresh = () => startTransition(refreshIrasuto);
return (
<Button onClick={refresh}>
<RotateCcw /> Force-refresh
</Button>
);
}

0 comments on commit 498ae9c

Please sign in to comment.