2022-03-22 01:50:25 -04:00
|
|
|
import type { Document } from "@lib/types"
|
2022-03-23 00:18:26 -04:00
|
|
|
import DocumentComponent from "@components/edit-document"
|
2022-03-22 01:50:25 -04:00
|
|
|
import { ChangeEvent, memo, 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-03-22 01:50:25 -04:00
|
|
|
}) => {
|
2022-04-09 20:48:19 -04:00
|
|
|
const handleOnChange = useCallback(
|
|
|
|
(i) => (e: ChangeEvent<HTMLTextAreaElement>) => {
|
|
|
|
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)}
|
|
|
|
setContent={updateDocContent(i)}
|
|
|
|
setTitle={updateDocTitle(i)}
|
|
|
|
handleOnContentChange={handleOnChange(i)}
|
|
|
|
content={content}
|
|
|
|
title={title}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
)
|
2022-03-22 01:50:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(DocumentList)
|