-
Notifications
You must be signed in to change notification settings - Fork 782
/
create-post-button.tsx
36 lines (33 loc) · 1.37 KB
/
create-post-button.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use client";
import { useTransition } from "react";
import { createPost } from "@/lib/actions";
import { cn } from "@/lib/utils";
import { useParams, useRouter } from "next/navigation";
import LoadingDots from "@/components/icons/loading-dots";
import va from "@vercel/analytics";
export default function CreatePostButton() {
const router = useRouter();
const { id } = useParams() as { id: string };
const [isPending, startTransition] = useTransition();
return (
<button
onClick={() =>
startTransition(async () => {
const post = await createPost(null, id, null);
va.track("Created Post");
router.refresh();
router.push(`/post/${post.id}`);
})
}
className={cn(
"flex h-8 w-36 items-center justify-center space-x-2 rounded-lg border text-sm transition-all focus:outline-none sm:h-9",
isPending
? "cursor-not-allowed border-stone-200 bg-stone-100 text-stone-400 dark:border-stone-700 dark:bg-stone-800 dark:text-stone-300"
: "border border-black bg-black text-white hover:bg-white hover:text-black active:bg-stone-100 dark:border-stone-700 dark:hover:border-stone-200 dark:hover:bg-black dark:hover:text-white dark:active:bg-stone-800",
)}
disabled={isPending}
>
{isPending ? <LoadingDots color="#808080" /> : <p>Create New Post</p>}
</button>
);
}