mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
refactor: move page service to a new folder
This commit is contained in:
parent
05de4d83f3
commit
a5a4cde1d7
@ -6,9 +6,9 @@ import { EditorRefApi, generateJSONfromHTML } from "@plane/editor-core";
|
||||
// hooks
|
||||
import useReloadConfirmations from "@/hooks/use-reload-confirmation";
|
||||
// services
|
||||
import { PageService } from "@/services/page.service";
|
||||
import { ProjectPageService } from "@/services/page";
|
||||
import { IPageStore } from "@/store/pages/page.store";
|
||||
const pageService = new PageService();
|
||||
const projectPageService = new ProjectPageService();
|
||||
|
||||
type Props = {
|
||||
editorRef: React.RefObject<EditorRefApi>;
|
||||
@ -32,7 +32,7 @@ export const usePageDescription = (props: Props) => {
|
||||
const { data: descriptionYJS, mutate: mutateDescriptionYJS } = useSWR(
|
||||
workspaceSlug && projectId && pageId ? `PAGE_DESCRIPTION_${workspaceSlug}_${projectId}_${pageId}` : null,
|
||||
workspaceSlug && projectId && pageId
|
||||
? () => pageService.fetchDescriptionYJS(workspaceSlug.toString(), projectId.toString(), pageId.toString())
|
||||
? () => projectPageService.fetchDescriptionYJS(workspaceSlug.toString(), projectId.toString(), pageId.toString())
|
||||
: null,
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
|
1
web/services/page/index.ts
Normal file
1
web/services/page/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./project-page.service";
|
@ -5,7 +5,7 @@ import { API_BASE_URL } from "@/helpers/common.helper";
|
||||
// services
|
||||
import { APIService } from "@/services/api.service";
|
||||
|
||||
export class PageService extends APIService {
|
||||
export class ProjectPageService extends APIService {
|
||||
constructor() {
|
||||
super(API_BASE_URL);
|
||||
}
|
@ -6,7 +6,7 @@ import { TLogoProps, TPage } from "@plane/types";
|
||||
import { EPageAccess } from "@/constants/page";
|
||||
import { EUserProjectRoles } from "@/constants/project";
|
||||
// services
|
||||
import { PageService } from "@/services/page.service";
|
||||
import { ProjectPageService } from "@/services/page";
|
||||
import { RootStore } from "../root.store";
|
||||
|
||||
export type TLoader = "submitting" | "submitted" | "saved";
|
||||
@ -69,7 +69,7 @@ export class PageStore implements IPageStore {
|
||||
// reactions
|
||||
disposers: Array<() => void> = [];
|
||||
// services
|
||||
pageService: PageService;
|
||||
projectPageService: ProjectPageService;
|
||||
|
||||
constructor(
|
||||
private store: RootStore,
|
||||
@ -144,7 +144,7 @@ export class PageStore implements IPageStore {
|
||||
removeFromFavorites: action,
|
||||
});
|
||||
|
||||
this.pageService = new PageService();
|
||||
this.projectPageService = new ProjectPageService();
|
||||
|
||||
const titleDisposer = reaction(
|
||||
() => this.name,
|
||||
@ -152,7 +152,7 @@ export class PageStore implements IPageStore {
|
||||
const { workspaceSlug, projectId } = this.store.router;
|
||||
if (!workspaceSlug || !projectId || !this.id) return;
|
||||
this.isSubmitting = "submitting";
|
||||
this.pageService
|
||||
this.projectPageService
|
||||
.update(workspaceSlug, projectId, this.id, {
|
||||
name,
|
||||
})
|
||||
@ -299,7 +299,7 @@ export class PageStore implements IPageStore {
|
||||
});
|
||||
});
|
||||
|
||||
await this.pageService.update(workspaceSlug, projectId, this.id, currentPage);
|
||||
await this.projectPageService.update(workspaceSlug, projectId, this.id, currentPage);
|
||||
} catch (error) {
|
||||
runInAction(() => {
|
||||
Object.keys(pageData).forEach((key) => {
|
||||
@ -335,7 +335,7 @@ export class PageStore implements IPageStore {
|
||||
});
|
||||
|
||||
try {
|
||||
await this.pageService.updateDescriptionYJS(workspaceSlug, projectId, this.id, {
|
||||
await this.projectPageService.updateDescriptionYJS(workspaceSlug, projectId, this.id, {
|
||||
description_binary: binaryString,
|
||||
description_html: descriptionHTML,
|
||||
});
|
||||
@ -358,7 +358,7 @@ export class PageStore implements IPageStore {
|
||||
runInAction(() => (this.access = EPageAccess.PUBLIC));
|
||||
|
||||
try {
|
||||
await this.pageService.update(workspaceSlug, projectId, this.id, {
|
||||
await this.projectPageService.update(workspaceSlug, projectId, this.id, {
|
||||
access: EPageAccess.PUBLIC,
|
||||
});
|
||||
} catch (error) {
|
||||
@ -380,7 +380,7 @@ export class PageStore implements IPageStore {
|
||||
runInAction(() => (this.access = EPageAccess.PRIVATE));
|
||||
|
||||
try {
|
||||
await this.pageService.update(workspaceSlug, projectId, this.id, {
|
||||
await this.projectPageService.update(workspaceSlug, projectId, this.id, {
|
||||
access: EPageAccess.PRIVATE,
|
||||
});
|
||||
} catch (error) {
|
||||
@ -401,7 +401,7 @@ export class PageStore implements IPageStore {
|
||||
const pageIsLocked = this.is_locked;
|
||||
runInAction(() => (this.is_locked = true));
|
||||
|
||||
await this.pageService.lock(workspaceSlug, projectId, this.id).catch((error) => {
|
||||
await this.projectPageService.lock(workspaceSlug, projectId, this.id).catch((error) => {
|
||||
runInAction(() => {
|
||||
this.is_locked = pageIsLocked;
|
||||
});
|
||||
@ -419,7 +419,7 @@ export class PageStore implements IPageStore {
|
||||
const pageIsLocked = this.is_locked;
|
||||
runInAction(() => (this.is_locked = false));
|
||||
|
||||
await this.pageService.unlock(workspaceSlug, projectId, this.id).catch((error) => {
|
||||
await this.projectPageService.unlock(workspaceSlug, projectId, this.id).catch((error) => {
|
||||
runInAction(() => {
|
||||
this.is_locked = pageIsLocked;
|
||||
});
|
||||
@ -435,7 +435,7 @@ export class PageStore implements IPageStore {
|
||||
if (!workspaceSlug || !projectId || !this.id) return undefined;
|
||||
|
||||
try {
|
||||
const response = await this.pageService.archive(workspaceSlug, projectId, this.id);
|
||||
const response = await this.projectPageService.archive(workspaceSlug, projectId, this.id);
|
||||
runInAction(() => {
|
||||
this.archived_at = response.archived_at;
|
||||
});
|
||||
@ -452,7 +452,7 @@ export class PageStore implements IPageStore {
|
||||
if (!workspaceSlug || !projectId || !this.id) return undefined;
|
||||
|
||||
try {
|
||||
await this.pageService.restore(workspaceSlug, projectId, this.id);
|
||||
await this.projectPageService.restore(workspaceSlug, projectId, this.id);
|
||||
runInAction(() => {
|
||||
this.archived_at = null;
|
||||
});
|
||||
@ -466,7 +466,7 @@ export class PageStore implements IPageStore {
|
||||
if (!workspaceSlug || !projectId || !this.id) return undefined;
|
||||
|
||||
try {
|
||||
await this.pageService.update(workspaceSlug, projectId, this.id, {
|
||||
await this.projectPageService.update(workspaceSlug, projectId, this.id, {
|
||||
logo_props,
|
||||
});
|
||||
runInAction(() => {
|
||||
@ -489,7 +489,7 @@ export class PageStore implements IPageStore {
|
||||
this.is_favorite = true;
|
||||
});
|
||||
|
||||
await this.pageService.addToFavorites(workspaceSlug, projectId, this.id).catch((error) => {
|
||||
await this.projectPageService.addToFavorites(workspaceSlug, projectId, this.id).catch((error) => {
|
||||
runInAction(() => {
|
||||
this.is_favorite = pageIsFavorite;
|
||||
});
|
||||
@ -509,7 +509,7 @@ export class PageStore implements IPageStore {
|
||||
this.is_favorite = false;
|
||||
});
|
||||
|
||||
await this.pageService.removeFromFavorites(workspaceSlug, projectId, this.id).catch((error) => {
|
||||
await this.projectPageService.removeFromFavorites(workspaceSlug, projectId, this.id).catch((error) => {
|
||||
runInAction(() => {
|
||||
this.is_favorite = pageIsFavorite;
|
||||
});
|
||||
|
@ -7,7 +7,7 @@ import { TPage, TPageFilters, TPageNavigationTabs } from "@plane/types";
|
||||
// helpers
|
||||
import { filterPagesByPageType, getPageName, orderPages, shouldFilterPage } from "@/helpers/page.helper";
|
||||
// services
|
||||
import { PageService } from "@/services/page.service";
|
||||
import { ProjectPageService } from "@/services/page";
|
||||
// store
|
||||
import { IPageStore, PageStore } from "@/store/pages/page.store";
|
||||
import { RootStore } from "../root.store";
|
||||
@ -48,7 +48,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
sortBy: "desc",
|
||||
};
|
||||
// service
|
||||
service: PageService;
|
||||
projectPageService: ProjectPageService;
|
||||
|
||||
constructor(private store: RootStore) {
|
||||
makeObservable(this, {
|
||||
@ -67,7 +67,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
removePage: action,
|
||||
});
|
||||
// service
|
||||
this.service = new PageService();
|
||||
this.projectPageService = new ProjectPageService();
|
||||
// initialize display filters of the current project
|
||||
reaction(
|
||||
() => this.store.router.projectId,
|
||||
@ -159,7 +159,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
this.error = undefined;
|
||||
});
|
||||
|
||||
const pages = await this.service.fetchAll(workspaceSlug, projectId);
|
||||
const pages = await this.projectPageService.fetchAll(workspaceSlug, projectId);
|
||||
runInAction(() => {
|
||||
for (const page of pages) if (page?.id) set(this.data, [page.id], new PageStore(this.store, page));
|
||||
this.loader = undefined;
|
||||
@ -193,7 +193,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
this.error = undefined;
|
||||
});
|
||||
|
||||
const page = await this.service.fetchById(workspaceSlug, projectId, pageId);
|
||||
const page = await this.projectPageService.fetchById(workspaceSlug, projectId, pageId);
|
||||
runInAction(() => {
|
||||
if (page?.id) set(this.data, [page.id], new PageStore(this.store, page));
|
||||
this.loader = undefined;
|
||||
@ -226,7 +226,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
this.error = undefined;
|
||||
});
|
||||
|
||||
const page = await this.service.create(workspaceSlug, projectId, pageData);
|
||||
const page = await this.projectPageService.create(workspaceSlug, projectId, pageData);
|
||||
runInAction(() => {
|
||||
if (page?.id) set(this.data, [page.id], new PageStore(this.store, page));
|
||||
this.loader = undefined;
|
||||
@ -254,7 +254,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
const { workspaceSlug, projectId } = this.store.router;
|
||||
if (!workspaceSlug || !projectId || !pageId) return undefined;
|
||||
|
||||
await this.service.remove(workspaceSlug, projectId, pageId);
|
||||
await this.projectPageService.remove(workspaceSlug, projectId, pageId);
|
||||
runInAction(() => unset(this.data, [pageId]));
|
||||
} catch (error) {
|
||||
runInAction(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user