import { ActionResult } from "@/app/lib/actions/ActionResult"; import { handleActionResult } from "@/app/lib/actions/clientActionHandler"; import { Post, Project, Bucket, PostBucket, Attachment } from "@/model/Models"; import { Attributes } from "@sequelize/core"; import { UUID } from "crypto"; import { ChangeEventHandler, MouseEventHandler, useLayoutEffect, useRef, useState } from "react"; import { Accordion, AccordionBody, AccordionHeader, AccordionItem } from "react-bootstrap"; export type PostTableCallbacks = { savePost: (p:Partial>)=>any; closeEditor: ()=>any; } type PostEditorBucket = Partial> & { attachments:Partial>[] } type PostEditorPost = Partial> & { buckets:PostEditorBucket[] } export type EditorProps = { open:boolean; post:PostEditorPost; projects?:Attributes[]; callbacks:PostTableCallbacks; } export default function PostEditor(props:EditorProps){ let [content,setContent] = useState(props.post?.content) let [title,setTitle] = useState(props.post?.title) let [projectID,setProjectID] = useState(props.post?.project_id) let textbox:any = useRef(undefined); function adjustHeight() { if(!textbox.current || !textbox.current.style) return textbox.current.style.height = "fit-content"; textbox.current.style.height = `${textbox.current.scrollHeight}px`; } useLayoutEffect(adjustHeight, []); const onTextAreaChange:ChangeEventHandler = (e) => {setContent(e.target.value);adjustHeight()}; const projectSelectionChange:ChangeEventHandler = (e)=>setProjectID(parseInt(e.target.value)); const onClickSaveButton:MouseEventHandler = (e)=>{ props.callbacks.savePost({ id: props.post.id as number, content:content as string, title:title as string, }); } const onClickCancelButton:MouseEventHandler = (e)=>{props.callbacks.closeEditor();} return <>

Edit Post

Title

setTitle(e.target.value)} type='text' className="m-2">

Content

Project

Attachments

{ (()=>{ let bucketMap:Map = new Map(props.post.buckets.map((b)=>[b.id as UUID,b])); let bucketList = [...props.post.buckets.map((b)=>b.id)]; return bucketList.map((e)=>{ return {e}
    {bucketMap.get(e as UUID)?.attachments.map((attachment)=>
  • {attachment.filename}
  • )}
}) })() } ...
Buckets
...
}