mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 00:37:05 +08:00
feat(core): support share edgeless mode (#4856)
Close #3287 <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at d3fdf86</samp> ### Summary 📄🚀🔗 <!-- 1. 📄 - This emoji represents the page and edgeless modes of sharing a page, as well as the GraphQL operations and types related to public pages. 2. 🚀 - This emoji represents the functionality of publishing and revoking public pages, as well as the confirmation modal and the notifications for the user. 3. 🔗 - This emoji represents the sharing URL and the query parameter for the share mode, as well as the hooks and functions that generate and use the URL. --> This pull request adds a feature to the frontend component of AFFiNE that allows the user to share a page in either `page` or `edgeless` mode, which affects the appearance and functionality of the page. It also adds the necessary GraphQL operations, types, and schema to support this feature in the backend, and updates the tests and the storybook stories accordingly. * Modify the `useIsSharedPage` hook to accept an optional `shareMode` argument and use the `getWorkspacePublicPagesQuery`, `publishPageMutation`, and `revokePublicPageMutation` from `@affine/graphql`
This commit is contained in:
@@ -3,6 +3,7 @@ import { DebugLogger } from '@affine/debug';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { getOrCreateWorkspace } from '@affine/workspace/manager';
|
||||
import { downloadBinaryFromCloud } from '@affine/workspace/providers';
|
||||
import type { CloudDoc } from '@affine/workspace/providers/cloud';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { noop } from 'foxact/noop';
|
||||
@@ -18,12 +19,25 @@ import {
|
||||
import { applyUpdate } from 'yjs';
|
||||
|
||||
import { PageDetailEditor } from '../../adapters/shared';
|
||||
import type { PageMode } from '../../atoms';
|
||||
import { AppContainer } from '../../components/affine/app-container';
|
||||
import { ShareHeader } from '../../components/share-header';
|
||||
import { SharePageNotFoundError } from '../../components/share-page-not-found-error';
|
||||
|
||||
function assertArrayBuffer(value: unknown): asserts value is ArrayBuffer {
|
||||
if (!(value instanceof ArrayBuffer)) {
|
||||
throw new Error('value is not ArrayBuffer');
|
||||
type LoaderData = {
|
||||
page: Page;
|
||||
publishMode: PageMode;
|
||||
};
|
||||
|
||||
function assertDownloadResponse(
|
||||
value: CloudDoc | boolean
|
||||
): asserts value is CloudDoc {
|
||||
if (
|
||||
!value ||
|
||||
!((value as CloudDoc).arrayBuffer instanceof ArrayBuffer) ||
|
||||
typeof (value as CloudDoc).publishMode !== 'string'
|
||||
) {
|
||||
throw new Error('value is not a valid download response');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,33 +55,42 @@ export const loader: LoaderFunction = async ({ params }) => {
|
||||
);
|
||||
// download root workspace
|
||||
{
|
||||
const buffer = await downloadBinaryFromCloud(workspaceId, workspaceId);
|
||||
assertArrayBuffer(buffer);
|
||||
applyUpdate(workspace.doc, new Uint8Array(buffer));
|
||||
const response = await downloadBinaryFromCloud(workspaceId, workspaceId);
|
||||
assertDownloadResponse(response);
|
||||
const { arrayBuffer } = response;
|
||||
applyUpdate(workspace.doc, new Uint8Array(arrayBuffer));
|
||||
}
|
||||
const page = workspace.getPage(pageId);
|
||||
assertExists(page, 'cannot find page');
|
||||
// download page
|
||||
{
|
||||
const buffer = await downloadBinaryFromCloud(
|
||||
workspaceId,
|
||||
page.spaceDoc.guid
|
||||
);
|
||||
assertArrayBuffer(buffer);
|
||||
applyUpdate(page.spaceDoc, new Uint8Array(buffer));
|
||||
}
|
||||
|
||||
const response = await downloadBinaryFromCloud(
|
||||
workspaceId,
|
||||
page.spaceDoc.guid
|
||||
);
|
||||
assertDownloadResponse(response);
|
||||
const { arrayBuffer, publishMode } = response;
|
||||
|
||||
applyUpdate(page.spaceDoc, new Uint8Array(arrayBuffer));
|
||||
|
||||
logger.info('workspace', workspace);
|
||||
workspace.awarenessStore.setReadonly(page, true);
|
||||
return page;
|
||||
return { page, publishMode };
|
||||
};
|
||||
|
||||
export const Component = (): ReactElement => {
|
||||
const page = useLoaderData() as Page;
|
||||
const { page, publishMode } = useLoaderData() as LoaderData;
|
||||
return (
|
||||
<AppContainer>
|
||||
<MainContainer>
|
||||
<ShareHeader
|
||||
workspace={page.workspace}
|
||||
pageId={page.id}
|
||||
publishMode={publishMode}
|
||||
/>
|
||||
<PageDetailEditor
|
||||
isPublic
|
||||
publishMode={publishMode}
|
||||
workspace={page.workspace}
|
||||
pageId={page.id}
|
||||
onLoad={useCallback(() => noop, [])}
|
||||
|
||||
Reference in New Issue
Block a user