2022-11-14 20:24:35 -05:00
|
|
|
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-03-22 01:50:25 -04:00
|
|
|
|
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-03-22 01:50:25 -04:00
|
|
|
}) => {
|
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-03-22 01:50:25 -04:00
|
|
|
|
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}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
)
|
2022-03-22 01:50:25 -04:00
|
|
|
}
|
|
|
|
|
2022-11-18 02:39:52 -05:00
|
|
|
export default DocumentList
|