mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Fix a greyed out create file button after the Zotero Integration was merged.
This commit is contained in:
@@ -35,10 +35,19 @@ export function CreateFileMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function CreateFilePane() {
|
export function CreateFilePane() {
|
||||||
|
const { newFileCreateMode } = useFileTreeActionable()
|
||||||
|
|
||||||
|
if (newFileCreateMode !== 'zotero') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return <ZoteroCreateFilePane />
|
||||||
|
}
|
||||||
|
|
||||||
|
function ZoteroCreateFilePane() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { setValid } = useFileTreeCreateForm()
|
const { setValid } = useFileTreeCreateForm()
|
||||||
const { newFileCreateMode, finishCreatingLinkedFile, error, inFlight } =
|
const { finishCreatingLinkedFile, error, inFlight } = useFileTreeActionable()
|
||||||
useFileTreeActionable()
|
|
||||||
|
|
||||||
const [groups, setGroups] = useState<ZoteroGroup[]>([])
|
const [groups, setGroups] = useState<ZoteroGroup[]>([])
|
||||||
const [selectedGroupId, setSelectedGroupId] = useState<string>('')
|
const [selectedGroupId, setSelectedGroupId] = useState<string>('')
|
||||||
@@ -46,33 +55,45 @@ export function CreateFilePane() {
|
|||||||
const [loadingGroups, setLoadingGroups] = useState(true)
|
const [loadingGroups, setLoadingGroups] = useState(true)
|
||||||
const [groupsError, setGroupsError] = useState('')
|
const [groupsError, setGroupsError] = useState('')
|
||||||
|
|
||||||
// form validation
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValid(!!name && !loadingGroups)
|
setValid(!!name && !loadingGroups)
|
||||||
}, [setValid, name, loadingGroups])
|
}, [setValid, name, loadingGroups])
|
||||||
|
|
||||||
// load groups when the mode is active
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (newFileCreateMode !== 'zotero') return
|
let cancelled = false
|
||||||
|
|
||||||
setLoadingGroups(true)
|
setLoadingGroups(true)
|
||||||
setGroupsError('')
|
setGroupsError('')
|
||||||
|
|
||||||
getJSON('/zotero/groups')
|
getJSON('/zotero/groups')
|
||||||
.then((data: { groups: ZoteroGroup[] }) => {
|
.then((data: { groups: ZoteroGroup[] }) => {
|
||||||
|
if (cancelled) return
|
||||||
|
|
||||||
setGroups(data.groups || [])
|
setGroups(data.groups || [])
|
||||||
setLoadingGroups(false)
|
setLoadingGroups(false)
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
if (cancelled) return
|
||||||
|
|
||||||
setGroupsError(t('zotero_groups_loading_error'))
|
setGroupsError(t('zotero_groups_loading_error'))
|
||||||
setLoadingGroups(false)
|
setLoadingGroups(false)
|
||||||
})
|
})
|
||||||
}, [newFileCreateMode, t])
|
|
||||||
|
return () => {
|
||||||
|
cancelled = true
|
||||||
|
}
|
||||||
|
}, [t])
|
||||||
|
|
||||||
const handleSubmit: FormEventHandler = useCallback(
|
const handleSubmit: FormEventHandler = useCallback(
|
||||||
event => {
|
event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
|
if (!name || loadingGroups || inFlight) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const data: Record<string, string> = {}
|
const data: Record<string, string> = {}
|
||||||
|
|
||||||
if (selectedGroupId) {
|
if (selectedGroupId) {
|
||||||
data.zoteroGroupId = selectedGroupId
|
data.zoteroGroupId = selectedGroupId
|
||||||
}
|
}
|
||||||
@@ -83,13 +104,15 @@ export function CreateFilePane() {
|
|||||||
data,
|
data,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[name, selectedGroupId, finishCreatingLinkedFile]
|
[
|
||||||
|
name,
|
||||||
|
loadingGroups,
|
||||||
|
inFlight,
|
||||||
|
selectedGroupId,
|
||||||
|
finishCreatingLinkedFile,
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
if (newFileCreateMode !== 'zotero') {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
className="form-controls"
|
className="form-controls"
|
||||||
|
|||||||
Reference in New Issue
Block a user