Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Added spinner and disabled export button while the export is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
iskaktoltay committed Oct 9, 2024
1 parent 821055c commit 6c01b69
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions frontend/packages/app/pages/export-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Checkbox,
Container,
SizableText,
Spinner,
XStack,
YStack,
toast,
Expand All @@ -25,6 +26,7 @@ import {useNavRoute} from '../utils/navigation'
export default function ExportPage() {
const [documents, setDocuments] = useState<HMPublication[]>([])
const [allSelected, setAllSelected] = useState(false)
const [loading, setLoading] = useState(false)
const {exportDocuments} = useAppContext()

const route = useNavRoute()
Expand Down Expand Up @@ -129,6 +131,7 @@ export default function ExportPage() {
}

const submitExportDocuments = async () => {
setLoading(true)
const documentsToExport = await Promise.all(
documents.map(async (doc) => {
const blocks: HMBlockNode[] | undefined = doc.document?.children
Expand All @@ -153,9 +156,11 @@ export default function ExportPage() {
exportDocuments(documentsToExport)
.then((res) => {
toast.success(res)
setLoading(false)
})
.catch((err) => {
toast.error(err)
setLoading(false)
})
}

Expand All @@ -168,10 +173,13 @@ export default function ExportPage() {
<Button
marginBottom="$4"
width="$20"
disabled={loading}
onPress={() => {
submitExportDocuments()
}}
>{`Export ${documents.length} documents`}</Button>
>
{loading ? <Spinner /> : `Export ${documents.length} documents`}
</Button>
<YStack margin="$1.5" w="100%">
<XStack
marginBottom="$5"
Expand Down Expand Up @@ -211,10 +219,13 @@ export default function ExportPage() {
<Button
marginTop="$3"
width="$20"
disabled={loading}
onPress={() => {
submitExportDocuments()
}}
>{`Export ${documents.length} documents`}</Button>
>
{loading ? <Spinner /> : `Export ${documents.length} documents`}
</Button>
</YStack>
</Container>
</MainWrapper>
Expand Down

0 comments on commit 6c01b69

Please sign in to comment.