From ee6138134d9df3383807789aa63a0f2733e5e8b8 Mon Sep 17 00:00:00 2001 From: DiamondThree <857159145@qq.com> Date: Wed, 11 Jan 2023 12:12:12 +0800 Subject: [PATCH] feat: publish workspace --- .../workspace-setting/MembersPage.tsx | 2 +- .../workspace-setting/PublishPage.tsx | 32 ++++--------------- .../components/workspace-setting/SyncPage.tsx | 26 ++------------- .../app/src/hooks/use-workspace-helper.ts | 32 +++++++++++++++---- .../providers/app-state-provider/Provider.tsx | 2 +- .../data-center/src/provider/affine/affine.ts | 1 + 6 files changed, 38 insertions(+), 57 deletions(-) diff --git a/packages/app/src/components/workspace-setting/MembersPage.tsx b/packages/app/src/components/workspace-setting/MembersPage.tsx index 3859bcbd26..08b2640c97 100644 --- a/packages/app/src/components/workspace-setting/MembersPage.tsx +++ b/packages/app/src/components/workspace-setting/MembersPage.tsx @@ -64,7 +64,7 @@ export const MembersPage = ({ workspace }: { workspace: WorkspaceUnit }) => { return (
- {workspace.provider === 'cloud' ? ( + {workspace.provider === 'affine' ? ( <> diff --git a/packages/app/src/components/workspace-setting/PublishPage.tsx b/packages/app/src/components/workspace-setting/PublishPage.tsx index dce254dc21..c5c39cc2de 100644 --- a/packages/app/src/components/workspace-setting/PublishPage.tsx +++ b/packages/app/src/components/workspace-setting/PublishPage.tsx @@ -9,20 +9,17 @@ import { import { Button } from '@/ui/button'; import Input from '@/ui/input'; import { toast } from '@/ui/toast'; -import { useConfirm } from '@/providers/ConfirmProvider'; // import { useAppState } from '@/providers/app-state-provider3'; -import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; import { WorkspaceUnit } from '@affine/datacenter'; +import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => { const shareUrl = window.location.host + '/workspace/' + workspace.id + '?share=true'; - const { publishWorkspace } = useWorkspaceHelper(); + const { publishWorkspace, enableWorkspace } = useWorkspaceHelper(); - const { confirm } = useConfirm(); - - const togglePublic = (flag: boolean) => { - workspace.id && publishWorkspace(workspace?.id, flag); + const togglePublic = async (flag: boolean) => { + await publishWorkspace(workspace.id.toString(), flag); }; const copyUrl = () => { @@ -30,27 +27,12 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => { toast('Copied url to clipboard'); }; - const enableAffineCloud = () => { - confirm({ - title: 'Enable AFFiNE Cloud?', - content: `If enabled, the data in this workspace will be backed up and synchronized via AFFiNE Cloud.`, - confirmText: - workspace.provider === 'local' ? 'Enable' : 'Sign in and Enable', - cancelText: 'Skip', - }).then(confirm => { - if (confirm) { - // if (user) { - // updateWorkspaceMeta(workspace.id, { type: 'cloud' }); - // } else { - // login(); - // updateWorkspaceMeta(workspace.id, { type: 'cloud' }); - // } - } - }); + const enableAffineCloud = async () => { + await enableWorkspace(); }; return ( <> - {workspace.provider === 'cloud' ? ( + {workspace.provider === 'affine' ? (
{workspace?.published ? ( diff --git a/packages/app/src/components/workspace-setting/SyncPage.tsx b/packages/app/src/components/workspace-setting/SyncPage.tsx index 37ba8ab3f6..d6345a294b 100644 --- a/packages/app/src/components/workspace-setting/SyncPage.tsx +++ b/packages/app/src/components/workspace-setting/SyncPage.tsx @@ -8,16 +8,8 @@ import { Button } from '@/ui/button'; import { Menu, MenuItem } from '@/ui/menu'; import { WorkspaceUnit } from '@affine/datacenter'; import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; -import { useAppState } from '@/providers/app-state-provider'; -import { useConfirm } from '@/providers/ConfirmProvider'; -import { toast } from '@/ui/toast'; -import { useRouter } from 'next/router'; export const SyncPage = ({ workspace }: { workspace: WorkspaceUnit }) => { - // console.log('workspace: ', workspace); const { enableWorkspace } = useWorkspaceHelper(); - const { currentWorkspace, user } = useAppState(); - const { confirm } = useConfirm(); - const router = useRouter(); return (
@@ -31,22 +23,8 @@ export const SyncPage = ({ workspace }: { workspace: WorkspaceUnit }) => {