diff --git a/app/components/DocumentTitle.tsx b/app/components/DocumentTitle.tsx index 91c6a9e..9218f6d 100644 --- a/app/components/DocumentTitle.tsx +++ b/app/components/DocumentTitle.tsx @@ -16,52 +16,66 @@ export function DocumentTitle() { } }, [updateDoc]); - const startEditing = useCallback(() => { - ref.current?.select(); - ref.current?.focus(); - }, [ref.current]); - - return ( - + if (doc.readOnly) { + return ( - - - setEditedTitle(e.target.value)} - /> - - - {match(editedTitle) - .with(doc.title, () => Save) - .with("", () => ( - setEditedTitle(doc.title)} - > - Reset - - )) - .otherwise(() => ( - - Save - - ))} + + {doc.title} + - - ); + ); + } else { + return ( + + + + + setEditedTitle(e.target.value)} + /> + + + {match(editedTitle) + .with(doc.title, () => ( + Save + )) + .with("", () => ( + setEditedTitle(doc.title)} + > + Reset + + )) + .otherwise(() => ( + + Save + + ))} + + + ); + } } diff --git a/app/components/Home/HomeInfoBoxSection.tsx b/app/components/Home/HomeInfoBoxSection.tsx index 0d0fc51..a3cc24c 100644 --- a/app/components/Home/HomeInfoBoxSection.tsx +++ b/app/components/Home/HomeInfoBoxSection.tsx @@ -142,7 +142,13 @@ function SampleJSONPreview({ }) { return ( diff --git a/app/components/JsonEditor.tsx b/app/components/JsonEditor.tsx index 8b6c4db..36ad620 100644 --- a/app/components/JsonEditor.tsx +++ b/app/components/JsonEditor.tsx @@ -81,7 +81,7 @@ export function JsonEditor() { diff --git a/app/jsonDoc.server.ts b/app/jsonDoc.server.ts index 336284a..1dc3b24 100644 --- a/app/jsonDoc.server.ts +++ b/app/jsonDoc.server.ts @@ -3,6 +3,7 @@ import { customRandom } from "nanoid"; type BaseJsonDocument = { id: string; title: string; + readOnly: boolean; }; export type RawJsonDocument = BaseJsonDocument & { @@ -17,6 +18,7 @@ export type UrlJsonDocument = BaseJsonDocument & { export type CreateJsonOptions = { ttl?: number; + readOnly?: boolean; metadata?: any; }; @@ -41,11 +43,12 @@ export async function createFromUrl( options?: CreateJsonOptions ): Promise { const docId = createId(); - const doc = { + const doc: JSONDocument = { id: docId, type: "url", url: url.href, title: title ?? url.hostname, + readOnly: options?.readOnly ?? false, }; await DOCUMENTS.put(docId, JSON.stringify(doc), { @@ -62,7 +65,13 @@ export async function createFromRawJson( options?: CreateJsonOptions ): Promise { const docId = createId(); - const doc = { id: docId, type: "raw", contents, title: filename }; + const doc: JSONDocument = { + id: docId, + type: "raw", + contents, + title: filename, + readOnly: options?.readOnly ?? false, + }; await DOCUMENTS.put(docId, JSON.stringify(doc), { expirationTtl: options?.ttl ?? undefined, diff --git a/app/routes/new.tsx b/app/routes/new.tsx index fdac9cd..e3f8723 100644 --- a/app/routes/new.tsx +++ b/app/routes/new.tsx @@ -1,4 +1,4 @@ -import { LoaderFunction, redirect } from "remix"; +import { json, LoaderFunction, redirect } from "remix"; import invariant from "tiny-invariant"; import { sendEvent } from "~/graphJSON.server"; import { @@ -12,6 +12,8 @@ export let loader: LoaderFunction = async ({ request, context }) => { const jsonUrl = url.searchParams.get("url"); const base64EncodedJson = url.searchParams.get("j"); const ttl = url.searchParams.get("ttl"); + const readOnly = url.searchParams.get("readonly"); + const title = url.searchParams.get("title"); if (!jsonUrl && !base64EncodedJson) { return redirect("/"); @@ -27,12 +29,16 @@ export let loader: LoaderFunction = async ({ request, context }) => { invariant(options.ttl >= 60, "ttl must be at least 60 seconds"); } + if (typeof readOnly === "string") { + options.readOnly = readOnly === "true"; + } + if (jsonUrl) { const jsonURL = new URL(jsonUrl); invariant(jsonURL, "url must be a valid URL"); - const doc = await createFromUrl(jsonURL, jsonURL.href, options); + const doc = await createFromUrl(jsonURL, title ?? jsonURL.href, options); context.waitUntil( sendEvent({ @@ -49,7 +55,7 @@ export let loader: LoaderFunction = async ({ request, context }) => { if (base64EncodedJson) { const doc = await createFromRawJson( - "Untitled", + title ?? "Untitled", atob(base64EncodedJson), options );
Save