Просмотр исходного кода

Merge pull request #8932 from weseek/feat/149418-implement-an-api-client-to-request-sync-latest-revision-body-to-yjs-draft

feat: Implement an api client to request sync latest revision body to yjs draft
Shun Miyazawa 1 год назад
Родитель
Сommit
865ec7e8c0

+ 3 - 1
apps/app/public/static/locales/en_US/translation.json

@@ -880,6 +880,8 @@
     "untitled": "Untitled"
   },
   "sync-latest-reevision-body": {
-    "confirm": "Delete the draft data being entered into the editor and synchronize the latest text. Are you sure you want to run it?"
+    "confirm": "Delete the draft data being entered into the editor and synchronize the latest text. Are you sure you want to run it?",
+    "success-toaster": "Latest text synchronized",
+    "error-toaster": "Synchronization of the latest text failed"
   }
 }

+ 3 - 1
apps/app/public/static/locales/fr_FR/translation.json

@@ -871,6 +871,8 @@
     "size_l": "Taille: G"
   },
   "sync-latest-reevision-body": {
-    "confirm": "Delete the draft data being entered into the editor and synchronize the latest text. Are you sure you want to run it?"
+    "confirm": "Delete the draft data being entered into the editor and synchronize the latest text. Are you sure you want to run it?",
+    "success-toaster": "Dernier texte synchronisé",
+    "error-toaster": "La synchronisation du dernier texte a échoué"
   }
 }

+ 3 - 1
apps/app/public/static/locales/ja_JP/translation.json

@@ -913,6 +913,8 @@
     "untitled": "無題のページ"
   },
   "sync-latest-reevision-body": {
-    "confirm": "エディターに入力中のドラフトデータを削除して最新の本文を同期します。実行しますか?"
+    "confirm": "エディターに入力中のドラフトデータを削除して最新の本文を同期します。実行しますか?",
+    "success-toaster": "最新の本文を同期しました",
+    "error-toaster": "最新の本文の同期に失敗しました"
   }
 }

+ 3 - 1
apps/app/public/static/locales/zh_CN/translation.json

@@ -883,6 +883,8 @@
     "untitled": "Untitled"
   },
   "sync-latest-reevision-body": {
-    "confirm": "删除输入编辑器的草稿数据,同步最新文本。 您真的想运行它吗?"
+    "confirm": "删除输入编辑器的草稿数据,同步最新文本。 您真的想运行它吗?",
+    "success-toaster": "同步最新文本",
+    "error-toaster": "同步最新文本失败"
   }
 }

+ 10 - 3
apps/app/src/client/components/Navbar/GrowiContextualSubNavigation.tsx

@@ -14,7 +14,8 @@ import { useRouter } from 'next/router';
 import Sticky from 'react-stickynode';
 import { DropdownItem } from 'reactstrap';
 
-import { exportAsMarkdown, updateContentWidth } from '~/client/services/page-operation';
+import { exportAsMarkdown, updateContentWidth, syncLatestRevisionBody } from '~/client/services/page-operation';
+import { toastSuccess, toastError } from '~/client/util/toastr';
 import { GroundGlassBar } from '~/components/Navbar/GroundGlassBar';
 import type { OnDuplicatedFunction, OnRenamedFunction, OnDeletedFunction } from '~/interfaces/ui';
 import { useShouldExpandContent } from '~/services/layout/use-should-expand-content';
@@ -80,9 +81,15 @@ const PageOperationMenuItems = (props: PageOperationMenuItemsProps): JSX.Element
     // eslint-disable-next-line no-alert
     const answer = window.confirm(t('sync-latest-reevision-body.confirm'));
     if (answer) {
-      // TODO: https://redmine.weseek.co.jp/issues/149418
+      try {
+        await syncLatestRevisionBody(pageId);
+        toastSuccess(t('sync-latest-reevision-body.success-toaster'));
+      }
+      catch {
+        toastError(t('sync-latest-reevision-body.error-toaster'));
+      }
     }
-  }, [t]);
+  }, [pageId, t]);
 
   return (
     <>

+ 5 - 0
apps/app/src/client/services/page-operation.ts

@@ -174,3 +174,8 @@ export const unpublish = async(pageId: string): Promise<IPageHasId> => {
   const res = await apiv3Put(`/page/${pageId}/unpublish`);
   return res.data;
 };
+
+export const syncLatestRevisionBody = async(pageId: string): Promise<void> => {
+  await apiv3Put(`/page/${pageId}/sync-latest-revision-body-to-yjs-draft`);
+  return;
+};