|
1 | 1 | import { Box, Grid, Group, NumberFormatter, Paper, Table, Text, Title } from "@mantine/core"; |
2 | 2 | import { useLocalStorage } from "@mantine/hooks"; |
3 | | -import { useEffect, useState } from "react"; |
| 3 | +import { useEffect, useState, useTransition } from "react"; |
4 | 4 | import { TauriTypes } from "$types"; |
5 | 5 | import { useQueries } from "./queries"; |
6 | 6 | import { useTauriEvent } from "@hooks/useTauriEvent.hook"; |
@@ -58,6 +58,10 @@ export const TransactionPanel = ({ isActive }: TransactionPanelProps = {}) => { |
58 | 58 | const [filterOpened, setFilterOpened] = useState<boolean>(false); |
59 | 59 | const [canExport, setCanExport] = useState<boolean>(false); |
60 | 60 |
|
| 61 | + // Progressive rendering === allows navigation during table render (without it ui freezes until table loads) |
| 62 | + const [isPending, startTransition] = useTransition(); |
| 63 | + const [displayedRecords, setDisplayedRecords] = useState<TauriTypes.TransactionDto[]>([]); |
| 64 | + |
61 | 65 | // Check permissions for export on mount |
62 | 66 | useEffect(() => { |
63 | 67 | HasPermission(TauriTypes.PermissionsFlags.EXPORT_DATA).then((res) => setCanExport(res)); |
@@ -94,6 +98,17 @@ export const TransactionPanel = ({ isActive }: TransactionPanelProps = {}) => { |
94 | 98 | // Use the custom hook for Tauri events |
95 | 99 | useTauriEvent(TauriTypes.Events.RefreshTransactions, handleRefresh, []); |
96 | 100 |
|
| 101 | + // Progressive rendering |
| 102 | + useEffect(() => { |
| 103 | + if (paginationQuery.isFetching) { |
| 104 | + setDisplayedRecords([]); |
| 105 | + } else if (paginationQuery.data?.results) { |
| 106 | + startTransition(() => { |
| 107 | + setDisplayedRecords(paginationQuery.data?.results || []); |
| 108 | + }); |
| 109 | + } |
| 110 | + }, [paginationQuery.isFetching, paginationQuery.data?.results]); |
| 111 | + |
97 | 112 | return ( |
98 | 113 | <Box p={"md"}> |
99 | 114 | {" "} |
@@ -200,8 +215,8 @@ export const TransactionPanel = ({ isActive }: TransactionPanelProps = {}) => { |
200 | 215 | className={`${classes.databaseTransactions} ${useHasAlert() ? classes.alert : ""} ${filterOpened ? classes.filterOpened : ""}`} |
201 | 216 | mt={"md"} |
202 | 217 | striped |
203 | | - fetching={paginationQuery.isFetching || calculateTaxMutation.isPending} |
204 | | - records={paginationQuery.isFetching ? [] : (paginationQuery.data?.results || [])} |
| 218 | + fetching={paginationQuery.isFetching || isPending || calculateTaxMutation.isPending} |
| 219 | + records={displayedRecords} |
205 | 220 | page={getSafePage(queryData.page, paginationQuery.data?.total_pages)} |
206 | 221 | onPageChange={(page) => setQueryData((prev) => ({ ...prev, page }))} |
207 | 222 | totalRecords={paginationQuery.data?.total || 0} |
|
0 commit comments