mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { useTranslation } from 'react-i18next'
|
|
import OLButton from '@/shared/components/ol/ol-button'
|
|
import type { BinaryFile } from '@/features/file-view/types/binary-file'
|
|
import getMeta from '@/utils/meta'
|
|
|
|
type TPRFileViewRefreshButtonProps = {
|
|
file: BinaryFile
|
|
refreshFile: (isTPR: boolean | null) => void
|
|
refreshing: boolean
|
|
}
|
|
|
|
/**
|
|
* Zotero-specific refresh button for the file view.
|
|
* Tells the system this is a TPR file so references are re-indexed.
|
|
* Registered via overleafModuleImports.tprFileViewRefreshButton.
|
|
*/
|
|
export function TPRFileViewRefreshButton({
|
|
file,
|
|
refreshFile,
|
|
refreshing,
|
|
}: TPRFileViewRefreshButtonProps) {
|
|
const { t } = useTranslation()
|
|
const provider = (file.linkedFileData as Record<string, unknown>)?.provider
|
|
const currentUserId =
|
|
(getMeta('ol-user') as any)?._id || (getMeta('ol-user_id') as string)
|
|
const importedByUserId = (file.linkedFileData as any)?.importedByUserId
|
|
const isOriginalImporter =
|
|
provider === 'zotero' &&
|
|
currentUserId &&
|
|
importedByUserId === currentUserId
|
|
|
|
if (provider !== 'zotero' || isOriginalImporter) {
|
|
// Zotero or default refresh for originator only
|
|
return (
|
|
<OLButton
|
|
variant="primary"
|
|
onClick={() => refreshFile(provider === 'zotero' ? true : null)}
|
|
disabled={refreshing}
|
|
isLoading={refreshing}
|
|
loadingLabel={t('refreshing')}
|
|
>
|
|
{t('refresh')}
|
|
</OLButton>
|
|
)
|
|
}
|
|
|
|
// collaborator of Zotero file should not refresh
|
|
return (
|
|
<OLButton
|
|
variant="primary"
|
|
disabled
|
|
>
|
|
{t('refresh')}
|
|
</OLButton>
|
|
)
|
|
}
|