MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / DocumentTitle

Function DocumentTitle

app/components/DocumentTitle.tsx:7–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { useJsonDoc } from "~/hooks/useJsonDoc";
6
7export function DocumentTitle() {
8 const { doc } = useJsonDoc();
9 const [editedTitle, setEditedTitle] = useState(doc.title);
10 const updateDoc = useFetcher();
11 const ref = useRef<HTMLInputElement | null>(null);
12
13 useEffect(() => {
14 if (updateDoc.type === "done" && updateDoc.data.title) {
15 ref.current?.blur();
16 }
17 }, [updateDoc]);
18
19 if (doc.readOnly) {
20 return (
21 <div
22 className="flex justify-center items-center w-full"
23 title={doc.title}
24 >
25 <span
26 className={
27 "min-w-[15vw] border-none text-ellipsis text-slate-300 px-2 pl-10 py-1 rounded-sm bg-transparent placeholder:text-slate-400 focus:bg-black/30 focus:outline-none focus:border-none hover:cursor-text transition dark:bg-transparent dark:text-slate-200 dark:placeholder:text-slate-400 dark:focus:bg-black dark:focus:bg-opacity-10"
28 }
29 >
30 {doc.title}
31 </span>
32 </div>
33 );
34 } else {
35 return (
36 <updateDoc.Form method="post" action={`/actions/${doc.id}/update`}>
37 <div
38 className="flex justify-center items-center w-full"
39 title={doc.title}
40 >
41 <label className="relative block group">
42 <PencilAltIcon className="h-5 w-5 absolute top-1/2 transform -translate-y-1/2 left-3 text-white opacity-0 transition pointer-events-none group-hover:opacity-80 group-focus:opacity-80" />
43 <input
44 ref={ref}
45 className={
46 "min-w-[15vw] border-none text-ellipsis text-slate-300 px-2 pl-10 py-1 rounded-sm bg-transparent placeholder:text-slate-400 focus:bg-black/30 focus:outline-none focus:border-none hover:bg-black hover:bg-opacity-30 hover:cursor-text transition dark:bg-transparent dark:text-slate-200 dark:placeholder:text-slate-400 dark:focus:bg-black dark:focus:bg-opacity-10 dark:hover:bg-black dark:hover:bg-opacity-10"
47 }
48 type="text"
49 name="title"
50 spellCheck="false"
51 placeholder="Name your JSON file"
52 value={editedTitle}
53 onChange={(e) => setEditedTitle(e.target.value)}
54 />
55 </label>
56
57 {match(editedTitle)
58 .with(doc.title, () => (
59 <p className="ml-2 text-transparent">Save</p>
60 ))
61 .with("", () => (
62 <button
63 className="ml-2 text-lime-500 hover:text-lime-600 transition"
64 onClick={() => setEditedTitle(doc.title)}

Callers

nothing calls this directly

Calls 1

useJsonDocFunction · 0.90

Tested by

no test coverage detected