Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

1.4 KB
Raw Blame
/**
 * Copyright (c) 2023-present Plane Software, Inc. and contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 * See the LICENSE file for details.
 */

import { action, makeObservable, observable, runInAction } from "mobx";
// plane imports
import { SitesCycleService } from "@plane/services";
import type { TPublicCycle } from "@/types/cycle";
// store
import type { RootStore } from "./root.store";

export interface ICycleStore {
  // observables
  cycles: TPublicCycle[] | undefined;
  // computed actions
  getCycleById: (cycleId: string | undefined) => TPublicCycle | undefined;
  // fetch actions
  fetchCycles: (anchor: string) => Promise<TPublicCycle[]>;
}

export class CycleStore implements ICycleStore {
  cycles: TPublicCycle[] | undefined = undefined;
  cycleService: SitesCycleService;
  rootStore: RootStore;

  constructor(_rootStore: RootStore) {
    makeObservable(this, {
      // observables
      cycles: observable,
      // fetch action
      fetchCycles: action,
    });
    this.cycleService = new SitesCycleService();
    this.rootStore = _rootStore;
  }

  getCycleById = (cycleId: string | undefined) => this.cycles?.find((cycle) => cycle.id === cycleId);

  fetchCycles = async (anchor: string) => {
    const cyclesResponse = await this.cycleService.list(anchor);
    runInAction(() => {
      this.cycles = cyclesResponse;
    });
    return cyclesResponse;
  };
}