mirror of
https://github.com/makeplane/plane
synced 2025-08-07 19:59:33 +00:00
* [WEB-3066] refactor: replace Space Services with Services Package * chore: minor improvements * fix: type --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import clone from "lodash/clone";
|
|
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
|
// plane imports
|
|
import { SitesStateService } from "@plane/services";
|
|
import { IState } from "@plane/types";
|
|
// helpers
|
|
import { sortStates } from "@/helpers/state.helper";
|
|
// store
|
|
import { CoreRootStore } from "./root.store";
|
|
|
|
export interface IStateStore {
|
|
// observables
|
|
states: IState[] | undefined;
|
|
//computed
|
|
sortedStates: IState[] | undefined;
|
|
// computed actions
|
|
getStateById: (stateId: string | undefined) => IState | undefined;
|
|
// fetch actions
|
|
fetchStates: (anchor: string) => Promise<IState[]>;
|
|
}
|
|
|
|
export class StateStore implements IStateStore {
|
|
states: IState[] | undefined = undefined;
|
|
stateService: SitesStateService;
|
|
rootStore: CoreRootStore;
|
|
|
|
constructor(_rootStore: CoreRootStore) {
|
|
makeObservable(this, {
|
|
// observables
|
|
states: observable,
|
|
// computed
|
|
sortedStates: computed,
|
|
// fetch action
|
|
fetchStates: action,
|
|
});
|
|
this.stateService = new SitesStateService();
|
|
this.rootStore = _rootStore;
|
|
}
|
|
|
|
get sortedStates() {
|
|
if (!this.states) return;
|
|
return sortStates(clone(this.states));
|
|
}
|
|
|
|
getStateById = (stateId: string | undefined) => this.states?.find((state) => state.id === stateId);
|
|
|
|
fetchStates = async (anchor: string) => {
|
|
const statesResponse = await this.stateService.list(anchor);
|
|
runInAction(() => {
|
|
this.states = statesResponse;
|
|
});
|
|
return statesResponse;
|
|
};
|
|
}
|