migration of comments
This commit is contained in:
@@ -6,13 +6,14 @@ import { api } from "~/lib/api";
|
||||
export default function CreatePost() {
|
||||
const [searchParams] = useSearchParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
||||
// TODO: Get actual privilege level from session/auth
|
||||
const privilegeLevel = "anonymous";
|
||||
const userID = null;
|
||||
|
||||
const category = () => searchParams.category === "project" ? "project" : "blog";
|
||||
|
||||
|
||||
const category = () =>
|
||||
searchParams.category === "project" ? "project" : "blog";
|
||||
|
||||
const [title, setTitle] = createSignal("");
|
||||
const [subtitle, setSubtitle] = createSignal("");
|
||||
const [body, setBody] = createSignal("");
|
||||
@@ -24,15 +25,15 @@ export default function CreatePost() {
|
||||
|
||||
const handleSubmit = async (e: Event) => {
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
if (!userID) {
|
||||
setError("You must be logged in to create a post");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
setLoading(true);
|
||||
setError("");
|
||||
|
||||
|
||||
try {
|
||||
const result = await api.database.createPost.mutate({
|
||||
category: category(),
|
||||
@@ -42,9 +43,9 @@ export default function CreatePost() {
|
||||
banner_photo: bannerPhoto() || null,
|
||||
published: published(),
|
||||
tags: tags().length > 0 ? tags() : null,
|
||||
author_id: userID,
|
||||
author_id: userID
|
||||
});
|
||||
|
||||
|
||||
if (result.data) {
|
||||
// Redirect to the new post
|
||||
navigate(`/blog/${encodeURIComponent(title())}`);
|
||||
@@ -59,29 +60,32 @@ export default function CreatePost() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title>Create {category() === "project" ? "Project" : "Blog Post"} | Michael Freno</Title>
|
||||
|
||||
<Title>
|
||||
Create {category() === "project" ? "Project" : "Blog Post"} | Michael
|
||||
Freno
|
||||
</Title>
|
||||
|
||||
<Show
|
||||
when={privilegeLevel === "admin"}
|
||||
fallback={
|
||||
<div class="w-full pt-[30vh] text-center">
|
||||
<div class="text-2xl">Unauthorized</div>
|
||||
<div class="text-gray-600 dark:text-gray-400 mt-4">
|
||||
<div class="text-text text-2xl">Unauthorized</div>
|
||||
<div class="text-subtext0 mt-4">
|
||||
You must be an admin to create posts.
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div class="min-h-screen bg-white dark:bg-zinc-900 py-12 px-4">
|
||||
<div class="max-w-4xl mx-auto">
|
||||
<h1 class="text-4xl font-bold text-center mb-8">
|
||||
<div class="bg-base min-h-screen px-4 py-12">
|
||||
<div class="mx-auto max-w-4xl">
|
||||
<h1 class="mb-8 text-center text-4xl font-bold">
|
||||
Create {category() === "project" ? "Project" : "Blog Post"}
|
||||
</h1>
|
||||
|
||||
|
||||
<form onSubmit={handleSubmit} class="space-y-6">
|
||||
{/* Title */}
|
||||
<div>
|
||||
<label for="title" class="block text-sm font-medium mb-2">
|
||||
<label for="title" class="mb-2 block text-sm font-medium">
|
||||
Title *
|
||||
</label>
|
||||
<input
|
||||
@@ -90,14 +94,14 @@ export default function CreatePost() {
|
||||
required
|
||||
value={title()}
|
||||
onInput={(e) => setTitle(e.currentTarget.value)}
|
||||
class="w-full px-4 py-2 border border-gray-300 rounded-md dark:bg-zinc-800 dark:border-zinc-700"
|
||||
class="border-surface2 bg-surface0 w-full rounded-md border px-4 py-2"
|
||||
placeholder="Enter post title"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Subtitle */}
|
||||
<div>
|
||||
<label for="subtitle" class="block text-sm font-medium mb-2">
|
||||
<label for="subtitle" class="mb-2 block text-sm font-medium">
|
||||
Subtitle
|
||||
</label>
|
||||
<input
|
||||
@@ -105,14 +109,14 @@ export default function CreatePost() {
|
||||
type="text"
|
||||
value={subtitle()}
|
||||
onInput={(e) => setSubtitle(e.currentTarget.value)}
|
||||
class="w-full px-4 py-2 border border-gray-300 rounded-md dark:bg-zinc-800 dark:border-zinc-700"
|
||||
class="border-surface2 bg-surface0 w-full rounded-md border px-4 py-2"
|
||||
placeholder="Enter post subtitle"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Body */}
|
||||
<div>
|
||||
<label for="body" class="block text-sm font-medium mb-2">
|
||||
<label for="body" class="mb-2 block text-sm font-medium">
|
||||
Body (HTML)
|
||||
</label>
|
||||
<textarea
|
||||
@@ -120,14 +124,14 @@ export default function CreatePost() {
|
||||
rows={15}
|
||||
value={body()}
|
||||
onInput={(e) => setBody(e.currentTarget.value)}
|
||||
class="w-full px-4 py-2 border border-gray-300 rounded-md dark:bg-zinc-800 dark:border-zinc-700 font-mono text-sm"
|
||||
class="w-full rounded-md border border-surface2 bg-surface0 px-4 py-2 font-mono text-sm"
|
||||
placeholder="Enter post content (HTML)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Banner Photo URL */}
|
||||
<div>
|
||||
<label for="banner" class="block text-sm font-medium mb-2">
|
||||
<label for="banner" class="mb-2 block text-sm font-medium">
|
||||
Banner Photo URL
|
||||
</label>
|
||||
<input
|
||||
@@ -135,26 +139,33 @@ export default function CreatePost() {
|
||||
type="text"
|
||||
value={bannerPhoto()}
|
||||
onInput={(e) => setBannerPhoto(e.currentTarget.value)}
|
||||
class="w-full px-4 py-2 border border-gray-300 rounded-md dark:bg-zinc-800 dark:border-zinc-700"
|
||||
class="border-surface2 bg-surface0 w-full rounded-md border px-4 py-2"
|
||||
placeholder="Enter banner photo URL"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Tags */}
|
||||
<div>
|
||||
<label for="tags" class="block text-sm font-medium mb-2">
|
||||
<label for="tags" class="mb-2 block text-sm font-medium">
|
||||
Tags (comma-separated)
|
||||
</label>
|
||||
<input
|
||||
id="tags"
|
||||
type="text"
|
||||
value={tags().join(", ")}
|
||||
onInput={(e) => setTags(e.currentTarget.value.split(",").map(t => t.trim()).filter(Boolean))}
|
||||
class="w-full px-4 py-2 border border-gray-300 rounded-md dark:bg-zinc-800 dark:border-zinc-700"
|
||||
onInput={(e) =>
|
||||
setTags(
|
||||
e.currentTarget.value
|
||||
.split(",")
|
||||
.map((t) => t.trim())
|
||||
.filter(Boolean)
|
||||
)
|
||||
}
|
||||
class="border-surface2 bg-surface0 w-full rounded-md border px-4 py-2"
|
||||
placeholder="tag1, tag2, tag3"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Published */}
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
@@ -168,30 +179,30 @@ export default function CreatePost() {
|
||||
Publish immediately
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Error message */}
|
||||
<Show when={error()}>
|
||||
<div class="text-red-500 text-sm">{error()}</div>
|
||||
<div class="text-red text-sm">{error()}</div>
|
||||
</Show>
|
||||
|
||||
|
||||
{/* Submit button */}
|
||||
<div class="flex gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading()}
|
||||
class={`flex-1 px-6 py-3 rounded-md text-white transition-all ${
|
||||
class={`flex-1 rounded-md px-6 py-3 text-base transition-all ${
|
||||
loading()
|
||||
? "bg-gray-400 cursor-not-allowed"
|
||||
: "bg-blue-500 hover:bg-blue-600 active:scale-95"
|
||||
? "bg-blue cursor-not-allowed brightness-50"
|
||||
: "bg-blue hover:brightness-125 active:scale-95"
|
||||
}`}
|
||||
>
|
||||
{loading() ? "Creating..." : "Create Post"}
|
||||
</button>
|
||||
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate("/blog")}
|
||||
class="px-6 py-3 rounded-md border border-gray-300 hover:bg-gray-100 dark:hover:bg-zinc-800 transition-all"
|
||||
class="border-surface2 rounded-md border px-6 py-3 transition-all hover:brightness-125"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user