mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
[FIX] Pages Malfunctioning on Load and Recent Pages Computation (#3359)
* fix: fixed `usePage` hook returning context instead of IPageStore * fix: updated recent pages with `updated_at` instead of `created_at` * fix: thown error instead of returning empty array
This commit is contained in:
parent
38580c3940
commit
151c355177
@ -4,8 +4,8 @@ import { StoreContext } from "contexts/store-context";
|
|||||||
// types
|
// types
|
||||||
import { IPageStore } from "store/page.store";
|
import { IPageStore } from "store/page.store";
|
||||||
|
|
||||||
export const usePage = (): any => {
|
export const usePage = (): IPageStore => {
|
||||||
const context = useContext(StoreContext);
|
const context = useContext(StoreContext);
|
||||||
if (context === undefined) throw new Error("usePage must be used within StoreProvider");
|
if (context === undefined) throw new Error("usePage must be used within StoreProvider");
|
||||||
return context as any;
|
return context.page;
|
||||||
};
|
};
|
||||||
|
@ -133,21 +133,21 @@ export class PageStore implements IPageStore {
|
|||||||
get recentProjectPages() {
|
get recentProjectPages() {
|
||||||
if (!this.projectPageIds) return null;
|
if (!this.projectPageIds) return null;
|
||||||
const data: IRecentPages = { today: [], yesterday: [], this_week: [], older: [] };
|
const data: IRecentPages = { today: [], yesterday: [], this_week: [], older: [] };
|
||||||
data.today = this.projectPageIds.filter((p) => isToday(new Date(this.pages?.[p]?.created_at))) || [];
|
data.today = this.projectPageIds.filter((p) => isToday(new Date(this.pages?.[p]?.updated_at))) || [];
|
||||||
data.yesterday = this.projectPageIds.filter((p) => isYesterday(new Date(this.pages?.[p]?.created_at))) || [];
|
data.yesterday = this.projectPageIds.filter((p) => isYesterday(new Date(this.pages?.[p]?.updated_at))) || [];
|
||||||
data.this_week =
|
data.this_week =
|
||||||
this.projectPageIds.filter((p) => {
|
this.projectPageIds.filter((p) => {
|
||||||
const pageCreatedAt = this.pages?.[p]?.created_at;
|
const pageUpdatedAt = this.pages?.[p]?.updated_at;
|
||||||
return (
|
return (
|
||||||
isThisWeek(new Date(pageCreatedAt)) &&
|
isThisWeek(new Date(pageUpdatedAt)) &&
|
||||||
!isToday(new Date(pageCreatedAt)) &&
|
!isToday(new Date(pageUpdatedAt)) &&
|
||||||
!isYesterday(new Date(pageCreatedAt))
|
!isYesterday(new Date(pageUpdatedAt))
|
||||||
);
|
);
|
||||||
}) || [];
|
}) || [];
|
||||||
data.older =
|
data.older =
|
||||||
this.projectPageIds.filter((p) => {
|
this.projectPageIds.filter((p) => {
|
||||||
const pageCreatedAt = this.pages?.[p]?.created_at;
|
const pageUpdatedAt = this.pages?.[p]?.updated_at;
|
||||||
return !isThisWeek(new Date(pageCreatedAt)) && !isYesterday(new Date(pageCreatedAt));
|
return !isThisWeek(new Date(pageUpdatedAt)) && !isYesterday(new Date(pageUpdatedAt));
|
||||||
}) || [];
|
}) || [];
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -184,8 +184,10 @@ export class PageStore implements IPageStore {
|
|||||||
* @param projectId
|
* @param projectId
|
||||||
* @returns Promise<IPage[]>
|
* @returns Promise<IPage[]>
|
||||||
*/
|
*/
|
||||||
fetchProjectPages = async (workspaceSlug: string, projectId: string) =>
|
fetchProjectPages = async (workspaceSlug: string, projectId: string) => {
|
||||||
await this.pageService.getProjectPages(workspaceSlug, projectId).then((response) => {
|
try {
|
||||||
|
return await this.pageService.getProjectPages(workspaceSlug, projectId).then((response) => {
|
||||||
|
console.log("Response from backend 1", response);
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
response.forEach((page) => {
|
response.forEach((page) => {
|
||||||
set(this.pages, [page.id], page);
|
set(this.pages, [page.id], page);
|
||||||
@ -193,6 +195,10 @@ export class PageStore implements IPageStore {
|
|||||||
});
|
});
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches all archived pages for a project.
|
* fetches all archived pages for a project.
|
||||||
|
Loading…
Reference in New Issue
Block a user