Sfoglia il codice sorgente

Display an error message when the synctex request fails (#27523)

GitOrigin-RevId: 4a57058386ba8b11dee90ef13e374411db54e2cc
Alf Eaton 1 anno fa
parent
commit
94c8fe5b93

+ 1 - 0
services/web/frontend/extracted-translations.json

@@ -1747,6 +1747,7 @@
   "sync_project_to_github_explanation": "",
   "sync_to_dropbox": "",
   "sync_to_github": "",
+  "synctex_error_recompile_and_try_again": "",
   "synctex_failed": "",
   "syntax_validation": "",
   "tab_connecting": "",

+ 26 - 0
services/web/frontend/js/features/pdf-preview/components/synctex-toasts.tsx

@@ -21,6 +21,12 @@ export const SynctexFileErrorToast = () => {
   )
 }
 
+export const SynctexRequestErrorToast = () => {
+  const { t } = useTranslation()
+
+  return <span>{t('synctex_error_recompile_and_try_again')}</span>
+}
+
 const generators: GlobalToastGeneratorEntry[] = [
   {
     key: 'synctex:file-error',
@@ -32,6 +38,16 @@ const generators: GlobalToastGeneratorEntry[] = [
       isDismissible: true,
     }),
   },
+  {
+    key: 'synctex:request-error',
+    generator: () => ({
+      content: <SynctexRequestErrorToast />,
+      type: 'warning',
+      autoHide: true,
+      delay: 4000,
+      isDismissible: true,
+    }),
+  },
 ]
 
 export default generators
@@ -45,3 +61,13 @@ export const showFileErrorToast = () => {
     })
   )
 }
+
+export const showSynctexRequestErrorToast = () => {
+  window.dispatchEvent(
+    new CustomEvent('ide:show-toast', {
+      detail: {
+        key: 'synctex:request-error',
+      },
+    })
+  )
+}

+ 12 - 3
services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts

@@ -17,7 +17,10 @@ import useEventListener from '@/shared/hooks/use-event-listener'
 import { CursorPosition } from '@/features/ide-react/types/cursor-position'
 import { isValidTeXFile } from '@/main/is-valid-tex-file'
 import { PdfScrollPosition } from '@/shared/hooks/use-pdf-scroll-position'
-import { showFileErrorToast } from '@/features/pdf-preview/components/synctex-toasts'
+import {
+  showFileErrorToast,
+  showSynctexRequestErrorToast,
+} from '@/features/pdf-preview/components/synctex-toasts'
 import { sendMB } from '@/infrastructure/event-tracking'
 
 export default function useSynctex(): {
@@ -125,7 +128,10 @@ export default function useSynctex(): {
             })
           }
         })
-        .catch(debugConsole.error)
+        .catch(error => {
+          showSynctexRequestErrorToast()
+          debugConsole.error(error)
+        })
         .finally(() => {
           if (isMounted.current) {
             setSyncToPdfInFlight(false)
@@ -236,7 +242,10 @@ export default function useSynctex(): {
             })
           }
         })
-        .catch(debugConsole.error)
+        .catch(error => {
+          debugConsole.error(error)
+          showSynctexRequestErrorToast()
+        })
         .finally(() => {
           if (isMounted.current) {
             setSyncToCodeInFlight(false)

+ 1 - 0
services/web/locales/en.json

@@ -2246,6 +2246,7 @@
   "sync_project_to_github_explanation": "Any changes you have made in __appName__ will be committed and merged with any updates in GitHub.",
   "sync_to_dropbox": "Sync to Dropbox",
   "sync_to_github": "Sync to GitHub",
+  "synctex_error_recompile_and_try_again": "That didn’t work. Recompile and try again.",
   "synctex_failed": "Couldn’t find the corresponding source file",
   "syntax_validation": "Code check",
   "tab_connecting": "Connecting with the editor",