NewFileForm.tsx
Raw
1import type { RepositoryRow } from "../../db/index.ts";
2import type { SessionUser } from "../../middleware/session.ts";
3import { Layout } from "../layout.tsx";
4import { RepoHeader } from "../repos/RepoHeader.tsx";
5import { RepoNav } from "./RepoNav.tsx";
6
7interface NewFileFormProps {
8 user: SessionUser;
9 repo: RepositoryRow;
10 ref: string;
11 dir?: string;
12 error?: string;
13}
14
15export function NewFileForm({
16 user,
17 repo,
18 ref: treeRef,
19 dir,
20 error,
21}: NewFileFormProps) {
22 const defaultPath = dir ? `${dir}/` : "";
23 const cancelHref = dir
24 ? `/${repo.name}/tree/${treeRef}/${dir}`
25 : `/${repo.name}/tree/${treeRef}`;
26 return (
27 <Layout user={user} title={`New file — ${repo.name}`}>
28 <div class="container">
29 <RepoHeader repo={repo} />
30 <RepoNav repo={repo} active="code" user={user} />
31 {error && <p class="form-error">{error}</p>}
32 <form
33 method="POST"
34 action={`/${repo.name}/new-file/${treeRef}`}
35 >
36 <div class="file-blob-header">
37 <span class="file-blob-name">New file</span>
38 <div class="file-blob-actions">
39 <a href={cancelHref} class="btn btn-sm">
40 Cancel
41 </a>
42 </div>
43 </div>
44 <div class="file-blob-body">
45 <textarea
46 name="content"
47 class="file-edit-textarea"
48 rows="20"
49 spellcheck="false"
50 autocorrect="off"
51 autocapitalize="off"
52 {...{ autocomplete: "off" }}
53 placeholder="File contents..."
54 />
55 </div>
56 <div class="form-card">
57 <p
58 class="form-hint"
59 style="margin-bottom: var(--space-4);"
60 >
61 Creating file on <strong>{treeRef}</strong>
62 </p>
63 <div class="form-group">
64 <label for="file-path">File path</label>
65 <input
66 id="file-path"
67 name="path"
68 type="text"
69 required
70 value={defaultPath}
71 placeholder="path/to/file.txt"
72 class="mono"
73 maxlength="1000"
74 />
75 </div>
76 <div class="form-group">
77 <label for="message">Commit message</label>
78 <textarea
79 id="message"
80 name="message"
81 rows="3"
82 placeholder="Add new file"
83 />
84 </div>
85 <div class="form-actions">
86 <button type="submit" class="btn btn-primary">
87 Create file
88 </button>
89 <a href={cancelHref} class="btn">
90 Cancel
91 </a>
92 </div>
93 </div>
94 </form>
95 </div>
96 </Layout>
97 );
98}
99