CoastalCommitsPastes/client/app/(posts)/new/components/edit-document-list/index.tsx

45 lines
956 B
TypeScript
Raw Normal View History

import type { Document } from "../new"
2022-11-12 03:58:21 -05:00
import DocumentComponent from "./edit-document"
2022-12-04 04:31:51 -05:00
import { ChangeEvent, useCallback } from "react"
2022-04-09 20:48:19 -04:00
const DocumentList = ({
docs,
removeDoc,
updateDocContent,
updateDocTitle,
onPaste
}: {
docs: Document[]
updateDocTitle: (i: number) => (title: string) => void
updateDocContent: (i: number) => (content: string) => void
removeDoc: (i: number) => () => void
onPaste: (e: any) => void
}) => {
2022-04-09 20:48:19 -04:00
const handleOnChange = useCallback(
2022-04-09 20:54:08 -04:00
(i: number) => (e: ChangeEvent<HTMLTextAreaElement>) => {
2022-04-09 20:48:19 -04:00
updateDocContent(i)(e.target.value)
},
[updateDocContent]
)
2022-04-09 20:48:19 -04:00
return (
<>
{docs.map(({ content, id, title }, i) => {
return (
<DocumentComponent
onPaste={onPaste}
key={id}
remove={removeDoc(i)}
setTitle={updateDocTitle(i)}
handleOnContentChange={handleOnChange(i)}
content={content}
title={title}
/>
)
})}
</>
)
}
export default DocumentList