2024-03-04 14:39:46 +00:00
|
|
|
import { makeObservable, observable } from "mobx";
|
2024-03-04 15:02:36 +00:00
|
|
|
import { WorkspaceModel } from "store/workspace.store";
|
2024-03-04 14:39:46 +00:00
|
|
|
import { DataStore } from ".";
|
|
|
|
import { IWorkspace } from "@plane/types";
|
|
|
|
import { set } from "lodash";
|
|
|
|
|
|
|
|
export interface IWorkspaceData {
|
|
|
|
workspaceMap: Record<string, WorkspaceModel>;
|
|
|
|
|
2024-03-05 07:59:28 +00:00
|
|
|
addWorkspace: (workspaces: IWorkspace) => void;
|
2024-03-04 14:39:46 +00:00
|
|
|
deleteWorkspace: (workspaceId: string) => void;
|
|
|
|
getWorkspacebyId: (workspaceId: string) => WorkspaceModel | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class WorkspaceData implements IWorkspaceData {
|
|
|
|
workspaceMap: Record<string, WorkspaceModel> = {};
|
|
|
|
|
|
|
|
// data store
|
|
|
|
dataStore;
|
|
|
|
|
|
|
|
constructor(_dataStore: DataStore) {
|
|
|
|
makeObservable(this, {
|
|
|
|
workspaceMap: observable,
|
|
|
|
});
|
|
|
|
this.dataStore = _dataStore;
|
|
|
|
}
|
|
|
|
|
2024-03-05 07:59:28 +00:00
|
|
|
addWorkspace = (workspace: IWorkspace) => {
|
|
|
|
set(this.workspaceMap, [workspace.id], new WorkspaceModel(workspace, this.dataStore));
|
2024-03-04 14:39:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
deleteWorkspace = (workspaceId: string) => {
|
|
|
|
delete this.workspaceMap[workspaceId];
|
|
|
|
};
|
|
|
|
|
|
|
|
getWorkspacebyId = (workspaceId: string) => this.workspaceMap[workspaceId];
|
|
|
|
}
|