mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-09 18:26:15 +02:00
fix(Settings): standardize manifest fetching behavior
This commit is contained in:
parent
d7d3821c06
commit
c4514e8c3d
|
|
@ -6,7 +6,7 @@ import { useModals } from '~/context/ModalContext'
|
||||||
import StyledModal from '~/components/StyledModal'
|
import StyledModal from '~/components/StyledModal'
|
||||||
import { FileEntry } from '../../../types/files'
|
import { FileEntry } from '../../../types/files'
|
||||||
import { useNotifications } from '~/context/NotificationContext'
|
import { useNotifications } from '~/context/NotificationContext'
|
||||||
import { useEffect, useState } from 'react'
|
import { useState } from 'react'
|
||||||
import api from '~/lib/api'
|
import api from '~/lib/api'
|
||||||
import DownloadURLModal from '~/components/DownloadURLModal'
|
import DownloadURLModal from '~/components/DownloadURLModal'
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
|
@ -161,28 +161,17 @@ export default function MapsManager(props: {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchLatestCollections = useMutation({
|
const refreshManifests = useMutation({
|
||||||
mutationFn: () => api.fetchLatestMapCollections(),
|
mutationFn: () => api.refreshManifests(),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
addNotification({
|
addNotification({
|
||||||
message: 'Successfully fetched the latest map collections.',
|
message: 'Successfully refreshed map collections.',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
})
|
})
|
||||||
queryClient.invalidateQueries({ queryKey: [CURATED_COLLECTIONS_KEY] })
|
queryClient.invalidateQueries({ queryKey: [CURATED_COLLECTIONS_KEY] })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Auto-fetch latest collections if the list is empty
|
|
||||||
useEffect(() => {
|
|
||||||
if (
|
|
||||||
curatedCollections &&
|
|
||||||
curatedCollections.length === 0 &&
|
|
||||||
!fetchLatestCollections.isPending
|
|
||||||
) {
|
|
||||||
fetchLatestCollections.mutate()
|
|
||||||
}
|
|
||||||
}, [curatedCollections, fetchLatestCollections])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsLayout>
|
<SettingsLayout>
|
||||||
<Head title="Maps Manager" />
|
<Head title="Maps Manager" />
|
||||||
|
|
@ -215,11 +204,11 @@ export default function MapsManager(props: {
|
||||||
<div className="mt-8 mb-6 flex items-center justify-between">
|
<div className="mt-8 mb-6 flex items-center justify-between">
|
||||||
<StyledSectionHeader title="Curated Map Regions" className="!mb-0" />
|
<StyledSectionHeader title="Curated Map Regions" className="!mb-0" />
|
||||||
<StyledButton
|
<StyledButton
|
||||||
onClick={() => fetchLatestCollections.mutate()}
|
onClick={() => refreshManifests.mutate()}
|
||||||
disabled={fetchLatestCollections.isPending}
|
disabled={refreshManifests.isPending}
|
||||||
icon="IconRefresh"
|
icon="IconRefresh"
|
||||||
>
|
>
|
||||||
Get Latest Collections from GitHub
|
Force Refresh Collections
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
</div>
|
</div>
|
||||||
<div className="!mt-4 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
|
<div className="!mt-4 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,7 @@ export default function ZimRemoteExplorer() {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
})
|
})
|
||||||
queryClient.invalidateQueries({ queryKey: [CURATED_CATEGORIES_KEY] })
|
queryClient.invalidateQueries({ queryKey: [CURATED_CATEGORIES_KEY] })
|
||||||
|
queryClient.invalidateQueries({ queryKey: [WIKIPEDIA_STATE_KEY] })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -296,7 +297,16 @@ export default function ZimRemoteExplorer() {
|
||||||
className="!mt-6"
|
className="!mt-6"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<StyledSectionHeader title="Curated Content" className="mt-8 !mb-4" />
|
<div className="mt-8 mb-6 flex items-center justify-between">
|
||||||
|
<StyledSectionHeader title="Curated Content" className="!mb-0" />
|
||||||
|
<StyledButton
|
||||||
|
onClick={() => refreshManifests.mutate()}
|
||||||
|
disabled={refreshManifests.isPending || !isOnline}
|
||||||
|
icon="IconRefresh"
|
||||||
|
>
|
||||||
|
Force Refresh Collections
|
||||||
|
</StyledButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Wikipedia Selector */}
|
{/* Wikipedia Selector */}
|
||||||
{isLoadingWikipedia ? (
|
{isLoadingWikipedia ? (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user