Yuki Takei 8 месяцев назад
Родитель
Сommit
b4f668b07d

+ 7 - 7
apps/app/src/states/hydrate/page.ts

@@ -26,17 +26,17 @@ import {
  *
  *
  * @example
  * @example
  * // Basic usage
  * // Basic usage
- * useHydratePageAtoms(pageWithMeta?.data ?? null);
+ * useHydratePageAtoms(pageWithMeta?.data);
  *
  *
  * // With template data and custom flags
  * // With template data and custom flags
- * useHydratePageAtoms(pageWithMeta?.data ?? null, {
+ * useHydratePageAtoms(pageWithMeta?.data, {
  *   isLatestRevision: false,
  *   isLatestRevision: false,
  *   templateTags: ['tag1', 'tag2'],
  *   templateTags: ['tag1', 'tag2'],
  *   templateBody: 'Template content'
  *   templateBody: 'Template content'
  * });
  * });
  */
  */
 export const useHydratePageAtoms = (
 export const useHydratePageAtoms = (
-    page: IPagePopulatedToShowRevision | null,
+    page: IPagePopulatedToShowRevision | undefined,
     options?: {
     options?: {
       isNotFound?: boolean;
       isNotFound?: boolean;
       isLatestRevision?: boolean;
       isLatestRevision?: boolean;
@@ -46,8 +46,8 @@ export const useHydratePageAtoms = (
 ): void => {
 ): void => {
   useHydrateAtoms([
   useHydrateAtoms([
     // Core page state - automatically extract from page object
     // Core page state - automatically extract from page object
-    [currentPageIdAtom, page?._id ?? null],
-    [currentPageDataAtom, page ?? null],
+    [currentPageIdAtom, page?._id],
+    [currentPageDataAtom, page],
     [pageNotFoundAtom, options?.isNotFound ?? (page == null)],
     [pageNotFoundAtom, options?.isNotFound ?? (page == null)],
     [latestRevisionAtom, options?.isLatestRevision ?? true],
     [latestRevisionAtom, options?.isLatestRevision ?? true],
 
 
@@ -56,7 +56,7 @@ export const useHydratePageAtoms = (
     [templateContentAtom, options?.templateBody ?? ''],
     [templateContentAtom, options?.templateBody ?? ''],
 
 
     // Remote revision data - auto-extracted from page.revision
     // Remote revision data - auto-extracted from page.revision
-    [remoteRevisionIdAtom, page?.revision?._id ?? null],
-    [remoteRevisionBodyAtom, page?.revision?.body ?? null],
+    [remoteRevisionIdAtom, page?.revision?._id],
+    [remoteRevisionBodyAtom, page?.revision?.body],
   ]);
   ]);
 };
 };

+ 4 - 4
apps/app/src/states/page/hooks.ts

@@ -1,4 +1,4 @@
-import type { IPagePopulatedToShowRevision, IUserHasId } from '@growi/core';
+import type { IPagePopulatedToShowRevision } from '@growi/core';
 import { pagePathUtils } from '@growi/core/dist/utils';
 import { pagePathUtils } from '@growi/core/dist/utils';
 import { useAtom } from 'jotai';
 import { useAtom } from 'jotai';
 
 
@@ -47,12 +47,12 @@ export const useLatestRevision = (): UseAtom<typeof latestRevisionAtom> => {
   return useAtom(latestRevisionAtom);
   return useAtom(latestRevisionAtom);
 };
 };
 
 
-export const useCurrentPagePath = (): readonly [string | null, never] => {
+export const useCurrentPagePath = (): readonly [string | undefined, never] => {
   return useAtom(currentPagePathAtom);
   return useAtom(currentPagePathAtom);
 };
 };
 
 
 // Write hooks for updating page state
 // Write hooks for updating page state
-export const useSetCurrentPage = (): ((page: IPagePopulatedToShowRevision | null) => void) => {
+export const useSetCurrentPage = (): ((page: IPagePopulatedToShowRevision | undefined) => void) => {
   return useAtom(setCurrentPageAtom)[1];
   return useAtom(setCurrentPageAtom)[1];
 };
 };
 
 
@@ -67,7 +67,7 @@ export const useSetTemplateData = (): ((data: { tags?: string[]; body?: string }
 export const useSetRemoteRevisionData = (): ((data: {
 export const useSetRemoteRevisionData = (): ((data: {
   id?: string | null;
   id?: string | null;
   body?: string | null;
   body?: string | null;
-  lastUpdateUser?: IUserHasId | null;
+  lastUpdateUser?: any;
   lastUpdatedAt?: Date | null;
   lastUpdatedAt?: Date | null;
 }) => void) => {
 }) => void) => {
   return useAtom(setRemoteRevisionDataAtom)[1];
   return useAtom(setRemoteRevisionDataAtom)[1];

+ 0 - 1
apps/app/src/states/page/index.ts

@@ -30,7 +30,6 @@ export {
 // Data fetching hooks
 // Data fetching hooks
 export {
 export {
   usePageFetcher,
   usePageFetcher,
-  useInitializePageData,
 } from './page-fetcher';
 } from './page-fetcher';
 
 
 // Template data atoms (these need to be directly accessible for some use cases)
 // Template data atoms (these need to be directly accessible for some use cases)

+ 14 - 14
apps/app/src/states/page/internal-atoms.ts

@@ -1,4 +1,4 @@
-import type { IPagePopulatedToShowRevision, Nullable, IUserHasId } from '@growi/core';
+import type { IPagePopulatedToShowRevision, IUserHasId } from '@growi/core';
 import { pagePathUtils } from '@growi/core/dist/utils';
 import { pagePathUtils } from '@growi/core/dist/utils';
 import { atom } from 'jotai';
 import { atom } from 'jotai';
 
 
@@ -8,8 +8,8 @@ import { atom } from 'jotai';
  */
  */
 
 
 // Core page state atoms (internal)
 // Core page state atoms (internal)
-export const currentPageIdAtom = atom<Nullable<string>>(null);
-export const currentPageDataAtom = atom<IPagePopulatedToShowRevision | null>(null);
+export const currentPageIdAtom = atom<string>();
+export const currentPageDataAtom = atom<IPagePopulatedToShowRevision>();
 export const pageNotFoundAtom = atom(false);
 export const pageNotFoundAtom = atom(false);
 export const latestRevisionAtom = atom(true);
 export const latestRevisionAtom = atom(true);
 
 
@@ -20,20 +20,20 @@ export const templateContentAtom = atom<string>('');
 // Derived atoms for computed states
 // Derived atoms for computed states
 export const currentPagePathAtom = atom((get) => {
 export const currentPagePathAtom = atom((get) => {
   const currentPage = get(currentPageDataAtom);
   const currentPage = get(currentPageDataAtom);
-  return currentPage?.path ?? null;
+  return currentPage?.path;
 });
 });
 
 
 // Additional computed atoms for migrated hooks
 // Additional computed atoms for migrated hooks
 export const currentRevisionIdAtom = atom((get) => {
 export const currentRevisionIdAtom = atom((get) => {
   const currentPage = get(currentPageDataAtom);
   const currentPage = get(currentPageDataAtom);
-  return currentPage?.revision?._id ?? null;
+  return currentPage?.revision?._id;
 });
 });
 
 
 // Remote revision data atoms (migrated from useSWRStatic)
 // Remote revision data atoms (migrated from useSWRStatic)
-export const remoteRevisionIdAtom = atom<string | null>(null);
-export const remoteRevisionBodyAtom = atom<string | null>(null);
-export const remoteRevisionLastUpdateUserAtom = atom<IUserHasId | null>(null);
-export const remoteRevisionLastUpdatedAtAtom = atom<Date | null>(null);
+export const remoteRevisionIdAtom = atom<string>();
+export const remoteRevisionBodyAtom = atom<string>();
+export const remoteRevisionLastUpdateUserAtom = atom<IUserHasId>();
+export const remoteRevisionLastUpdatedAtAtom = atom<Date>();
 
 
 // Enhanced computed atoms that replace SWR-based hooks
 // Enhanced computed atoms that replace SWR-based hooks
 export const isTrashPageAtom = atom((get) => {
 export const isTrashPageAtom = atom((get) => {
@@ -55,7 +55,7 @@ export const isRevisionOutdatedAtom = atom((get) => {
 // Action atoms for state updates
 // Action atoms for state updates
 export const setCurrentPageAtom = atom(
 export const setCurrentPageAtom = atom(
   null,
   null,
-  (get, set, page: IPagePopulatedToShowRevision | null) => {
+  (get, set, page: IPagePopulatedToShowRevision | undefined) => {
     set(currentPageDataAtom, page);
     set(currentPageDataAtom, page);
     if (page?._id) {
     if (page?._id) {
       set(currentPageIdAtom, page._id);
       set(currentPageIdAtom, page._id);
@@ -91,10 +91,10 @@ export const setTemplateDataAtom = atom(
 export const setRemoteRevisionDataAtom = atom(
 export const setRemoteRevisionDataAtom = atom(
   null,
   null,
   (get, set, data: {
   (get, set, data: {
-    id?: string | null;
-    body?: string | null;
-    lastUpdateUser?: IUserHasId | null;
-    lastUpdatedAt?: Date | null;
+    id?: string;
+    body?: string;
+    lastUpdateUser?: IUserHasId;
+    lastUpdatedAt?: Date;
   }) => {
   }) => {
     if (data.id !== undefined) {
     if (data.id !== undefined) {
       set(remoteRevisionIdAtom, data.id);
       set(remoteRevisionIdAtom, data.id);

+ 0 - 13
apps/app/src/states/page/page-fetcher.ts

@@ -90,16 +90,3 @@ export const usePageFetcher = (): SWRMutationResponse<IPagePopulatedToShowRevisi
     fetchAndUpdatePage,
     fetchAndUpdatePage,
   };
   };
 };
 };
-
-/**
- * Hook for initializing page data (replaces useSWRxCurrentPage complexity)
- * This simplifies the shouldMutate logic by using Jotai's reactive state
- */
-export const useInitializePageData = (): ((initialData: IPagePopulatedToShowRevision | null) => void) => {
-  const setCurrentPage = useAtom(setCurrentPageAtom)[1];
-
-  return useCallback((initialData: IPagePopulatedToShowRevision | null) => {
-    // Simple direct update - no complex shouldMutate logic needed
-    setCurrentPage(initialData);
-  }, [setCurrentPage]);
-};