Commit 111813c7 authored by StyleZhang's avatar StyleZhang

feat: notion-page-selector

parent 68daf79f
...@@ -9,9 +9,9 @@ import { fetchDataSource } from '@/service/common' ...@@ -9,9 +9,9 @@ import { fetchDataSource } from '@/service/common'
import type { DataSourceNotionPage } from '@/models/common' import type { DataSourceNotionPage } from '@/models/common'
type NotionPageSelectorProps = { type NotionPageSelectorProps = {
onSelect: (selectedPages: DataSourceNotionPage[]) => void onSelect: (selectedPages: (DataSourceNotionPage & { workspace_id: string })[]) => void
canPreview?: boolean canPreview?: boolean
onPreview?: (selectedPage: DataSourceNotionPage) => void onPreview?: (selectedPage: DataSourceNotionPage & { workspace_id: string }) => void
} }
const NotionPageSelector = ({ const NotionPageSelector = ({
...@@ -32,6 +32,22 @@ const NotionPageSelector = ({ ...@@ -32,6 +32,22 @@ const NotionPageSelector = ({
const handleSelectWorkspace = useCallback((workspaceId: string) => { const handleSelectWorkspace = useCallback((workspaceId: string) => {
setCurrentWorkspaceId(workspaceId) setCurrentWorkspaceId(workspaceId)
}, []) }, [])
const handleSelecPages = (selectedPages: DataSourceNotionPage[]) => {
onSelect(selectedPages.map((item) => {
return {
...item,
workspace_id: currentWorkspace?.source_info.workspace_id || '',
}
}))
}
const handlePreviewPage = (previewPage: DataSourceNotionPage) => {
if (onPreview) {
onPreview({
...previewPage,
workspace_id: currentWorkspace?.source_info.workspace_id || '',
})
}
}
useEffect(() => { useEffect(() => {
setCurrentWorkspaceId(firstWorkspace) setCurrentWorkspaceId(firstWorkspace)
...@@ -57,9 +73,9 @@ const NotionPageSelector = ({ ...@@ -57,9 +73,9 @@ const NotionPageSelector = ({
currentWorkspace?.source_info.pages.length && ( currentWorkspace?.source_info.pages.length && (
<PageSelector <PageSelector
list={currentWorkspace?.source_info.pages} list={currentWorkspace?.source_info.pages}
onSelect={onSelect} onSelect={handleSelecPages}
canPreview={canPreview} canPreview={canPreview}
onPreview={onPreview} onPreview={handlePreviewPage}
/> />
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment