diff --git a/web/hooks/store/use-page.ts b/web/hooks/store/use-page.ts index cc348a4ad..8cd13dcdc 100644 --- a/web/hooks/store/use-page.ts +++ b/web/hooks/store/use-page.ts @@ -4,8 +4,8 @@ import { StoreContext } from "contexts/store-context"; // types import { IPageStore } from "store/page.store"; -export const usePage = (): any => { +export const usePage = (): IPageStore => { const context = useContext(StoreContext); if (context === undefined) throw new Error("usePage must be used within StoreProvider"); - return context as any; + return context.page; }; diff --git a/web/store/page.store.ts b/web/store/page.store.ts index debbad0ff..abb196334 100644 --- a/web/store/page.store.ts +++ b/web/store/page.store.ts @@ -133,21 +133,21 @@ export class PageStore implements IPageStore { get recentProjectPages() { if (!this.projectPageIds) return null; const data: IRecentPages = { today: [], yesterday: [], this_week: [], older: [] }; - data.today = this.projectPageIds.filter((p) => isToday(new Date(this.pages?.[p]?.created_at))) || []; - data.yesterday = this.projectPageIds.filter((p) => isYesterday(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]?.updated_at))) || []; data.this_week = this.projectPageIds.filter((p) => { - const pageCreatedAt = this.pages?.[p]?.created_at; + const pageUpdatedAt = this.pages?.[p]?.updated_at; return ( - isThisWeek(new Date(pageCreatedAt)) && - !isToday(new Date(pageCreatedAt)) && - !isYesterday(new Date(pageCreatedAt)) + isThisWeek(new Date(pageUpdatedAt)) && + !isToday(new Date(pageUpdatedAt)) && + !isYesterday(new Date(pageUpdatedAt)) ); }) || []; data.older = this.projectPageIds.filter((p) => { - const pageCreatedAt = this.pages?.[p]?.created_at; - return !isThisWeek(new Date(pageCreatedAt)) && !isYesterday(new Date(pageCreatedAt)); + const pageUpdatedAt = this.pages?.[p]?.updated_at; + return !isThisWeek(new Date(pageUpdatedAt)) && !isYesterday(new Date(pageUpdatedAt)); }) || []; return data; } @@ -184,15 +184,21 @@ export class PageStore implements IPageStore { * @param projectId * @returns Promise */ - fetchProjectPages = async (workspaceSlug: string, projectId: string) => - await this.pageService.getProjectPages(workspaceSlug, projectId).then((response) => { - runInAction(() => { - response.forEach((page) => { - set(this.pages, [page.id], page); + fetchProjectPages = async (workspaceSlug: string, projectId: string) => { + try { + return await this.pageService.getProjectPages(workspaceSlug, projectId).then((response) => { + console.log("Response from backend 1", response); + runInAction(() => { + response.forEach((page) => { + set(this.pages, [page.id], page); + }); }); + return response; }); - return response; - }); + } catch (error) { + throw error; + } + }; /** * fetches all archived pages for a project.