Browse Source

Merge pull request #22168 from overleaf/mj-rm-events

[web] Add events when refreshing linked file and importing RM entry

GitOrigin-RevId: b9efcd1893f0a78a33ec325b306eccbaa44a77fe
Mathias Jakobsen 1 năm trước cách đây
mục cha
commit
0bec88cb2b

+ 14 - 7
services/web/frontend/js/features/file-view/components/file-view-refresh-button.tsx

@@ -9,11 +9,12 @@ import { useTranslation } from 'react-i18next'
 import Icon from '@/shared/components/icon'
 import Icon from '@/shared/components/icon'
 import { postJSON } from '@/infrastructure/fetch-json'
 import { postJSON } from '@/infrastructure/fetch-json'
 import { useProjectContext } from '@/shared/context/project-context'
 import { useProjectContext } from '@/shared/context/project-context'
-import useAbortController from '@/shared/hooks/use-abort-controller'
 import type { BinaryFile } from '../types/binary-file'
 import type { BinaryFile } from '../types/binary-file'
 import { Nullable } from '../../../../../types/utils'
 import { Nullable } from '../../../../../types/utils'
 import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
 import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
 import OLButton from '@/features/ui/components/ol/ol-button'
 import OLButton from '@/features/ui/components/ol/ol-button'
+import { sendMB } from '@/infrastructure/event-tracking'
+import useIsMounted from '@/shared/hooks/use-is-mounted'
 
 
 type FileViewRefreshButtonProps = {
 type FileViewRefreshButtonProps = {
   setRefreshError: Dispatch<SetStateAction<Nullable<string>>>
   setRefreshError: Dispatch<SetStateAction<Nullable<string>>>
@@ -32,8 +33,8 @@ export default function FileViewRefreshButton({
   file,
   file,
 }: FileViewRefreshButtonProps) {
 }: FileViewRefreshButtonProps) {
   const { _id: projectId } = useProjectContext()
   const { _id: projectId } = useProjectContext()
-  const { signal } = useAbortController()
   const [refreshing, setRefreshing] = useState(false)
   const [refreshing, setRefreshing] = useState(false)
+  const isMountedRef = useIsMounted()
 
 
   const refreshFile = useCallback(
   const refreshFile = useCallback(
     (isTPR: Nullable<boolean>) => {
     (isTPR: Nullable<boolean>) => {
@@ -44,18 +45,24 @@ export default function FileViewRefreshButton({
         shouldReindexReferences: isTPR || /\.bib$/.test(file.name),
         shouldReindexReferences: isTPR || /\.bib$/.test(file.name),
       }
       }
       postJSON(`/project/${projectId}/linked_file/${file.id}/refresh`, {
       postJSON(`/project/${projectId}/linked_file/${file.id}/refresh`, {
-        signal,
         body,
         body,
       })
       })
         .then(() => {
         .then(() => {
-          setRefreshing(false)
+          if (isMountedRef.current) {
+            setRefreshing(false)
+          }
+          sendMB('refresh-linked-file', {
+            provider: file.linkedFileData?.provider,
+          })
         })
         })
         .catch(err => {
         .catch(err => {
-          setRefreshing(false)
-          setRefreshError(err.data?.message || err.message)
+          if (isMountedRef.current) {
+            setRefreshing(false)
+            setRefreshError(err.data?.message || err.message)
+          }
         })
         })
     },
     },
-    [file, projectId, signal, setRefreshError]
+    [file, projectId, setRefreshError, isMountedRef]
   )
   )
 
 
   if (tprFileViewRefreshButton.length > 0) {
   if (tprFileViewRefreshButton.length > 0) {