refactor: create collection (#3406)
This commit is contained in:
@@ -3,11 +3,12 @@ import {
|
|||||||
EditCollectionModel,
|
EditCollectionModel,
|
||||||
useCollectionManager,
|
useCollectionManager,
|
||||||
} from '@affine/component/page-list';
|
} from '@affine/component/page-list';
|
||||||
|
import type { Collection } from '@affine/env/filter';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { PlusIcon } from '@blocksuite/icons';
|
import { PlusIcon } from '@blocksuite/icons';
|
||||||
import type { Workspace } from '@blocksuite/store';
|
import type { Workspace } from '@blocksuite/store';
|
||||||
import { uuidv4 } from '@blocksuite/store';
|
import { uuidv4 } from '@blocksuite/store';
|
||||||
import { useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
|
||||||
import { useGetPageInfoById } from '../../../../hooks/use-get-page-info';
|
import { useGetPageInfoById } from '../../../../hooks/use-get-page-info';
|
||||||
|
|
||||||
@@ -22,18 +23,23 @@ export const AddCollectionButton = ({
|
|||||||
const setting = useCollectionManager(workspace.id);
|
const setting = useCollectionManager(workspace.id);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
const [show, showUpdateCollection] = useState(false);
|
const [show, showUpdateCollection] = useState(false);
|
||||||
const defaultCollection = {
|
const [defaultCollection, setDefaultCollection] = useState<Collection>();
|
||||||
id: uuidv4(),
|
const handleClick = useCallback(() => {
|
||||||
name: '',
|
showUpdateCollection(true);
|
||||||
pinned: true,
|
setDefaultCollection({
|
||||||
filterList: [],
|
id: uuidv4(),
|
||||||
workspaceId: workspace.id,
|
name: '',
|
||||||
};
|
pinned: true,
|
||||||
|
filterList: [],
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
});
|
||||||
|
}, [showUpdateCollection, workspace.id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<IconButton
|
<IconButton
|
||||||
data-testid="slider-bar-add-collection-button"
|
data-testid="slider-bar-add-collection-button"
|
||||||
onClick={() => showUpdateCollection(true)}
|
onClick={handleClick}
|
||||||
size="small"
|
size="small"
|
||||||
>
|
>
|
||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import type { WorkspaceHeaderProps } from '@affine/env/workspace';
|
|||||||
import { WorkspaceFlavour, WorkspaceSubPath } from '@affine/env/workspace';
|
import { WorkspaceFlavour, WorkspaceSubPath } from '@affine/env/workspace';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { SettingsIcon } from '@blocksuite/icons';
|
import { SettingsIcon } from '@blocksuite/icons';
|
||||||
import { uuidv4 } from '@blocksuite/store';
|
|
||||||
import type { ReactElement } from 'react';
|
import type { ReactElement } from 'react';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
@@ -71,13 +70,9 @@ export function WorkspaceHeader({
|
|||||||
currentWorkspace.blockSuiteWorkspace.meta.properties
|
currentWorkspace.blockSuiteWorkspace.meta.properties
|
||||||
}
|
}
|
||||||
getPageInfo={getPageInfoById}
|
getPageInfo={getPageInfoById}
|
||||||
init={{
|
|
||||||
id: uuidv4(),
|
|
||||||
name: '',
|
|
||||||
filterList: setting.currentCollection.filterList,
|
|
||||||
workspaceId: currentWorkspaceId,
|
|
||||||
}}
|
|
||||||
onConfirm={saveToCollection}
|
onConfirm={saveToCollection}
|
||||||
|
filterList={setting.currentCollection.filterList}
|
||||||
|
workspaceId={currentWorkspaceId}
|
||||||
></SaveCollectionButton>
|
></SaveCollectionButton>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Collection } from '@affine/env/filter';
|
import type { Collection, Filter } from '@affine/env/filter';
|
||||||
import type { PropertiesMeta } from '@affine/env/filter';
|
import type { PropertiesMeta } from '@affine/env/filter';
|
||||||
import type { GetPageInfoById } from '@affine/env/page-info';
|
import type { GetPageInfoById } from '@affine/env/page-info';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
RemoveIcon,
|
RemoveIcon,
|
||||||
SaveIcon,
|
SaveIcon,
|
||||||
} from '@blocksuite/icons';
|
} from '@blocksuite/icons';
|
||||||
|
import { uuidv4 } from '@blocksuite/store';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -29,6 +30,15 @@ type CreateCollectionProps = {
|
|||||||
getPageInfo: GetPageInfoById;
|
getPageInfo: GetPageInfoById;
|
||||||
propertiesMeta: PropertiesMeta;
|
propertiesMeta: PropertiesMeta;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type SaveCollectionButtonProps = {
|
||||||
|
onConfirm: (collection: Collection) => void;
|
||||||
|
getPageInfo: GetPageInfoById;
|
||||||
|
propertiesMeta: PropertiesMeta;
|
||||||
|
filterList: Filter[];
|
||||||
|
workspaceId: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const EditCollectionModel = ({
|
export const EditCollectionModel = ({
|
||||||
init,
|
init,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
@@ -266,17 +276,28 @@ export const EditCollection = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
export const SaveCollectionButton = ({
|
export const SaveCollectionButton = ({
|
||||||
init,
|
|
||||||
onConfirm,
|
onConfirm,
|
||||||
getPageInfo,
|
getPageInfo,
|
||||||
propertiesMeta,
|
propertiesMeta,
|
||||||
}: CreateCollectionProps) => {
|
filterList,
|
||||||
|
workspaceId,
|
||||||
|
}: SaveCollectionButtonProps) => {
|
||||||
const [show, changeShow] = useState(false);
|
const [show, changeShow] = useState(false);
|
||||||
|
const [init, setInit] = useState<Collection>();
|
||||||
|
const handleClick = useCallback(() => {
|
||||||
|
changeShow(true);
|
||||||
|
setInit({
|
||||||
|
id: uuidv4(),
|
||||||
|
name: '',
|
||||||
|
filterList,
|
||||||
|
workspaceId,
|
||||||
|
});
|
||||||
|
}, [changeShow, workspaceId, filterList]);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => changeShow(true)}
|
onClick={handleClick}
|
||||||
data-testid="save-as-collection"
|
data-testid="save-as-collection"
|
||||||
icon={<SaveIcon />}
|
icon={<SaveIcon />}
|
||||||
size="large"
|
size="large"
|
||||||
|
|||||||
Reference in New Issue
Block a user