Skip to content

Commit

Permalink
Merge pull request #9011 from weseek/fix/autofocus-to-page-header
Browse files Browse the repository at this point in the history
fix: Wrongly autofocus to PageHeader even after updating
  • Loading branch information
yuki-takei authored Aug 1, 2024
2 parents 2e3166a + 69ca55b commit 64e0fec
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
3 changes: 2 additions & 1 deletion apps/app/src/client/components/PageEditor/PageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useTranslation } from 'next-i18next';
import { throttle, debounce } from 'throttle-debounce';

import { useUpdateStateAfterSave } from '~/client/services/page-operation';
import { updatePage, extractRemoteRevisionDataFromErrorObj } from '~/client/services/update-page';
import { useUpdatePage, extractRemoteRevisionDataFromErrorObj } from '~/client/services/update-page';
import { uploadAttachments } from '~/client/services/upload-attachments';
import { toastError, toastSuccess, toastWarning } from '~/client/util/toastr';
import { useShouldExpandContent } from '~/services/layout/use-should-expand-content';
Expand Down Expand Up @@ -118,6 +118,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {

const shouldExpandContent = useShouldExpandContent(currentPage);

const updatePage = useUpdatePage();
const updateStateAfterSave = useUpdateStateAfterSave(pageId, { supressEditingMarkdownMutation: true });

useConflictEffect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Origin } from '@growi/core';
import type { DrawioEditByViewerProps } from '@growi/remark-drawio';

import { replaceDrawioInMarkdown } from '~/client/components/Page/markdown-drawio-util-for-view';
import { extractRemoteRevisionDataFromErrorObj, updatePage as _updatePage } from '~/client/services/update-page';
import { extractRemoteRevisionDataFromErrorObj, useUpdatePage } from '~/client/services/update-page';
import { useShareLinkId } from '~/stores-universal/context';
import { useConflictDiffModal, useDrawioModal } from '~/stores/modal';
import { useSWRxCurrentPage } from '~/stores/page';
Expand Down Expand Up @@ -36,6 +36,8 @@ export const useDrawioModalLauncherForView = (opts?: {

const { open: openConflictDiffModal, close: closeConflictDiffModal } = useConflictDiffModal();

const _updatePage = useUpdatePage();

const { setRemoteLatestPageData } = useSetRemoteLatestPageData();

// eslint-disable-next-line max-len
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Origin } from '@growi/core';
import type { MarkdownTable } from '@growi/editor';

import { getMarkdownTableFromLine, replaceMarkdownTableInMarkdown } from '~/client/components/Page/markdown-table-util-for-view';
import { extractRemoteRevisionDataFromErrorObj, updatePage as _updatePage } from '~/client/services/update-page';
import { extractRemoteRevisionDataFromErrorObj, useUpdatePage } from '~/client/services/update-page';
import { useShareLinkId } from '~/stores-universal/context';
import { useHandsontableModal, useConflictDiffModal } from '~/stores/modal';
import { useSWRxCurrentPage } from '~/stores/page';
Expand Down Expand Up @@ -36,6 +36,8 @@ export const useHandsontableModalLauncherForView = (opts?: {

const { open: openConflictDiffModal, close: closeConflictDiffModal } = useConflictDiffModal();

const _updatePage = useUpdatePage();

const { setRemoteLatestPageData } = useSetRemoteLatestPageData();

// eslint-disable-next-line max-len
Expand Down
9 changes: 1 addition & 8 deletions apps/app/src/client/services/update-page/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
import { apiv3Put } from '~/client/util/apiv3-client';
import type { IApiv3PageUpdateParams, IApiv3PageUpdateResponse } from '~/interfaces/apiv3';

export * from './conflict';

export const updatePage = async(params: IApiv3PageUpdateParams): Promise<IApiv3PageUpdateResponse> => {
const res = await apiv3Put<IApiv3PageUpdateResponse>('/page', params);
return res.data;
};
export * from './use-update-page';
7 changes: 7 additions & 0 deletions apps/app/src/client/services/update-page/update-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { apiv3Put } from '~/client/util/apiv3-client';
import type { IApiv3PageUpdateParams, IApiv3PageUpdateResponse } from '~/interfaces/apiv3';

export const updatePage = async(params: IApiv3PageUpdateParams): Promise<IApiv3PageUpdateResponse> => {
const res = await apiv3Put<IApiv3PageUpdateResponse>('/page', params);
return res.data;
};
25 changes: 25 additions & 0 deletions apps/app/src/client/services/update-page/use-update-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useCallback } from 'react';

import type { IApiv3PageUpdateParams, IApiv3PageUpdateResponse } from '~/interfaces/apiv3';
import { useIsUntitledPage } from '~/stores/ui';

import { updatePage } from './update-page';


type UseUpdatePage = (params: IApiv3PageUpdateParams) => Promise<IApiv3PageUpdateResponse>;


export const useUpdatePage = (): UseUpdatePage => {
const { mutate: mutateUntitledPage } = useIsUntitledPage();

const updatePageExt: UseUpdatePage = useCallback(async(params) => {
const result = await updatePage(params);

// set false to isUntitledPage
mutateUntitledPage(false);

return result;
}, [mutateUntitledPage]);

return updatePageExt;
};

0 comments on commit 64e0fec

Please sign in to comment.