mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-30 00:29:46 +08:00
feat: add shared page filter to all pages (#5540)
Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
@@ -12,9 +12,11 @@ import { useCallback, useMemo } from 'react';
|
||||
|
||||
import { usePageHelper } from '../../components/blocksuite/block-suite-page-list/utils';
|
||||
import { useBlockSuiteMetaHelper } from './use-block-suite-meta-helper';
|
||||
import { usePublicPages } from './use-is-shared-page';
|
||||
|
||||
export const useAllPageListConfig = () => {
|
||||
const currentWorkspace = useService(Workspace);
|
||||
const { getPublicMode } = usePublicPages(currentWorkspace);
|
||||
const workspace = currentWorkspace.blockSuiteWorkspace;
|
||||
const pageMetas = useBlockSuitePageMeta(workspace);
|
||||
const { isPreferredEdgeless } = usePageHelper(workspace);
|
||||
@@ -42,6 +44,7 @@ export const useAllPageListConfig = () => {
|
||||
return {
|
||||
allPages: pageMetas,
|
||||
isEdgeless: isPreferredEdgeless,
|
||||
getPublicMode,
|
||||
workspace: currentWorkspace.blockSuiteWorkspace,
|
||||
getPage: id => pageMap[id],
|
||||
favoriteRender: page => {
|
||||
@@ -55,9 +58,10 @@ export const useAllPageListConfig = () => {
|
||||
},
|
||||
};
|
||||
}, [
|
||||
currentWorkspace.blockSuiteWorkspace,
|
||||
isPreferredEdgeless,
|
||||
pageMetas,
|
||||
isPreferredEdgeless,
|
||||
getPublicMode,
|
||||
currentWorkspace.blockSuiteWorkspace,
|
||||
pageMap,
|
||||
onToggleFavoritePage,
|
||||
]);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { pushNotificationAtom } from '@affine/component/notification-center';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import {
|
||||
getWorkspacePublicPagesQuery,
|
||||
PublicPageMode,
|
||||
@@ -6,6 +7,7 @@ import {
|
||||
revokePublicPageMutation,
|
||||
} from '@affine/graphql';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import type { Workspace } from '@toeverything/infra/workspace';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
@@ -192,3 +194,44 @@ export function useIsSharedPage(
|
||||
[isSharedPage, currentShareMode, enableShare, disableShare, changeShare]
|
||||
);
|
||||
}
|
||||
|
||||
export function usePublicPages(workspace: Workspace) {
|
||||
const isLocalWorkspace = workspace.flavour === WorkspaceFlavour.LOCAL;
|
||||
const { data } = useQuery(
|
||||
isLocalWorkspace
|
||||
? undefined
|
||||
: {
|
||||
query: getWorkspacePublicPagesQuery,
|
||||
variables: {
|
||||
workspaceId: workspace.id,
|
||||
},
|
||||
}
|
||||
);
|
||||
const maybeData = data as typeof data | undefined;
|
||||
|
||||
const publicPages: {
|
||||
id: string;
|
||||
mode: PageMode;
|
||||
}[] = useMemo(
|
||||
() =>
|
||||
maybeData?.workspace.publicPages.map(i => ({
|
||||
id: i.id,
|
||||
mode: i.mode === PublicPageMode.Edgeless ? 'edgeless' : 'page',
|
||||
})) ?? [],
|
||||
[maybeData?.workspace.publicPages]
|
||||
);
|
||||
|
||||
/**
|
||||
* Return `undefined` if the page is not public.
|
||||
*/
|
||||
const getPublicMode = useCallback(
|
||||
(pageId: string) => {
|
||||
return publicPages.find(i => i.id === pageId)?.mode;
|
||||
},
|
||||
[publicPages]
|
||||
);
|
||||
return {
|
||||
publicPages,
|
||||
getPublicMode,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user