Skip to content

Commit 16d3394

Browse files
authored
feat: loader in between renders of pages (#137)
* feat: loader in between renders of pages * chore: remove unused import
1 parent bb5b989 commit 16d3394

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/components/ExplorerTable/ExplorerTable.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react"
2-
import { Table, TableHead, TableCell, TableBody, TableRow } from "@mui/material"
2+
import { Table, TableHead, TableCell, TableBody, TableRow, CircularProgress } from "@mui/material"
33
import clsx from "clsx"
44
import { Link } from "react-router-dom"
55
import { EvmBridgeConfig, ResourceTypes, SharedConfigDomain, Transfer } from "../../types"
@@ -144,21 +144,16 @@ const ExplorerTable: React.FC<ExplorerTable> = ({ state, sharedConfig }: Explore
144144
<TableCell sx={{ borderTopRightRadius: "12px !important" }}>Value</TableCell>
145145
</TableRow>
146146
</TableHead>
147-
<TableBody>
148-
{state.loading === "done" ? (
149-
renderTransferList(state.transfers)
150-
) : (
147+
{state.loading === "done" && <TableBody>{renderTransferList(state.transfers)}</TableBody>}
148+
{state.loading === "loading" && (
149+
<TableBody>
151150
<TableRow>
152-
<TableCell>Loading</TableCell>
151+
<TableCell colSpan={8} align="center">
152+
<CircularProgress />
153+
</TableCell>
153154
</TableRow>
154-
)}
155-
156-
{state.error && (
157-
<TableRow>
158-
<TableCell>{state.error}</TableCell>
159-
</TableRow>
160-
)}
161-
</TableBody>
155+
</TableBody>
156+
)}
162157
</Table>
163158
)
164159
}

src/pages/ExplorerPage/hooks/useGetTransferData.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const transferData = async (page: number, limit: number, routes: Routes, dispatc
1515
type: "fetch_transfers",
1616
payload: sanitizedTransfers,
1717
})
18+
19+
dispatcher({
20+
type: "loading_done",
21+
})
1822
} catch (e) {
1923
dispatcher({
2024
type: "fetch_transfer_error",
@@ -57,19 +61,14 @@ export function useGetTransferData(
5761
state: ExplorerPageState,
5862
explorerContextState: ExplorerContextState,
5963
): void {
60-
useEffect(() => {
61-
if (state.loading === "loading" && state.transfers.length) {
62-
dispatcher({
63-
type: "loading_done",
64-
})
65-
}
66-
}, [state.loading, state.transfers])
67-
6864
useEffect(() => {
6965
if (!explorerContextState.account) {
7066
const {
7167
queryParams: { page, limit },
7268
} = explorerContextState
69+
dispatcher({
70+
type: "loading_transfers",
71+
})
7372
void transferData(page, limit, routes, dispatcher)
7473
} else {
7574
const { account } = explorerContextState

src/pages/ExplorerPage/reducer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type TransferActions =
66
| { type: "fetch_transfer_by_sender"; payload: Transfer[] }
77
| { type: "fetch_transfer_by_sender_error"; payload: string }
88
| { type: "loading_done" }
9+
| { type: "loading_transfers" }
910

1011
export type ExplorerPageState = {
1112
transfers: Transfer[]
@@ -20,7 +21,6 @@ export function reducer(state: ExplorerPageState, action: TransferActions): Expl
2021
return {
2122
...state,
2223
transfers: action.payload,
23-
loading: "loading",
2424
error: undefined,
2525
}
2626
case "fetch_transfer_error":
@@ -47,6 +47,11 @@ export function reducer(state: ExplorerPageState, action: TransferActions): Expl
4747
...state,
4848
loading: "done",
4949
}
50+
case "loading_transfers":
51+
return {
52+
...state,
53+
loading: "loading",
54+
}
5055
default:
5156
return state
5257
}

0 commit comments

Comments
 (0)