feat: use provied

This commit is contained in:
DiamondThree
2023-01-06 16:14:10 +08:00
parent 0346b22bdd
commit 726c8c54ab
4 changed files with 18 additions and 23 deletions

View File

@@ -14,10 +14,11 @@ interface ModalProps {
export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
const [workspaceName, setWorkspaceName] = useState('');
const { createWorkspace } = useTemporaryHelper();
const { createWorkspace, setActiveWorkspace } = useTemporaryHelper();
const handleCreateWorkspace = () => {
const { id } = createWorkspace(workspaceName);
onClose({ workspaceId: id });
const workspace = createWorkspace(workspaceName);
onClose({ workspaceId: workspace.id });
setActiveWorkspace(workspace);
};
return (
<div>

View File

@@ -4,14 +4,9 @@ import {
StyledPublishExplanation,
} from './style';
import { DownloadIcon } from '@blocksuite/icons';
import { useEffect, useState } from 'react';
import { Button } from '@/ui/button';
import { Menu, MenuItem } from '@/ui/menu';
import {
deleteMember,
updateWorkspaceMeta,
Workspace,
} from '@/hooks/mock-data/mock';
import { deleteMember, Workspace } from '@/hooks/mock-data/mock';
import { useTemporaryHelper } from '@/providers/temporary-helper-provider';
export const SyncPage = ({ workspace }: { workspace: Workspace }) => {
@@ -20,18 +15,18 @@ export const SyncPage = ({ workspace }: { workspace: Workspace }) => {
return (
<div>
<StyledPublishContent>
{currentWorkspace.type === 'local' ? (
{currentWorkspace?.type === 'local' ? (
<>
<StyledPublishExplanation>
{workspace.name} is Local Workspace. All data is stored on the
current device. You can enable AFFiNE Cloud for this workspace to
keep data in sync with the cloud.
{currentWorkspace.name} is Local Workspace. All data is stored on
the current device. You can enable AFFiNE Cloud for this workspace
to keep data in sync with the cloud.
</StyledPublishExplanation>
<StyledPublishCopyContainer>
<Button
onClick={() => {
updateWorkspaceMeta(workspace.id, {
updateWorkspaceMeta(currentWorkspace.id, {
type: 'cloud',
});
}}
@@ -45,8 +40,8 @@ export const SyncPage = ({ workspace }: { workspace: Workspace }) => {
) : (
<>
<StyledPublishExplanation>
<code>{workspace.name}</code> is Cloud Workspace. All data will be
synchronized and saved to the AFFiNE
<code>{currentWorkspace && currentWorkspace.name}</code> is Cloud
Workspace. All data will be synchronized and saved to the AFFiNE
</StyledPublishExplanation>
<StyledPublishCopyContainer>
<Menu

View File

@@ -15,12 +15,12 @@ import { WorkspaceDelete } from './delete';
import { debounce } from '@/utils';
import { WorkspaceLeave } from './leave';
import { Upload } from '@/components/file-upload';
import { updateWorkspaceMeta, Workspace } from '@/hooks/mock-data/mock';
import { Workspace } from '@/hooks/mock-data/mock';
import { WorkspaceAvatar } from '@/components/workspace-avatar';
import { useTemporaryHelper } from '@/providers/temporary-helper-provider';
export const GeneralPage = ({ workspace }: { workspace: Workspace }) => {
const { refreshWorkspacesMeta } = useAppState();
const { currentWorkspace } = useTemporaryHelper();
const { updateWorkspaceMeta } = useTemporaryHelper();
const [showDelete, setShowDelete] = useState<boolean>(false);
const [showLeave, setShowLeave] = useState<boolean>(false);
const [uploading, setUploading] = useState<boolean>(false);
@@ -47,7 +47,7 @@ export const GeneralPage = ({ workspace }: { workspace: Workspace }) => {
setShowLeave(false);
};
const handleUpdateWorkspaceName = () => {
updateWorkspaceMeta(workspace.id, { name: workspaceName });
workspace && updateWorkspaceMeta(workspace.id, { name: workspaceName });
};
const fileChange = async (file: File) => {

View File

@@ -16,7 +16,6 @@ import {
} from '@blocksuite/icons';
import { useEffect, useState } from 'react';
import { GeneralPage } from './general';
import { getActiveWorkspace } from '@/hooks/mock-data/mock';
import { MembersPage } from './MembersPage';
import { PublishPage } from './PublishPage';
import { SyncPage } from './SyncPage';
@@ -142,16 +141,16 @@ export const WorkspaceSetting = ({
</StyledSettingSidebar>
) : null}
<StyledSettingContent>
{activeTab === ActiveTab.general && (
{activeTab === ActiveTab.general && currentWorkspace && (
<GeneralPage workspace={currentWorkspace} />
)}
{activeTab === ActiveTab.sync && (
{activeTab === ActiveTab.sync && currentWorkspace && (
<SyncPage workspace={currentWorkspace} />
)}
{activeTab === ActiveTab.members && currentWorkspace && (
<MembersPage workspace={currentWorkspace} />
)}
{activeTab === ActiveTab.publish && (
{activeTab === ActiveTab.publish && currentWorkspace && (
<PublishPage workspace={currentWorkspace} />
)}
</StyledSettingContent>