Files
omnivore/packages/web/components/templates/article/SetLabelsModalPresenter.tsx
Jackson Harper e270d4acf9 Warnings clean up
2023-06-20 13:36:36 +08:00

62 lines
1.6 KiB
TypeScript

import { useEffect } from 'react'
import { useSetPageLabels } from '../../../lib/hooks/useSetPageLabels'
import { LabelsProvider } from './SetLabelsControl'
import { SetLabelsModal } from './SetLabelsModal'
import { useSetHighlightLabels } from '../../../lib/hooks/useSetHighlightLabels'
type SetPageLabelsModalPresenterProps = {
articleId: string
article: LabelsProvider
onOpenChange: (open: boolean) => void
}
export function SetPageLabelsModalPresenter(
props: SetPageLabelsModalPresenterProps
): JSX.Element {
const [labels, dispatchLabels] = useSetPageLabels(props.articleId)
useEffect(() => {
dispatchLabels({
type: 'RESET',
labels: props.article.labels ?? [],
})
}, [props.article, dispatchLabels])
return (
<SetLabelsModal
provider={props.article}
selectedLabels={labels.labels}
dispatchLabels={dispatchLabels}
onOpenChange={props.onOpenChange}
/>
)
}
type SetHighlightLabelsModalPresenterProps = {
highlightId: string
highlight: LabelsProvider
onOpenChange: (open: boolean) => void
}
export function SetHighlightLabelsModalPresenter(
props: SetHighlightLabelsModalPresenterProps
): JSX.Element {
const [labels, dispatchLabels] = useSetHighlightLabels(props.highlightId)
useEffect(() => {
dispatchLabels({
type: 'RESET',
labels: props.highlight.labels ?? [],
})
}, [props.highlight, dispatchLabels])
return (
<SetLabelsModal
provider={props.highlight}
selectedLabels={labels.labels}
dispatchLabels={dispatchLabels}
onOpenChange={props.onOpenChange}
/>
)
}