'use client' import { ReactNode } from "react" import TableGen from "../TableGen" import { Attributes } from "@sequelize/core"; import { Post } from "@/model/Post"; import { useState } from "react"; type Actions = { deletePost:any getPosts:()=>Promise } type Props = { children?:ReactNode; headings:Array; data:any[]; actions?:Actions; } type EditorProps = { open:boolean; post?:Attributes; } function RenderEditor(props:EditorProps){ let [content,setContent] = useState(props.post?.content) let [title,setTitle] = useState(props.post?.title) return

Edit Post

Title

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

Content

} export default function PostTable(props:Props){ function showEditor(entry:Attributes){ setEditor({ open: true, post: entry }) } const initEditorState:EditorProps = { open: false } const [posts, setPosts] = useState(props.data); const [editor, setEditor] = useState(initEditorState) function deletePost(entry:Attributes){ props.actions?.deletePost(entry.id); props.actions?.getPosts().then((p)=>setPosts(JSON.parse(p))); } return <> {posts.map((d)=>{ return <> {d.id} {d.title} {d.content.length<255 ? d.content :`${d.content.substring(0,255)}...`} {d.createdAt} {d.updatedAt} {(editor.open && editor.post && editor.post.id == d.id)? :""} })} }