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(Transactions): add loading spinner #2205

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Changes from all commits
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: 18 additions & 5 deletions src/app/screens/Transactions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Container from "@components/Container";
import Loading from "@components/Loading";
import TransactionsTable from "@components/TransactionsTable";
import { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
Expand All @@ -15,8 +16,12 @@ function Transactions() {

const { settings, getFormattedFiat } = useSettings();
const [transactions, setTransactions] = useState<Transaction[]>([]);
const [transactionsLoading, setTransactionsLoading] =
useState<boolean>(false);

const fetchData = useCallback(async () => {
setTransactionsLoading(true);

try {
// @Todo: add SWR caching? Check where to reset/mutate the cache?
const { payments } = await api.getPayments();
Expand All @@ -34,6 +39,8 @@ function Transactions() {
} catch (e) {
console.error(e);
if (e instanceof Error) toast.error(`Error: ${e.message}`);
} finally {
setTransactionsLoading(false);
}
}, [settings, getFormattedFiat]);

Expand All @@ -51,11 +58,17 @@ function Transactions() {
{t("description")}
</p>

<div>
{transactions?.length > 0 && (
<TransactionsTable transactions={transactions} />
)}
</div>
{transactionsLoading ? (
<div className="flex justify-center mt-12">
<Loading />
</div>
) : (
<div>
{transactions?.length > 0 && (
<TransactionsTable transactions={transactions} />
)}
</div>
)}
</Container>
);
}
Expand Down