source: frontend/src/components/CreateBlogForm.tsx@ 700e2f9

main
Last change on this file since 700e2f9 was 700e2f9, checked in by 186079 <matej.milevski@…>, 5 days ago

Init

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[700e2f9]1import { type Component, createSignal } from "solid-js";
2
3interface CreateBlogFormProps {
4 onSubmit: (title: string, content: string) => Promise<void>;
5 onCancel: () => void;
6}
7
8const CreateBlogForm: Component<CreateBlogFormProps> = (props) => {
9 const [title, setTitle] = createSignal("");
10 const [content, setContent] = createSignal("");
11 const [submitting, setSubmitting] = createSignal(false);
12
13 const handleSubmit = async (e: Event) => {
14 e.preventDefault();
15 setSubmitting(true);
16 try {
17 await props.onSubmit(title(), content());
18 setTitle("");
19 setContent("");
20 } finally {
21 setSubmitting(false);
22 }
23 };
24
25 return (
26 <div class="mb-8 bg-white p-6 rounded-lg shadow-md border border-gray-200">
27 <h2 class="text-xl font-semibold mb-4">Create New Post</h2>
28 <form onSubmit={handleSubmit}>
29 <div class="mb-4">
30 <label
31 for="title"
32 class="block text-sm font-medium text-gray-700 mb-1"
33 >
34 Title
35 </label>
36 <input
37 id="title"
38 type="text"
39 required
40 class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
41 value={title()}
42 onInput={(e) => setTitle(e.currentTarget.value)}
43 placeholder="Enter blog title..."
44 />
45 </div>
46 <div class="mb-4">
47 <label
48 for="content"
49 class="block text-sm font-medium text-gray-700 mb-1"
50 >
51 Content
52 </label>
53 <textarea
54 id="content"
55 required
56 rows={6}
57 class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none"
58 value={content()}
59 onInput={(e) => setContent(e.currentTarget.value)}
60 placeholder="Share your thoughts..."
61 />
62 </div>
63 <button
64 type="submit"
65 disabled={submitting()}
66 class="w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:bg-gray-400 transition-colors"
67 >
68 {submitting() ? "Posting..." : "Post"}
69 </button>
70 </form>
71 </div>
72 );
73};
74
75export default CreateBlogForm;
Note: See TracBrowser for help on using the repository browser.