mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
- use OAuth instead of tokens - add an integration card - improve error handling - add BibLaTeX format support - fix indexing of linked .bib files on creation
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { useState } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import useAsync from '@/shared/hooks/use-async'
|
|
import { getJSON } from '@/infrastructure/fetch-json'
|
|
import { debugConsole } from '@/utils/debugging'
|
|
import ZoteroLogo from '@/shared/svgs/zotero-logo'
|
|
import IntegrationCard from '@/features/integrations-panel/integration-card'
|
|
import ZoteroLinkInfoModal from './zotero-link-info-modal'
|
|
|
|
const ZoteroLinkCard = () => {
|
|
const { t } = useTranslation()
|
|
|
|
const [showModal, setShowModal] = useState(false)
|
|
|
|
const {
|
|
isError,
|
|
runAsync,
|
|
data: isConnected
|
|
} = useAsync<boolean>()
|
|
|
|
const handleClick = () => {
|
|
runAsync(getJSON('/user/zotero/status'))
|
|
.then(isConnected => {
|
|
if (isConnected) {
|
|
setShowModal(true)
|
|
} else {
|
|
window.open(
|
|
'/user/zotero/oauth?popup=1',
|
|
'_blank',
|
|
'width=600,height=700'
|
|
)
|
|
}
|
|
})
|
|
.catch(err => {
|
|
debugConsole.error(
|
|
err?.data?.message || err?.message || err
|
|
)
|
|
setShowModal(true)
|
|
})
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<IntegrationCard
|
|
title={t('zotero')}
|
|
description={t('cite_directly_or_import_references')}
|
|
icon={<ZoteroLogo size={32} />}
|
|
showPaywallBadge={false}
|
|
onClick={handleClick}
|
|
/>
|
|
|
|
<ZoteroLinkInfoModal
|
|
show={showModal}
|
|
handleHide={() => setShowModal(false)}
|
|
isError={isError}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default ZoteroLinkCard
|