plane/space/store/publish/publish.store.ts

115 lines
3.4 KiB
TypeScript
Raw Normal View History

import { observable, makeObservable, computed } from "mobx";
2024-06-04 16:13:36 +00:00
// types
import { IWorkspaceLite } from "@plane/types";
2024-06-04 08:08:47 +00:00
// store types
import { RootStore } from "@/store/root.store";
// types
2024-06-04 16:13:36 +00:00
import { TProjectDetails, TViewDetails } from "@/types/project";
import { TPublishEntityType, TPublishSettings } from "@/types/publish";
2024-06-04 08:08:47 +00:00
export interface IPublishStore extends TPublishSettings {
// computed
workspaceSlug: string | undefined;
2024-06-04 13:37:35 +00:00
canComment: boolean;
canReact: boolean;
canVote: boolean;
}
2024-06-04 08:08:47 +00:00
export class PublishStore implements IPublishStore {
// observables
anchor: string | undefined;
2024-06-05 13:52:32 +00:00
is_comments_enabled: boolean;
2024-06-04 08:08:47 +00:00
created_at: string | undefined;
created_by: string | undefined;
entity_identifier: string | undefined;
entity_name: TPublishEntityType | undefined;
2024-06-04 08:08:47 +00:00
id: string | undefined;
inbox: unknown;
project: string | undefined;
project_details: TProjectDetails | undefined;
2024-06-05 13:52:32 +00:00
is_reactions_enabled: boolean;
2024-06-04 08:08:47 +00:00
updated_at: string | undefined;
updated_by: string | undefined;
view_props: TViewDetails | undefined;
2024-06-05 13:52:32 +00:00
is_votes_enabled: boolean;
2024-06-04 08:08:47 +00:00
workspace: string | undefined;
2024-06-04 16:13:36 +00:00
workspace_detail: IWorkspaceLite | undefined;
2024-06-04 08:08:47 +00:00
constructor(
private store: RootStore,
publishSettings: TPublishSettings
) {
this.anchor = publishSettings.anchor;
2024-06-05 13:52:32 +00:00
this.is_comments_enabled = publishSettings.is_comments_enabled;
2024-06-04 08:08:47 +00:00
this.created_at = publishSettings.created_at;
this.created_by = publishSettings.created_by;
this.entity_identifier = publishSettings.entity_identifier;
this.entity_name = publishSettings.entity_name;
2024-06-04 08:08:47 +00:00
this.id = publishSettings.id;
this.inbox = publishSettings.inbox;
this.project = publishSettings.project;
this.project_details = publishSettings.project_details;
2024-06-05 13:52:32 +00:00
this.is_reactions_enabled = publishSettings.is_reactions_enabled;
2024-06-04 08:08:47 +00:00
this.updated_at = publishSettings.updated_at;
this.updated_by = publishSettings.updated_by;
this.view_props = publishSettings.view_props;
2024-06-05 13:52:32 +00:00
this.is_votes_enabled = publishSettings.is_votes_enabled;
2024-06-04 08:08:47 +00:00
this.workspace = publishSettings.workspace;
this.workspace_detail = publishSettings.workspace_detail;
makeObservable(this, {
// observables
anchor: observable.ref,
2024-06-05 13:52:32 +00:00
is_comments_enabled: observable.ref,
2024-06-04 08:08:47 +00:00
created_at: observable.ref,
created_by: observable.ref,
entity_identifier: observable.ref,
entity_name: observable.ref,
2024-06-04 08:08:47 +00:00
id: observable.ref,
inbox: observable,
project: observable.ref,
project_details: observable,
2024-06-05 13:52:32 +00:00
is_reactions_enabled: observable.ref,
2024-06-04 08:08:47 +00:00
updated_at: observable.ref,
updated_by: observable.ref,
view_props: observable,
2024-06-05 13:52:32 +00:00
is_votes_enabled: observable.ref,
2024-06-04 08:08:47 +00:00
workspace: observable.ref,
workspace_detail: observable,
// computed
workspaceSlug: computed,
2024-06-04 13:37:35 +00:00
canComment: computed,
canReact: computed,
canVote: computed,
2024-06-04 08:08:47 +00:00
});
}
2024-06-04 13:37:35 +00:00
/**
* @description returns the workspace slug from the workspace details
*/
get workspaceSlug() {
return this?.workspace_detail?.slug ?? undefined;
}
2024-06-04 13:37:35 +00:00
/**
* @description returns whether commenting is enabled or not
*/
get canComment() {
2024-06-05 13:52:32 +00:00
return !!this.is_comments_enabled;
2024-06-04 13:37:35 +00:00
}
/**
* @description returns whether reacting is enabled or not
*/
get canReact() {
2024-06-05 13:52:32 +00:00
return !!this.is_reactions_enabled;
2024-06-04 13:37:35 +00:00
}
/**
* @description returns whether voting is enabled or not
*/
get canVote() {
2024-06-05 13:52:32 +00:00
return !!this.is_votes_enabled;
2024-06-04 13:37:35 +00:00
}
2024-06-04 08:08:47 +00:00
}