diff --git a/src/app/(root)/manage/_components/photo-editor.tsx b/src/app/(root)/manage/_components/photo-editor.tsx index 7c34629..bcd3ce0 100644 --- a/src/app/(root)/manage/_components/photo-editor.tsx +++ b/src/app/(root)/manage/_components/photo-editor.tsx @@ -8,6 +8,7 @@ import Text from "@tiptap/extension-text"; import Typography from "@tiptap/extension-typography"; import { Placeholder, UndoRedo } from "@tiptap/extensions"; import { + Editor, EditorContent, useEditor, useEditorState, @@ -18,9 +19,11 @@ import { useEffect } from "react"; export default function Tiptap({ onChange, initContent, + editorRef, }: { onChange: (args: unknown) => void; initContent?: Content; + editorRef: React.RefObject; }) { const editor = useEditor({ extensions: [ @@ -44,6 +47,7 @@ export default function Tiptap({ }, content: initContent, }); + editorRef.current = editor; const editorState = useEditorState({ editor, diff --git a/src/app/(root)/manage/_components/photo-tab.tsx b/src/app/(root)/manage/_components/photo-tab.tsx index 409fbad..1c4668b 100644 --- a/src/app/(root)/manage/_components/photo-tab.tsx +++ b/src/app/(root)/manage/_components/photo-tab.tsx @@ -3,7 +3,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; import Image from "next/image"; import type React from "react"; -import { useState } from "react"; +import { useRef, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import z from "zod"; import type { PhotoData } from "@/server/api/routers/photos/list"; @@ -11,6 +11,7 @@ import { api } from "@/trpc/react"; import DirSvg from "./dir-svg"; import ImageSvg from "./file-svg"; import Tiptap from "./photo-editor"; +import type { Editor } from "@tiptap/react"; // - TODO - Pull this from trpc const FormSchema = z.object({ @@ -123,6 +124,8 @@ function RenderLeaf( export function PhotoTab(): React.JSX.Element { const [selectedImage, setSelectedImage] = useState(); + const editorRef = useRef(null); + const titleRef = useRef(null); const listQuery = api.photos.list.useInfiniteQuery( {}, { @@ -137,6 +140,7 @@ export function PhotoTab(): React.JSX.Element { const { register, handleSubmit, + setValue, control, formState: { errors }, } = useForm({ @@ -164,6 +168,9 @@ export function PhotoTab(): React.JSX.Element { img.src === `https://fly.storage.tigris.dev/joemonk-photos/${path}`, ); setSelectedImage(img); + modifyMutate.reset(); + editorRef.current?.commands.setContent(img?.description ?? null); + setValue("title", img?.title ?? "", { shouldTouch: true }); }; const tree = buildDirectoryTree( @@ -178,6 +185,9 @@ export function PhotoTab(): React.JSX.Element { return (
    + {listQuery.hasNextPage || listQuery.isLoading ? ( + + ) : null} {RenderLeaf(renderedTree, selectImage, selectedImage)}
@@ -196,10 +206,10 @@ export function PhotoTab(): React.JSX.Element { > {`Title ${errors.title ? ` - ${errors.title.message}` : ""}`} )} />