Skip to content

Commit

Permalink
Support prefilling new post params from URL (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-sherman authored Nov 6, 2024
1 parent 28d3798 commit db25156
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 9 additions & 3 deletions packages/frontpage/app/(app)/post/new/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import {
} from "@/lib/data/db/constants";
import { InputLengthIndicator } from "@/lib/components/input-length-indicator";

export function NewPostForm() {
export function NewPostForm({
defaultTitle,
defaultUrl,
}: {
defaultTitle?: string;
defaultUrl?: string;
}) {
const [state, action, isPending] = useActionState(newPostAction, null);
const id = useId();
const [title, setTitle] = useState("");
const [url, setUrl] = useState("");
const [title, setTitle] = useState(defaultTitle ?? "");
const [url, setUrl] = useState(defaultUrl ?? "");
return (
<form
action={action}
Expand Down
10 changes: 8 additions & 2 deletions packages/frontpage/app/(app)/post/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ export const metadata: Metadata = {
robots: "noindex, nofollow",
};

export default function NewPost() {
export default async function NewPost(props: {
searchParams: Promise<Record<string, string>>;
}) {
const searchParams = await props.searchParams;
return (
<main className="flex flex-col gap-3">
<h2 className="text-3xl font-bold tracking-tight text-gray-900 dark:text-gray-100">
New post
</h2>
<NewPostForm />
<NewPostForm
defaultTitle={searchParams.title}
defaultUrl={searchParams.url}
/>
</main>
);
}

0 comments on commit db25156

Please sign in to comment.