Skip to content

Commit

Permalink
Admin/Subsection: disable button while API fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannaPeanut committed Nov 1, 2023
1 parent faefd95 commit 0f92657
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pages/admin/[projectSlug]/subsections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const AdminSubsectionsWithQuery = () => {
// Docs: https://blitzjs.com/docs/route-params-query#use-router-query
const params = useRouterQuery()
const [error, setError]: any | null = useState(null)
const [isFetching, setIsFetching] = useState(false)
const [updatedIds, setUpdatedIds] = useState<number[]>([])
const filteredSubsections = params.operator
? subsections.filter(
Expand All @@ -49,6 +50,7 @@ export const AdminSubsectionsWithQuery = () => {
}

const handleFeltDataClick = async () => {
setIsFetching(true)
if (!project.felt_subsection_geometry_source_url) {
window.alert("Keine Felt URL")
return console.error("No Felt URL")
Expand All @@ -62,6 +64,7 @@ export const AdminSubsectionsWithQuery = () => {
if (subsectionIds) setUpdatedIds(subsectionIds)
await refetch()
window.scrollTo(0, 0)
setIsFetching(false)
} catch (error: any) {
setError(error)
return console.error(error)
Expand Down Expand Up @@ -105,7 +108,11 @@ export const AdminSubsectionsWithQuery = () => {
</Link>
{project.felt_subsection_geometry_source_url ? (
<>
<button className={blueButtonStyles} onClick={handleFeltDataClick}>
<button
disabled={isFetching}
className={blueButtonStyles}
onClick={handleFeltDataClick}
>
Daten von Felt übernehmen
</button>

Expand Down

0 comments on commit 0f92657

Please sign in to comment.