mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-30 05:34:21 +03:00
feat: change workspaceInfo type
This commit is contained in:
parent
c4a484bbce
commit
30679763ab
@ -20,7 +20,7 @@ export const Input = (props: {
|
||||
const { currentWorkspaceId, workspaceList, currentWorkspace } = useAppState();
|
||||
const isPublish = workspaceList.find(
|
||||
meta => String(meta.id) === String(currentWorkspaceId)
|
||||
)?.isPublish;
|
||||
)?.published;
|
||||
useEffect(() => {
|
||||
inputRef.current?.addEventListener(
|
||||
'blur',
|
||||
|
@ -29,7 +29,7 @@ export const QuickSearch = ({ open, onClose }: TransitionsModalProps) => {
|
||||
const [showCreatePage, setShowCreatePage] = useState(true);
|
||||
const { triggerQuickSearchModal } = useModal();
|
||||
|
||||
const isPublish = currentMetaWorkSpace?.isPublish;
|
||||
const isPublish = currentMetaWorkSpace?.published;
|
||||
|
||||
// Add ‘⌘+K’ shortcut keys as switches
|
||||
useEffect(() => {
|
||||
|
@ -98,7 +98,7 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
|
||||
{item.provider === 'affine' && (
|
||||
<CloudInsyncIcon fontSize={24} />
|
||||
)}
|
||||
{item.isPublish && <UsersIcon fontSize={24} />}
|
||||
{item.published && <UsersIcon fontSize={24} />}
|
||||
</span>
|
||||
{/* {item.isLocal ? 'isLocal' : ''}/ */}
|
||||
</WorkspaceItem>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { styled } from '@/styles';
|
||||
import { WorkspaceInfo } from '@affine/datacenter';
|
||||
import { WorkspaceUnit } from '@affine/datacenter';
|
||||
|
||||
export const ExportPageTitleContainer = styled('div')(() => {
|
||||
return {
|
||||
@ -9,7 +9,7 @@ export const ExportPageTitleContainer = styled('div')(() => {
|
||||
flex: 1,
|
||||
};
|
||||
});
|
||||
export const ExportPage = ({ workspace }: { workspace: WorkspaceInfo }) => {
|
||||
export const ExportPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
|
||||
return (
|
||||
<ExportPageTitleContainer>
|
||||
Export Workspace{' '}
|
||||
|
@ -24,13 +24,13 @@ import { Empty } from '@/ui/empty';
|
||||
// User,
|
||||
// Workspace,
|
||||
// } from '@/hooks/mock-data/mock';
|
||||
import { WorkspaceInfo } from '@affine/datacenter';
|
||||
import { WorkspaceUnit } from '@affine/datacenter';
|
||||
import { useTemporaryHelper } from '@/providers/temporary-helper-provider';
|
||||
import { StyledMemberWarp } from './general/style';
|
||||
import { useConfirm } from '@/providers/ConfirmProvider';
|
||||
|
||||
// import { useAppState } from '@/providers/app-state-provider';
|
||||
export const MembersPage = ({ workspace }: { workspace: WorkspaceInfo }) => {
|
||||
export const MembersPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
|
||||
const [isInviteModalShow, setIsInviteModalShow] = useState(false);
|
||||
const [members, setMembers] = useState<[{ name: string; email: string }]>([
|
||||
{ name: 'affine', email: 'tttt' },
|
||||
|
@ -12,9 +12,9 @@ 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 { WorkspaceInfo } from '@affine/datacenter';
|
||||
import { WorkspaceUnit } from '@affine/datacenter';
|
||||
|
||||
export const PublishPage = ({ workspace }: { workspace: WorkspaceInfo }) => {
|
||||
export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
|
||||
const shareUrl =
|
||||
window.location.host + '/workspace/' + workspace.id + '?share=true';
|
||||
const { publishWorkspace } = useWorkspaceHelper();
|
||||
@ -53,7 +53,7 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceInfo }) => {
|
||||
{workspace.provider === 'cloud' ? (
|
||||
<div>
|
||||
<StyledPublishContent>
|
||||
{workspace?.isPublish ? (
|
||||
{workspace?.published ? (
|
||||
<>
|
||||
<StyledPublishExplanation>
|
||||
Publishing to web requires AFFiNE Cloud service .
|
||||
@ -75,7 +75,7 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceInfo }) => {
|
||||
</StyledPublishExplanation>
|
||||
)}
|
||||
</StyledPublishContent>
|
||||
{workspace.isPublish ? (
|
||||
{workspace.published ? (
|
||||
<Button
|
||||
onClick={() => {
|
||||
togglePublic(false);
|
||||
|
@ -6,13 +6,13 @@ import {
|
||||
import { DownloadIcon } from '@blocksuite/icons';
|
||||
import { Button } from '@/ui/button';
|
||||
import { Menu, MenuItem } from '@/ui/menu';
|
||||
import { WorkspaceInfo } from '@affine/datacenter';
|
||||
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: WorkspaceInfo }) => {
|
||||
export const SyncPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
|
||||
// console.log('workspace: ', workspace);
|
||||
const { enableWorkspace } = useWorkspaceHelper();
|
||||
const { currentWorkspace, user } = useAppState();
|
||||
|
@ -14,9 +14,9 @@ import { WorkspaceDelete } from './delete';
|
||||
import { WorkspaceLeave } from './leave';
|
||||
import { Upload } from '@/components/file-upload';
|
||||
import { WorkspaceAvatar } from '@/components/workspace-avatar';
|
||||
import { WorkspaceInfo } from '@affine/datacenter';
|
||||
import { WorkspaceUnit } from '@affine/datacenter';
|
||||
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper';
|
||||
export const GeneralPage = ({ workspace }: { workspace: WorkspaceInfo }) => {
|
||||
export const GeneralPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
|
||||
const [showDelete, setShowDelete] = useState<boolean>(false);
|
||||
const [showLeave, setShowLeave] = useState<boolean>(false);
|
||||
const [uploading, setUploading] = useState<boolean>(false);
|
||||
|
@ -17,12 +17,12 @@ import {
|
||||
getWorkspaces,
|
||||
// Workspace,
|
||||
} from '@/hooks/mock-data/mock';
|
||||
import { WorkspaceInfo } from '@affine/datacenter';
|
||||
import { WorkspaceUnit } from '@affine/datacenter';
|
||||
|
||||
interface WorkspaceDeleteProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
workspace: WorkspaceInfo;
|
||||
workspace: WorkspaceUnit;
|
||||
}
|
||||
|
||||
export const WorkspaceDelete = ({
|
||||
|
@ -23,14 +23,14 @@ import {
|
||||
} from '@/components/workspace-setting';
|
||||
import { useAppState } from '@/providers/app-state-provider';
|
||||
import WorkspaceLayout from '@/components/workspace-layout';
|
||||
import { WorkspaceInfo } from '@affine/datacenter';
|
||||
import { WorkspaceUnit } from '@affine/datacenter';
|
||||
|
||||
type TabNames = 'general' | 'members' | 'publish' | 'sync' | 'export';
|
||||
|
||||
const tabMap: {
|
||||
name: TabNames;
|
||||
icon: ReactNode;
|
||||
panelRender: (workspace: WorkspaceInfo) => ReactNode;
|
||||
panelRender: (workspace: WorkspaceUnit) => ReactNode;
|
||||
}[] = [
|
||||
{
|
||||
name: 'general',
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
PageMeta,
|
||||
} from './interface';
|
||||
import { createDefaultWorkspace } from './utils';
|
||||
import { WorkspaceInfo, User } from '@affine/datacenter';
|
||||
import { WorkspaceUnit, User } from '@affine/datacenter';
|
||||
|
||||
type AppStateContextProps = PropsWithChildren<Record<string, unknown>>;
|
||||
|
||||
@ -66,12 +66,15 @@ export const AppStateProvider = ({
|
||||
useEffect(() => {
|
||||
const { dataCenter } = appState;
|
||||
// FIXME: onWorkspacesChange should have dispose function
|
||||
dataCenter?.onWorkspacesChange(() => {
|
||||
setAppState({
|
||||
...appState,
|
||||
workspaceList: dataCenter.workspaces,
|
||||
});
|
||||
});
|
||||
dataCenter?.onWorkspacesChange(
|
||||
() => {
|
||||
setAppState({
|
||||
...appState,
|
||||
workspaceList: dataCenter.workspaces,
|
||||
});
|
||||
},
|
||||
{ immediate: false }
|
||||
);
|
||||
}, [appState]);
|
||||
|
||||
const loadPage = useRef<AppStateFunction['loadPage']>();
|
||||
@ -100,7 +103,7 @@ export const AppStateProvider = ({
|
||||
|
||||
const workspace = await dataCenter.loadWorkspace(workspaceId);
|
||||
const currentMetaWorkSpace = dataCenter.workspaces.find(
|
||||
(item: WorkspaceInfo) => {
|
||||
(item: WorkspaceUnit) => {
|
||||
return item.id === workspace.room;
|
||||
}
|
||||
);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DataCenter, User, WorkspaceInfo } from '@affine/datacenter';
|
||||
import { DataCenter, User, WorkspaceUnit } from '@affine/datacenter';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
|
||||
import type {
|
||||
@ -18,9 +18,9 @@ export interface PageMeta extends StorePageMeta {
|
||||
export type AppStateValue = {
|
||||
dataCenter: DataCenter;
|
||||
user: User | null;
|
||||
workspaceList: WorkspaceInfo[];
|
||||
workspaceList: WorkspaceUnit[];
|
||||
currentWorkspace: StoreWorkspace | null;
|
||||
currentMetaWorkSpace: WorkspaceInfo | null;
|
||||
currentMetaWorkSpace: WorkspaceUnit | null;
|
||||
currentWorkspaceId: string;
|
||||
pageList: PageMeta[];
|
||||
currentPage: StorePage | null;
|
||||
|
@ -30,3 +30,4 @@ export type { AccessTokenMessage } from './provider/affine/apis';
|
||||
export { WorkspaceUnit } from './workspace-unit';
|
||||
export { getLogger } from './logger';
|
||||
export * from './message';
|
||||
export * from './types';
|
||||
|
@ -1,127 +0,0 @@
|
||||
import { Observable } from 'lib0/observable';
|
||||
import type { WorkspaceInfo, WorkspaceMeta } from './types';
|
||||
|
||||
export interface WorkspaceMetaCollectionScope {
|
||||
get: (workspaceId: string) => WorkspaceInfo | undefined;
|
||||
list: () => WorkspaceInfo[];
|
||||
add: (workspace: WorkspaceInfo) => void;
|
||||
remove: (workspaceId: string) => boolean;
|
||||
clear: () => void;
|
||||
update: (workspaceId: string, workspaceMeta: Partial<WorkspaceMeta>) => void;
|
||||
}
|
||||
|
||||
export interface WorkspaceMetaCollectionChangeEvent {
|
||||
added?: WorkspaceInfo;
|
||||
deleted?: WorkspaceInfo;
|
||||
updated?: WorkspaceInfo;
|
||||
}
|
||||
|
||||
export class WorkspaceMetaCollection extends Observable<'change'> {
|
||||
private _workspacesMap = new Map<string, WorkspaceInfo>();
|
||||
|
||||
get workspaces(): WorkspaceInfo[] {
|
||||
return Array.from(this._workspacesMap.values());
|
||||
}
|
||||
|
||||
find(workspaceId: string) {
|
||||
return this._workspacesMap.get(workspaceId);
|
||||
}
|
||||
|
||||
createScope(): WorkspaceMetaCollectionScope {
|
||||
const scopedWorkspaceIds = new Set<string>();
|
||||
|
||||
const get = (workspaceId: string) => {
|
||||
if (!scopedWorkspaceIds.has(workspaceId)) {
|
||||
return;
|
||||
}
|
||||
return this._workspacesMap.get(workspaceId);
|
||||
};
|
||||
|
||||
const add = (workspace: WorkspaceInfo) => {
|
||||
if (this._workspacesMap.has(workspace.id)) {
|
||||
throw new Error(`Duplicate workspace id.`);
|
||||
}
|
||||
this._workspacesMap.set(workspace.id.toString(), workspace);
|
||||
scopedWorkspaceIds.add(workspace.id);
|
||||
|
||||
this.emit('change', [
|
||||
{
|
||||
added: workspace,
|
||||
} as WorkspaceMetaCollectionChangeEvent,
|
||||
]);
|
||||
};
|
||||
|
||||
const remove = (workspaceId: string) => {
|
||||
if (!scopedWorkspaceIds.has(workspaceId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const workspace = this._workspacesMap.get(workspaceId);
|
||||
if (workspace) {
|
||||
const ret = this._workspacesMap.delete(workspaceId);
|
||||
// If deletion failed, return.
|
||||
if (!ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
scopedWorkspaceIds.delete(workspaceId);
|
||||
|
||||
this.emit('change', [
|
||||
{
|
||||
deleted: workspace,
|
||||
} as WorkspaceMetaCollectionChangeEvent,
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const clear = () => {
|
||||
scopedWorkspaceIds.forEach(id => {
|
||||
remove(id);
|
||||
});
|
||||
};
|
||||
|
||||
const update = (
|
||||
workspaceId: string,
|
||||
workspaceMeta: Partial<WorkspaceMeta>
|
||||
) => {
|
||||
if (!scopedWorkspaceIds.has(workspaceId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const workspace = this._workspacesMap.get(workspaceId);
|
||||
if (!workspace) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this._workspacesMap.set(workspaceId, { ...workspace, ...workspaceMeta });
|
||||
|
||||
this.emit('change', [
|
||||
{
|
||||
updated: this._workspacesMap.get(workspaceId),
|
||||
} as WorkspaceMetaCollectionChangeEvent,
|
||||
]);
|
||||
};
|
||||
|
||||
// TODO: need to optimize
|
||||
const list = () => {
|
||||
const workspaces: WorkspaceInfo[] = [];
|
||||
scopedWorkspaceIds.forEach(id => {
|
||||
const workspace = this._workspacesMap.get(id);
|
||||
if (workspace) {
|
||||
workspaces.push(workspace);
|
||||
}
|
||||
});
|
||||
return workspaces;
|
||||
};
|
||||
|
||||
return {
|
||||
get,
|
||||
list,
|
||||
add,
|
||||
remove,
|
||||
clear,
|
||||
update,
|
||||
};
|
||||
}
|
||||
}
|
@ -65,7 +65,7 @@ export class WorkspaceUnitCollection {
|
||||
}
|
||||
|
||||
const workspaceUnit = new WorkspaceUnit(workspace);
|
||||
this._workspaceUnitMap.set(workspace.id, workspaceUnit);
|
||||
this._workspaceUnitMap.set(workspace.id.toString(), workspaceUnit);
|
||||
|
||||
scopedWorkspaceIds.add(workspace.id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user