diff --git a/packages/component/src/components/page-list/view/create-collection.tsx b/packages/component/src/components/page-list/view/create-collection.tsx index 86e8a596f4..11405e6476 100644 --- a/packages/component/src/components/page-list/view/create-collection.tsx +++ b/packages/component/src/components/page-list/view/create-collection.tsx @@ -22,22 +22,15 @@ import { import { FilterList } from '../filter'; import * as styles from './collection-list.css'; -type CreateCollectionProps = { +interface EditCollectionModelProps { + init?: Collection; title?: string; - init: Collection; - onConfirm: (collection: Collection) => void; - onConfirmText?: string; + open: boolean; getPageInfo: GetPageInfoById; propertiesMeta: PropertiesMeta; -}; - -type SaveCollectionButtonProps = { - onConfirm: (collection: Collection) => Promise; - getPageInfo: GetPageInfoById; - propertiesMeta: PropertiesMeta; - filterList: Filter[]; - workspaceId: string; -}; + onClose: () => void; + onConfirm: (view: Collection) => Promise; +} export const EditCollectionModel = ({ init, @@ -47,15 +40,7 @@ export const EditCollectionModel = ({ getPageInfo, propertiesMeta, title, -}: { - init?: Collection; - onConfirm: (view: Collection) => Promise; - open: boolean; - onClose: () => void; - title?: string; - getPageInfo: GetPageInfoById; - propertiesMeta: PropertiesMeta; -}) => { +}: EditCollectionModelProps) => { const t = useAFFiNEI18N(); const onConfirmOnCollection = useCallback( (view: Collection) => { @@ -95,47 +80,46 @@ export const EditCollectionModel = ({ ); }; -const Page = ({ - id, - onClick, - getPageInfo, -}: { +interface PageProps { id: string; - onClick: (id: string) => void; getPageInfo: GetPageInfoById; -}) => { + onClick: (id: string) => void; +} + +const Page = ({ id, onClick, getPageInfo }: PageProps) => { const page = getPageInfo(id); - if (!page) { - return null; - } - const icon = page.isEdgeless ? ( - - ) : ( - - ); - const click = () => { - onClick(id); - }; + const handleClick = useCallback(() => onClick(id), [id, onClick]); return ( -
-
{icon}
-
{page.title}
-
- -
-
+ <> + {page ? ( +
+
+ {page.isEdgeless ? ( + + ) : ( + + )} +
+
{page.title}
+
+ +
+
+ ) : null} + ); }; + +interface EditCollectionProps { + title?: string; + onConfirmText?: string; + init: Collection; + getPageInfo: GetPageInfoById; + propertiesMeta: PropertiesMeta; + onCancel: () => void; + onConfirm: (collection: Collection) => void; +} + export const EditCollection = ({ title, init, @@ -144,9 +128,7 @@ export const EditCollection = ({ onConfirmText, getPageInfo, propertiesMeta, -}: CreateCollectionProps & { - onCancel: () => void; -}) => { +}: EditCollectionProps) => { const t = useAFFiNEI18N(); const [value, onChange] = useState(init); const removeFromExcludeList = useCallback( @@ -223,13 +205,8 @@ export const EditCollection = ({ - onChange({ - ...value, - filterList: list, - }) - } - > + onChange={filterList => onChange({ ...value, filterList })} + /> {value.allowList ? (
With follow pages:
@@ -253,12 +230,7 @@ export const EditCollection = ({ data-testid="input-collection-title" placeholder={t['Untitled Collection']()} defaultValue={value.name} - onChange={text => - onChange({ - ...value, - name: text, - }) - } + onChange={name => onChange({ ...value, name })} />
@@ -288,6 +260,15 @@ export const EditCollection = ({ ); }; + +interface SaveCollectionButtonProps { + getPageInfo: GetPageInfoById; + propertiesMeta: PropertiesMeta; + filterList: Filter[]; + workspaceId: string; + onConfirm: (collection: Collection) => Promise; +} + export const SaveCollectionButton = ({ onConfirm, getPageInfo, diff --git a/packages/component/src/ui/confirm/confirm.tsx b/packages/component/src/ui/confirm/confirm.tsx index 5b6342d828..01e4cc0242 100644 --- a/packages/component/src/ui/confirm/confirm.tsx +++ b/packages/component/src/ui/confirm/confirm.tsx @@ -1,5 +1,6 @@ import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { Button } from '@toeverything/components/button'; +import { useCallback, useMemo } from 'react'; import type { ModalProps } from '../modal'; import { Modal, ModalCloseButton } from '../modal'; @@ -39,33 +40,36 @@ export const Confirm = ({ confirmButtonTestId = '', }: ConfirmProps) => { const t = useAFFiNEI18N(); + const cancelText_ = useMemo(() => { + return cancelText === 'Cancel' ? t['Cancel']() : cancelText; + }, [cancelText, t]); + + const handleCancel = useCallback(() => { + onCancel?.(); + }, [onCancel]); + const handleConfirm = useCallback(() => { + onConfirm?.(); + }, [onConfirm]); + return ( - { - onCancel?.(); - }} - /> + {title} {content} {buttonDirection === 'row' ? ( )}