Yuki Takei 3 лет назад
Родитель
Сommit
6996279e12

+ 1 - 1
packages/app/package.json

@@ -185,7 +185,7 @@
     "string-width": "=4.2.2",
     "string-width": "=4.2.2",
     "superjson": "^1.9.1",
     "superjson": "^1.9.1",
     "swagger-jsdoc": "^6.1.0",
     "swagger-jsdoc": "^6.1.0",
-    "swr": "^1.3.0",
+    "swr": "^2.0.2",
     "throttle-debounce": "^3.0.1",
     "throttle-debounce": "^3.0.1",
     "toastr": "^2.1.2",
     "toastr": "^2.1.2",
     "uglifycss": "^0.0.29",
     "uglifycss": "^0.0.29",

+ 1 - 1
packages/app/src/stores/activity.ts

@@ -12,7 +12,7 @@ export const useSWRxActivity = (limit?: number, offset?: number, searchFilter?:
   const stringifiedSearchFilter = JSON.stringify(searchFilter);
   const stringifiedSearchFilter = JSON.stringify(searchFilter);
   return useSWRImmutable(
   return useSWRImmutable(
     auditLogEnabled ? ['/activity', limit, offset, stringifiedSearchFilter] : null,
     auditLogEnabled ? ['/activity', limit, offset, stringifiedSearchFilter] : null,
-    (endpoint, limit, offset, stringifiedSearchFilter) => apiv3Get(endpoint, { limit, offset, searchFilter: stringifiedSearchFilter })
+    ([endpoint, limit, offset, stringifiedSearchFilter]) => apiv3Get(endpoint, { limit, offset, searchFilter: stringifiedSearchFilter })
       .then(result => result.data.serializedPaginationResult),
       .then(result => result.data.serializedPaginationResult),
   );
   );
 };
 };

+ 1 - 1
packages/app/src/stores/attachment.tsx

@@ -23,7 +23,7 @@ type IDataAttachmentList = {
 export const useSWRxAttachments = (pageId?: Nullable<string>, pageNumber?: number): SWRResponseWithUtils<Util, IDataAttachmentList, Error> => {
 export const useSWRxAttachments = (pageId?: Nullable<string>, pageNumber?: number): SWRResponseWithUtils<Util, IDataAttachmentList, Error> => {
   const shouldFetch = pageId != null && pageNumber != null;
   const shouldFetch = pageId != null && pageNumber != null;
 
 
-  const fetcher = useCallback(async(endpoint, pageId, pageNumber) => {
+  const fetcher = useCallback(async([endpoint, pageId, pageNumber]) => {
     const res = await apiv3Get<IResAttachmentList>(endpoint, { pageId, pageNumber });
     const res = await apiv3Get<IResAttachmentList>(endpoint, { pageId, pageNumber });
     const resAttachmentList = res.data;
     const resAttachmentList = res.data;
     const { paginateResult } = resAttachmentList;
     const { paginateResult } = resAttachmentList;

+ 1 - 1
packages/app/src/stores/comment.tsx

@@ -20,7 +20,7 @@ export const useSWRxPageComment = (pageId: Nullable<string>): SWRResponse<IComme
 
 
   const swrResponse = useSWR(
   const swrResponse = useSWR(
     shouldFetch ? ['/comments.get', pageId] : null,
     shouldFetch ? ['/comments.get', pageId] : null,
-    (endpoint, pageId) => apiGet(endpoint, { page_id: pageId }).then((response:IResponseComment) => response.comments),
+    ([endpoint, pageId]) => apiGet(endpoint, { page_id: pageId }).then((response:IResponseComment) => response.comments),
   );
   );
 
 
   const update = async(comment: string, revisionId: string, commentId: string) => {
   const update = async(comment: string, revisionId: string, commentId: string) => {

+ 2 - 2
packages/app/src/stores/context.tsx

@@ -234,7 +234,7 @@ export const useIsGuestUser = (): SWRResponse<boolean, Error> => {
 
 
   return useSWRImmutable(
   return useSWRImmutable(
     ['isGuestUser', currentUser],
     ['isGuestUser', currentUser],
-    (key: Key, currentUser: IUser) => currentUser == null,
+    ([, currentUser]) => currentUser == null,
     { fallbackData: currentUser == null },
     { fallbackData: currentUser == null },
   );
   );
 };
 };
@@ -247,7 +247,7 @@ export const useIsEditable = (): SWRResponse<boolean, Error> => {
 
 
   return useSWRImmutable(
   return useSWRImmutable(
     ['isEditable', isGuestUser, isForbidden, isNotCreatable, isIdenticalPath],
     ['isEditable', isGuestUser, isForbidden, isNotCreatable, isIdenticalPath],
-    (key: Key, isGuestUser: boolean, isForbidden: boolean, isNotCreatable: boolean, isIdenticalPath: boolean) => {
+    ([, isGuestUser, isForbidden, isNotCreatable, isIdenticalPath]) => {
       return (!isForbidden && !isIdenticalPath && !isNotCreatable && !isGuestUser);
       return (!isForbidden && !isIdenticalPath && !isNotCreatable && !isGuestUser);
     },
     },
   );
   );

+ 2 - 2
packages/app/src/stores/editor.tsx

@@ -41,7 +41,7 @@ export const useEditorSettings = (): SWRResponseWithUtils<EditorSettingsOperatio
 
 
   const swrResult = useSWRImmutable<IEditorSettings>(
   const swrResult = useSWRImmutable<IEditorSettings>(
     isGuestUser ? null : ['/personal-setting/editor-settings', currentUser?.username],
     isGuestUser ? null : ['/personal-setting/editor-settings', currentUser?.username],
-    endpoint => apiv3Get(endpoint).then(result => result.data),
+    ([endpoint]) => apiv3Get(endpoint).then(result => result.data),
     {
     {
       // use: [localStorageMiddleware], // store to localStorage for initialization fastly
       // use: [localStorageMiddleware], // store to localStorage for initialization fastly
       // fallbackData: undefined,
       // fallbackData: undefined,
@@ -96,7 +96,7 @@ export const useSWRxSlackChannels = (currentPagePath: Nullable<string>): SWRResp
   const shouldFetch: boolean = currentPagePath != null;
   const shouldFetch: boolean = currentPagePath != null;
   return useSWRImmutable(
   return useSWRImmutable(
     shouldFetch ? ['/pages.updatePost', currentPagePath] : null,
     shouldFetch ? ['/pages.updatePost', currentPagePath] : null,
-    (endpoint, path) => apiGet(endpoint, { path }).then((response: SlackChannels) => response.updatePost),
+    ([endpoint, path]) => apiGet(endpoint, { path }).then((response: SlackChannels) => response.updatePost),
     { fallbackData: [''] },
     { fallbackData: [''] },
   );
   );
 };
 };

+ 2 - 2
packages/app/src/stores/in-app-notification.ts

@@ -19,7 +19,7 @@ export const useSWRxInAppNotifications = <Data, Error>(
 ): SWRResponse<PaginateResult<IInAppNotification>, Error> => {
 ): SWRResponse<PaginateResult<IInAppNotification>, Error> => {
   return useSWR(
   return useSWR(
     ['/in-app-notification/list', limit, offset, status],
     ['/in-app-notification/list', limit, offset, status],
-    endpoint => apiv3Get(endpoint, { limit, offset, status }).then((response) => {
+    ([endpoint]) => apiv3Get(endpoint, { limit, offset, status }).then((response) => {
       const inAppNotificationPaginateResult = response.data as inAppNotificationPaginateResult;
       const inAppNotificationPaginateResult = response.data as inAppNotificationPaginateResult;
       inAppNotificationPaginateResult.docs.forEach((doc) => {
       inAppNotificationPaginateResult.docs.forEach((doc) => {
         try {
         try {
@@ -39,7 +39,7 @@ export const useSWRxInAppNotifications = <Data, Error>(
 export const useSWRxInAppNotificationStatus = <Data, Error>(
 export const useSWRxInAppNotificationStatus = <Data, Error>(
 ): SWRResponse<number, Error> => {
 ): SWRResponse<number, Error> => {
   return useSWR(
   return useSWR(
-    ['/in-app-notification/status'],
+    '/in-app-notification/status',
     endpoint => apiv3Get(endpoint).then(response => response.data.count),
     endpoint => apiv3Get(endpoint).then(response => response.data.count),
   );
   );
 };
 };

+ 1 - 1
packages/app/src/stores/maintenanceMode.tsx

@@ -27,5 +27,5 @@ export const useIsMaintenanceMode = (initialData?: boolean): SWRResponseWithUtil
     },
     },
   };
   };
 
 
-  return withUtils(swrResult, utils);
+  return withUtils<maintenanceModeUtils, boolean>(swrResult, utils);
 };
 };

+ 8 - 8
packages/app/src/stores/page-listing.tsx

@@ -20,7 +20,7 @@ export const useSWRxPagesByPath = (path?: Nullable<string>): SWRResponse<IPageHa
   const findAll = true;
   const findAll = true;
   return useSWR<IPageHasId[], Error>(
   return useSWR<IPageHasId[], Error>(
     path != null ? ['/page', path, findAll] : null,
     path != null ? ['/page', path, findAll] : null,
-    (endpoint, path, findAll) => apiv3Get(endpoint, { path, findAll }).then(result => result.data.pages),
+    ([endpoint, path, findAll]) => apiv3Get(endpoint, { path, findAll }).then(result => result.data.pages),
   );
   );
 };
 };
 
 
@@ -31,12 +31,12 @@ export const useSWRxRecentlyUpdated = (): SWRResponse<(IPageHasId)[], Error> =>
   );
   );
 };
 };
 export const useSWRInifinitexRecentlyUpdated = () : SWRInfiniteResponse<(IPageHasId)[], Error> => {
 export const useSWRInifinitexRecentlyUpdated = () : SWRInfiniteResponse<(IPageHasId)[], Error> => {
-  const getKey = (page: number) => {
+  const getKey = (page: number): string => {
     return `/pages/recent?offset=${page + 1}`;
     return `/pages/recent?offset=${page + 1}`;
   };
   };
   return useSWRInfinite(
   return useSWRInfinite(
     getKey,
     getKey,
-    (endpoint: string) => apiv3Get<{ pages:(IPageHasId)[] }>(endpoint).then(response => response.data?.pages),
+    endpoint => apiv3Get<{ pages:(IPageHasId)[] }>(endpoint).then(response => response.data?.pages),
     {
     {
       revalidateFirstPage: false,
       revalidateFirstPage: false,
       revalidateAll: false,
       revalidateAll: false,
@@ -48,7 +48,7 @@ export const useSWRxPageList = (
     path: string | null, pageNumber?: number, termNumber?: number, limit?: number,
     path: string | null, pageNumber?: number, termNumber?: number, limit?: number,
 ): SWRResponse<IPagingResult<IPageHasId>, Error> => {
 ): SWRResponse<IPagingResult<IPageHasId>, Error> => {
 
 
-  let key;
+  let key: [string, number|undefined] | null;
   // if path not exist then the key is null
   // if path not exist then the key is null
   if (path == null) {
   if (path == null) {
     key = null;
     key = null;
@@ -62,7 +62,7 @@ export const useSWRxPageList = (
 
 
   return useSWR(
   return useSWR(
     key,
     key,
-    (endpoint: string) => apiv3Get<{pages: IPageHasId[], totalCount: number, limit: number}>(endpoint).then((response) => {
+    ([endpoint]) => apiv3Get<{pages: IPageHasId[], totalCount: number, limit: number}>(endpoint).then((response) => {
       return {
       return {
         items: response.data.pages,
         items: response.data.pages,
         totalCount: response.data.totalCount,
         totalCount: response.data.totalCount,
@@ -107,7 +107,7 @@ export const useSWRxPageInfoForList = (
 
 
   const swrResult = useSWRImmutable<Record<string, IPageInfoForListing>>(
   const swrResult = useSWRImmutable<Record<string, IPageInfoForListing>>(
     shouldFetch ? ['/page-listing/info', pageIds, path, attachBookmarkCount, attachShortBody] : null,
     shouldFetch ? ['/page-listing/info', pageIds, path, attachBookmarkCount, attachShortBody] : null,
-    (endpoint, pageIds, path, attachBookmarkCount, attachShortBody) => {
+    ([endpoint, pageIds, path, attachBookmarkCount, attachShortBody]) => {
       return apiv3Get(endpoint, {
       return apiv3Get(endpoint, {
         pageIds, path, attachBookmarkCount, attachShortBody,
         pageIds, path, attachBookmarkCount, attachShortBody,
       }).then(response => response.data);
       }).then(response => response.data);
@@ -159,7 +159,7 @@ export const useSWRxPageAncestorsChildren = (
 
 
   return useSWRImmutable(
   return useSWRImmutable(
     path ? [`/page-listing/ancestors-children?path=${path}`, termNumber] : null,
     path ? [`/page-listing/ancestors-children?path=${path}`, termNumber] : null,
-    endpoint => apiv3Get(endpoint).then((response) => {
+    ([endpoint]) => apiv3Get(endpoint).then((response) => {
       return {
       return {
         ancestorsChildren: response.data.ancestorsChildren,
         ancestorsChildren: response.data.ancestorsChildren,
       };
       };
@@ -177,7 +177,7 @@ export const useSWRxPageChildren = (
 
 
   return useSWR(
   return useSWR(
     id ? [`/page-listing/children?id=${id}`, termNumber] : null,
     id ? [`/page-listing/children?id=${id}`, termNumber] : null,
-    endpoint => apiv3Get(endpoint).then((response) => {
+    ([endpoint]) => apiv3Get(endpoint).then((response) => {
       return {
       return {
         children: response.data.children,
         children: response.data.children,
       };
       };

+ 8 - 1
yarn.lock

@@ -21803,6 +21803,13 @@ swr@^1.3.0:
   resolved "https://registry.yarnpkg.com/swr/-/swr-1.3.0.tgz#c6531866a35b4db37b38b72c45a63171faf9f4e8"
   resolved "https://registry.yarnpkg.com/swr/-/swr-1.3.0.tgz#c6531866a35b4db37b38b72c45a63171faf9f4e8"
   integrity sha512-dkghQrOl2ORX9HYrMDtPa7LTVHJjCTeZoB1dqTbnnEDlSvN8JEKpYIYurDfvbQFUUS8Cg8PceFVZNkW0KNNYPw==
   integrity sha512-dkghQrOl2ORX9HYrMDtPa7LTVHJjCTeZoB1dqTbnnEDlSvN8JEKpYIYurDfvbQFUUS8Cg8PceFVZNkW0KNNYPw==
 
 
+swr@^2.0.2:
+  version "2.0.2"
+  resolved "https://registry.yarnpkg.com/swr/-/swr-2.0.2.tgz#fd34f3aac354f6b70f9134eb4218c747cc899a8d"
+  integrity sha512-iHbQW17hsduonMEliZnr6/yaxb+yvLe2r0+AH+ZfeqKzwc2bb+QRYpZm5/b/H0Lxgy7VWow4o71JeSazSun+9A==
+  dependencies:
+    use-sync-external-store "^1.2.0"
+
 synckit@^0.7.2:
 synckit@^0.7.2:
   version "0.7.2"
   version "0.7.2"
   resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.7.2.tgz#43c07b5a8101ee45355aebf0216895309fd32a6f"
   resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.7.2.tgz#43c07b5a8101ee45355aebf0216895309fd32a6f"
@@ -23432,7 +23439,7 @@ url@0.10.3:
     punycode "1.3.2"
     punycode "1.3.2"
     querystring "0.2.0"
     querystring "0.2.0"
 
 
-use-sync-external-store@1.2.0:
+use-sync-external-store@1.2.0, use-sync-external-store@^1.2.0:
   version "1.2.0"
   version "1.2.0"
   resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
   resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
   integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==
   integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==