feat: publish workspace

This commit is contained in:
DiamondThree 2023-01-11 12:12:12 +08:00
parent eef467558e
commit ee6138134d
6 changed files with 38 additions and 57 deletions

View File

@ -64,7 +64,7 @@ export const MembersPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
return ( return (
<div> <div>
{workspace.provider === 'cloud' ? ( {workspace.provider === 'affine' ? (
<> <>
<StyledMemberTitleContainer> <StyledMemberTitleContainer>
<StyledMemberNameContainer> <StyledMemberNameContainer>

View File

@ -9,20 +9,17 @@ import {
import { Button } from '@/ui/button'; import { Button } from '@/ui/button';
import Input from '@/ui/input'; import Input from '@/ui/input';
import { toast } from '@/ui/toast'; import { toast } from '@/ui/toast';
import { useConfirm } from '@/providers/ConfirmProvider';
// import { useAppState } from '@/providers/app-state-provider3'; // import { useAppState } from '@/providers/app-state-provider3';
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper';
import { WorkspaceUnit } from '@affine/datacenter'; import { WorkspaceUnit } from '@affine/datacenter';
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper';
export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => { export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
const shareUrl = const shareUrl =
window.location.host + '/workspace/' + workspace.id + '?share=true'; window.location.host + '/workspace/' + workspace.id + '?share=true';
const { publishWorkspace } = useWorkspaceHelper(); const { publishWorkspace, enableWorkspace } = useWorkspaceHelper();
const { confirm } = useConfirm(); const togglePublic = async (flag: boolean) => {
await publishWorkspace(workspace.id.toString(), flag);
const togglePublic = (flag: boolean) => {
workspace.id && publishWorkspace(workspace?.id, flag);
}; };
const copyUrl = () => { const copyUrl = () => {
@ -30,27 +27,12 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
toast('Copied url to clipboard'); toast('Copied url to clipboard');
}; };
const enableAffineCloud = () => { const enableAffineCloud = async () => {
confirm({ await enableWorkspace();
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' });
// }
}
});
}; };
return ( return (
<> <>
{workspace.provider === 'cloud' ? ( {workspace.provider === 'affine' ? (
<div> <div>
<StyledPublishContent> <StyledPublishContent>
{workspace?.published ? ( {workspace?.published ? (

View File

@ -8,16 +8,8 @@ import { Button } from '@/ui/button';
import { Menu, MenuItem } from '@/ui/menu'; import { Menu, MenuItem } from '@/ui/menu';
import { WorkspaceUnit } from '@affine/datacenter'; import { WorkspaceUnit } from '@affine/datacenter';
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; 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 }) => { export const SyncPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
// console.log('workspace: ', workspace);
const { enableWorkspace } = useWorkspaceHelper(); const { enableWorkspace } = useWorkspaceHelper();
const { currentWorkspace, user } = useAppState();
const { confirm } = useConfirm();
const router = useRouter();
return ( return (
<div> <div>
<StyledPublishContent> <StyledPublishContent>
@ -31,22 +23,8 @@ export const SyncPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
<StyledPublishCopyContainer> <StyledPublishCopyContainer>
<Button <Button
onClick={() => { onClick={async () => {
confirm({ await enableWorkspace();
title: 'Enable AFFiNE Cloud?',
content: `If enabled, the data in this workspace will be backed up and synchronized via AFFiNE Cloud.`,
confirmText: user ? 'Enable' : 'Sign in and Enable',
cancelText: 'Skip',
}).then(async confirm => {
if (confirm && currentWorkspace) {
// if (user) {
// await login();
// }
const id = await enableWorkspace(currentWorkspace);
router.push(`/workspace/${id}/setting`);
toast('Enabled success');
}
});
}} }}
type="primary" type="primary"
shape="circle" shape="circle"

View File

@ -1,7 +1,12 @@
import { useAppState } from '@/providers/app-state-provider'; import { useAppState } from '@/providers/app-state-provider';
import { useConfirm } from '@/providers/ConfirmProvider';
import { toast } from '@/ui/toast';
import { Workspace } from '@blocksuite/store'; import { Workspace } from '@blocksuite/store';
import router from 'next/router';
export const useWorkspaceHelper = () => { export const useWorkspaceHelper = () => {
const { dataCenter } = useAppState(); const { confirm } = useConfirm();
const { dataCenter, currentWorkspace, user, login } = useAppState();
const createWorkspace = async (name: string) => { const createWorkspace = async (name: string) => {
const workspaceInfo = await dataCenter.createWorkspace({ const workspaceInfo = await dataCenter.createWorkspace({
name: name, name: name,
@ -16,7 +21,7 @@ export const useWorkspaceHelper = () => {
// const updateWorkspace = async (workspace: Workspace) => {}; // const updateWorkspace = async (workspace: Workspace) => {};
const publishWorkspace = async (workspaceId: string, publish: boolean) => { const publishWorkspace = async (workspaceId: string, publish: boolean) => {
dataCenter.setWorkspacePublish(workspaceId, publish); await dataCenter.setWorkspacePublish(workspaceId, publish);
}; };
const updateWorkspace = async ( const updateWorkspace = async (
@ -32,11 +37,26 @@ export const useWorkspaceHelper = () => {
} }
}; };
const enableWorkspace = async (workspace: Workspace) => { const enableWorkspace = async () => {
const newWorkspaceId = await dataCenter.enableWorkspaceCloud(workspace); confirm({
// console.log('newWorkspace: ', newWorkspace); title: 'Enable AFFiNE Cloud?',
return newWorkspaceId; content: `If enabled, the data in this workspace will be backed up and synchronized via AFFiNE Cloud.`,
confirmText: user ? 'Enable' : 'Sign in and Enable',
cancelText: 'Skip',
}).then(async confirm => {
if (confirm && currentWorkspace) {
if (user) {
await login();
}
const newWorkspaceId = await dataCenter.enableWorkspaceCloud(
currentWorkspace
);
router.push(`/workspace/${newWorkspaceId}/setting`);
toast('Enabled success');
}
});
}; };
return { return {
createWorkspace, createWorkspace,
publishWorkspace, publishWorkspace,

View File

@ -103,7 +103,7 @@ export const AppStateProvider = ({
const workspace = await dataCenter.loadWorkspace(workspaceId); const workspace = await dataCenter.loadWorkspace(workspaceId);
const currentMetaWorkSpace = dataCenter.workspaces.find( const currentMetaWorkSpace = dataCenter.workspaces.find(
(item: WorkspaceUnit) => { (item: WorkspaceUnit) => {
return item.id === workspace.room; return item.id.toString() === workspace.room;
} }
); );

View File

@ -125,6 +125,7 @@ export class AffineProvider extends BaseProvider {
const workspaces: WorkspaceMeta0[] = workspacesList.map(w => { const workspaces: WorkspaceMeta0[] = workspacesList.map(w => {
return { return {
...w, ...w,
published: w.public,
memberCount: 0, memberCount: 0,
name: '', name: '',
provider: 'affine', provider: 'affine',