mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 20:16:26 +08:00
refactor: add workspace unit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||
import type { User } from './types';
|
||||
|
||||
export type SyncMode = 'all' | 'core';
|
||||
|
||||
export interface WorkspaceUnitCtorParams {
|
||||
id: string;
|
||||
name: string;
|
||||
avatar?: string;
|
||||
owner?: User;
|
||||
published?: boolean;
|
||||
memberCount: number;
|
||||
provider: string;
|
||||
syncMode: SyncMode;
|
||||
|
||||
blocksuiteWorkspace?: BlocksuiteWorkspace;
|
||||
}
|
||||
|
||||
export type UpdateWorkspaceUnitParams = Partial<
|
||||
Omit<WorkspaceUnitCtorParams, 'id'>
|
||||
>;
|
||||
|
||||
export class WorkspaceUnit {
|
||||
public readonly id: string;
|
||||
public name!: string;
|
||||
public avatar?: string;
|
||||
public owner?: User;
|
||||
public published?: boolean;
|
||||
public memberCount!: number;
|
||||
public provider!: string;
|
||||
public syncMode: 'all' | 'core' = 'core';
|
||||
|
||||
private _blocksuiteWorkspace?: BlocksuiteWorkspace;
|
||||
|
||||
constructor(params: WorkspaceUnitCtorParams) {
|
||||
this.id = params.id;
|
||||
this.update(params);
|
||||
}
|
||||
|
||||
get blocksuiteWorkspace() {
|
||||
return this._blocksuiteWorkspace;
|
||||
}
|
||||
|
||||
setBlocksuiteWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace) {
|
||||
if (blocksuiteWorkspace?.room !== this.id) {
|
||||
throw new Error('Workspace id inconsistent.');
|
||||
}
|
||||
this._blocksuiteWorkspace = blocksuiteWorkspace;
|
||||
}
|
||||
|
||||
update(params: UpdateWorkspaceUnitParams) {
|
||||
Object.assign(this, params);
|
||||
}
|
||||
|
||||
get isPublish() {
|
||||
console.error('Suggest changing to published');
|
||||
return this.published;
|
||||
}
|
||||
|
||||
get isLocal() {
|
||||
console.error('Suggest changing to syncMode');
|
||||
return this.syncMode === 'all';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user