NewPatch.tsx
Raw
1import type { LabelRow, RepositoryRow } from "../../db/index.ts";
2import { labelTextColor } from "../../lib/labelColor.ts";
3import type { SessionUser } from "../../middleware/session.ts";
4import { Layout } from "../layout.tsx";
5import { RepoHeader } from "../repos/RepoHeader.tsx";
6import { RepoNav } from "../repos/RepoNav.tsx";
7
8interface NewPatchProps {
9 user: SessionUser;
10 repo: RepositoryRow;
11 error?: string;
12 template?: string;
13 labels: LabelRow[];
14}
15
16export function NewPatch({
17 user,
18 repo,
19 error,
20 template,
21 labels,
22}: NewPatchProps) {
23 return (
24 <Layout user={user} title={`New patch — ${repo.name}`}>
25 <div class="container">
26 <RepoHeader repo={repo} />
27 <RepoNav repo={repo} active="patches" user={user} />
28 <h2 class="section-title">Upload patch</h2>
29 {error && <p class="form-error">{error}</p>}
30 <form
31 method="POST"
32 action={`/${repo.name}/patches`}
33 enctype="multipart/form-data"
34 class="form-card"
35 >
36 <div class="form-group">
37 <label for="title">Title</label>
38 <input
39 id="title"
40 name="title"
41 type="text"
42 required
43 placeholder="What does this patch do?"
44 />
45 </div>
46 <div class="form-group">
47 <label for="description">
48 Description{" "}
49 <span class="text-muted">
50 (Markdown supported, optional)
51 </span>
52 </label>
53 <textarea id="description" name="description" rows="5">
54 {template ?? ""}
55 </textarea>
56 </div>
57 <div class="form-group">
58 <label for="patch_file">
59 Patch file <span class="text-muted">(.patch)</span>
60 </label>
61 <input
62 id="patch_file"
63 name="patch_file"
64 type="file"
65 accept=".patch"
66 required
67 />
68 </div>
69 {labels.length > 0 &&
70 (user.isAdmin || repo.allow_user_labels === 1) && (
71 <div class="form-group">
72 <span class="form-group-label">Labels</span>
73 <div class="label-checkbox-list">
74 {labels.map((label) => (
75 <label class="label-checkbox-item">
76 <input
77 type="checkbox"
78 name="label_ids"
79 value={String(label.id)}
80 />
81 <span
82 class="label-badge"
83 style={`background:${label.color};color:${labelTextColor(label.color)}`}
84 >
85 {label.name}
86 </span>
87 </label>
88 ))}
89 </div>
90 </div>
91 )}
92 <div class="form-actions">
93 <button type="submit" class="btn btn-primary">
94 Upload patch
95 </button>
96 <a href={`/${repo.name}/patches`} class="btn">
97 Cancel
98 </a>
99 </div>
100 </form>
101 </div>
102 </Layout>
103 );
104}
105