mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
2bf2e98b00
* chore: updated issue filters in space * chore: persisting the query params even when we switch layouts --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
// mobx
|
|
import { observable, action, makeObservable, runInAction } from "mobx";
|
|
// service
|
|
import ProjectService from "@/services/project.service";
|
|
// store types
|
|
import { RootStore } from "@/store/root.store";
|
|
// types
|
|
import { IWorkspace, IProject, IProjectSettings } from "@/types/project";
|
|
|
|
export interface IProjectStore {
|
|
// observables
|
|
loader: boolean;
|
|
error: any | null;
|
|
workspace: IWorkspace | null;
|
|
project: IProject | null;
|
|
settings: IProjectSettings | null;
|
|
canReact: boolean;
|
|
canComment: boolean;
|
|
canVote: boolean;
|
|
// actions
|
|
fetchProjectSettings: (workspace_slug: string, project_slug: string) => Promise<void>;
|
|
hydrate: (projectSettings: any) => void;
|
|
}
|
|
|
|
export class ProjectStore implements IProjectStore {
|
|
// observables
|
|
loader: boolean = false;
|
|
error: any | null = null;
|
|
workspace: IWorkspace | null = null;
|
|
project: IProject | null = null;
|
|
settings: IProjectSettings | null = null;
|
|
canReact: boolean = false;
|
|
canComment: boolean = false;
|
|
canVote: boolean = false;
|
|
// service
|
|
projectService;
|
|
|
|
constructor(private store: RootStore) {
|
|
makeObservable(this, {
|
|
// loaders and error observables
|
|
loader: observable,
|
|
error: observable.ref,
|
|
// observable
|
|
workspace: observable,
|
|
project: observable,
|
|
settings: observable,
|
|
canReact: observable.ref,
|
|
canComment: observable.ref,
|
|
canVote: observable.ref,
|
|
// actions
|
|
fetchProjectSettings: action,
|
|
|
|
hydrate: action,
|
|
// computed
|
|
});
|
|
|
|
// services
|
|
this.projectService = new ProjectService();
|
|
}
|
|
|
|
hydrate = (projectSettings: any) => {
|
|
const { workspace_detail, project_details, votes, comments, reactions } = projectSettings;
|
|
this.workspace = workspace_detail;
|
|
this.project = project_details;
|
|
this.canComment = comments;
|
|
this.canVote = votes;
|
|
this.canReact = reactions;
|
|
};
|
|
|
|
fetchProjectSettings = async (workspace_slug: string, project_slug: string) => {
|
|
try {
|
|
this.loader = true;
|
|
this.error = null;
|
|
|
|
const response = await this.projectService.getProjectSettings(workspace_slug, project_slug);
|
|
|
|
if (response) {
|
|
const currentProject: IProject = { ...response?.project_details };
|
|
const currentWorkspace: IWorkspace = { ...response?.workspace_detail };
|
|
const currentDeploySettings = { ...response };
|
|
this.store.issueFilter.updateLayoutOptions(response?.views);
|
|
runInAction(() => {
|
|
this.project = currentProject;
|
|
this.workspace = currentWorkspace;
|
|
this.settings = currentDeploySettings;
|
|
this.loader = false;
|
|
});
|
|
}
|
|
return response;
|
|
} catch (error) {
|
|
this.loader = false;
|
|
this.error = error;
|
|
return error;
|
|
}
|
|
};
|
|
}
|