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:
JimmFly
2023-11-15 07:49:25 +00:00
committed by LongYinan
parent e7e617a791
commit ddd7cab414
39 changed files with 800 additions and 332 deletions

View File

@@ -1,9 +1,6 @@
import { toast } from '@affine/component';
import {
PublicLinkDisableModal,
StyledDisableButton,
} from '@affine/component/share-menu';
import { ShareMenu } from '@affine/component/share-menu';
import { PublicLinkDisableModal } from '@affine/component/disable-public-link';
import { ShareMenu } from '@affine/core/components/affine/share-page-modal/share-menu';
import type {
AffineCloudWorkspace,
LocalWorkspace,
@@ -24,20 +21,6 @@ export default {
},
} satisfies Meta;
const sharePageMap = new Map<string, boolean>([]);
// todo: use a real hook
const useIsSharedPage = (
_workspaceId: string,
pageId: string
): [isSharePage: boolean, setIsSharePage: (enable: boolean) => void] => {
const [isShared, setIsShared] = useState(sharePageMap.get(pageId) ?? false);
const togglePagePublic = (enable: boolean) => {
setIsShared(enable);
sharePageMap.set(pageId, enable);
};
return [isShared, togglePagePublic];
};
async function initPage(page: Page) {
await page.waitForLoaded();
// Add page block and surface block at root level
@@ -88,11 +71,8 @@ export const Basic: StoryFn = () => {
return (
<ShareMenu
currentPage={blockSuiteWorkspace.getPage('page0') as Page}
useIsSharedPage={useIsSharedPage}
workspace={localWorkspace}
onEnableAffineCloud={unimplemented}
togglePagePublic={unimplemented}
exportHandler={unimplemented}
/>
);
};
@@ -119,11 +99,8 @@ export const AffineBasic: StoryFn = () => {
return (
<ShareMenu
currentPage={blockSuiteWorkspace.getPage('page0') as Page}
useIsSharedPage={useIsSharedPage}
workspace={affineWorkspace}
onEnableAffineCloud={unimplemented}
togglePagePublic={unimplemented}
exportHandler={unimplemented}
/>
);
};
@@ -133,9 +110,7 @@ export const DisableModal: StoryFn = () => {
use(promise);
return (
<>
<StyledDisableButton onClick={() => setOpen(!open)}>
Disable Public Link
</StyledDisableButton>
<div onClick={() => setOpen(!open)}>Disable Public Link</div>
<PublicLinkDisableModal
open={open}
onConfirm={() => {