|
@@ -1,13 +1,13 @@
|
|
|
import { useCallback } from 'react';
|
|
import { useCallback } from 'react';
|
|
|
|
|
|
|
|
import { Nullable, withUtils, type SWRResponseWithUtils } from '@growi/core';
|
|
import { Nullable, withUtils, type SWRResponseWithUtils } from '@growi/core';
|
|
|
-import { SWRResponse } from 'swr';
|
|
|
|
|
|
|
+import useSWR, { type SWRResponse } from 'swr';
|
|
|
import useSWRImmutable from 'swr/immutable';
|
|
import useSWRImmutable from 'swr/immutable';
|
|
|
|
|
|
|
|
import { apiGet } from '~/client/util/apiv1-client';
|
|
import { apiGet } from '~/client/util/apiv1-client';
|
|
|
import { apiv3Get, apiv3Put } from '~/client/util/apiv3-client';
|
|
import { apiv3Get, apiv3Put } from '~/client/util/apiv3-client';
|
|
|
-import { IEditorSettings } from '~/interfaces/editor-settings';
|
|
|
|
|
-import { SlackChannels } from '~/interfaces/user-trigger-notification';
|
|
|
|
|
|
|
+import type { IEditorSettings } from '~/interfaces/editor-settings';
|
|
|
|
|
+import type { SlackChannels } from '~/interfaces/user-trigger-notification';
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
|
useCurrentUser, useDefaultIndentSize, useIsGuestUser, useIsReadOnlyUser,
|
|
useCurrentUser, useDefaultIndentSize, useIsGuestUser, useIsReadOnlyUser,
|
|
@@ -41,7 +41,9 @@ export const useEditorSettings = (): SWRResponseWithUtils<EditorSettingsOperatio
|
|
|
|
|
|
|
|
const swrResult = useSWRImmutable(
|
|
const swrResult = useSWRImmutable(
|
|
|
(isGuestUser || isReadOnlyUser) ? null : ['/personal-setting/editor-settings', currentUser?.username],
|
|
(isGuestUser || isReadOnlyUser) ? null : ['/personal-setting/editor-settings', currentUser?.username],
|
|
|
- ([endpoint]) => apiv3Get(endpoint).then(result => result.data),
|
|
|
|
|
|
|
+ ([endpoint]) => {
|
|
|
|
|
+ return 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,
|
|
@@ -78,10 +80,13 @@ export const useCurrentIndentSize = (): SWRResponse<number, Error> => {
|
|
|
*/
|
|
*/
|
|
|
export const useSWRxSlackChannels = (currentPagePath: Nullable<string>): SWRResponse<string[], Error> => {
|
|
export const useSWRxSlackChannels = (currentPagePath: Nullable<string>): SWRResponse<string[], Error> => {
|
|
|
const shouldFetch: boolean = currentPagePath != null;
|
|
const shouldFetch: boolean = currentPagePath != null;
|
|
|
- return useSWRImmutable(
|
|
|
|
|
|
|
+ return useSWR(
|
|
|
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: [''] },
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ revalidateOnFocus: false,
|
|
|
|
|
+ fallbackData: [''],
|
|
|
|
|
+ },
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|