Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: loader in between renders of pages #137

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/components/ExplorerTable/ExplorerTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { Table, TableHead, TableCell, TableBody, TableRow } from "@mui/material"
import { Table, TableHead, TableCell, TableBody, TableRow, CircularProgress, Container } from "@mui/material"
import clsx from "clsx"
import { Link } from "react-router-dom"
import { EvmBridgeConfig, ResourceTypes, SharedConfigDomain, Transfer } from "../../types"
Expand Down Expand Up @@ -144,21 +144,16 @@ const ExplorerTable: React.FC<ExplorerTable> = ({ state, sharedConfig }: Explore
<TableCell sx={{ borderTopRightRadius: "12px !important" }}>Value</TableCell>
</TableRow>
</TableHead>
<TableBody>
{state.loading === "done" ? (
renderTransferList(state.transfers)
) : (
{state.loading === "done" && <TableBody>{renderTransferList(state.transfers)}</TableBody>}
{state.loading === "loading" && (
<TableBody>
<TableRow>
<TableCell>Loading</TableCell>
<TableCell colSpan={8} align="center">
<CircularProgress />
</TableCell>
</TableRow>
)}

{state.error && (
<TableRow>
<TableCell>{state.error}</TableCell>
</TableRow>
)}
</TableBody>
</TableBody>
)}
</Table>
)
}
Expand Down
15 changes: 7 additions & 8 deletions src/pages/ExplorerPage/hooks/useGetTransferData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const transferData = async (page: number, limit: number, routes: Routes, dispatc
type: "fetch_transfers",
payload: sanitizedTransfers,
})

dispatcher({
type: "loading_done",
})
} catch (e) {
dispatcher({
type: "fetch_transfer_error",
Expand Down Expand Up @@ -57,19 +61,14 @@ export function useGetTransferData(
state: ExplorerPageState,
explorerContextState: ExplorerContextState,
): void {
useEffect(() => {
if (state.loading === "loading" && state.transfers.length) {
dispatcher({
type: "loading_done",
})
}
}, [state.loading, state.transfers])

useEffect(() => {
if (!explorerContextState.account) {
const {
queryParams: { page, limit },
} = explorerContextState
dispatcher({
type: "loading_transfers",
})
void transferData(page, limit, routes, dispatcher)
} else {
const { account } = explorerContextState
Expand Down
7 changes: 6 additions & 1 deletion src/pages/ExplorerPage/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type TransferActions =
| { type: "fetch_transfer_by_sender"; payload: Transfer[] }
| { type: "fetch_transfer_by_sender_error"; payload: string }
| { type: "loading_done" }
| { type: "loading_transfers" }

export type ExplorerPageState = {
transfers: Transfer[]
Expand All @@ -20,7 +21,6 @@ export function reducer(state: ExplorerPageState, action: TransferActions): Expl
return {
...state,
transfers: action.payload,
loading: "loading",
error: undefined,
}
case "fetch_transfer_error":
Expand All @@ -47,6 +47,11 @@ export function reducer(state: ExplorerPageState, action: TransferActions): Expl
...state,
loading: "done",
}
case "loading_transfers":
return {
...state,
loading: "loading",
}
default:
return state
}
Expand Down
Loading