Skip to content

Commit

Permalink
Improve refresh button behavior in lists (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodyowl authored Oct 8, 2024
1 parent 32b3b85 commit 48cc86d
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ export const AccountMembersDetailsCardList = ({
filters={filters}
search={search}
status={status}
onRefresh={() => {
reload();
}}
onRefresh={reload}
onChangeFilters={filters => {
Router.replace("AccountMembersDetailsCardList", {
accountMembershipId: currentUserAccountMembershipId,
Expand Down
7 changes: 5 additions & 2 deletions clients/banking/src/components/BeneficiaryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ export const BeneficiaryList = ({
Option.fromNullable(data.account?.trustedBeneficiaries).toResult(undefined),
);

const [isRefreshing, setIsRefreshing] = useState(false);

return (
<ResponsiveContainer breakpoint={breakpoints.large} style={styles.fill}>
{({ large }) => {
Expand Down Expand Up @@ -580,9 +582,10 @@ export const BeneficiaryList = ({
mode="secondary"
size="small"
icon="arrow-counterclockwise-filled"
loading={beneficiaries.isLoading()}
loading={isRefreshing}
onPress={() => {
reload();
setIsRefreshing(true);
reload().tap(() => setIsRefreshing(false));
}}
/>
</>
Expand Down
4 changes: 1 addition & 3 deletions clients/banking/src/components/CardItemTransactionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ export const CardItemTransactionList = ({
large={large}
filters={filters}
search={search}
onRefresh={() => {
reload();
}}
onRefresh={reload}
onChangeFilters={filters => {
Router.replace("AccountCardsItemTransactions", { ...params, ...filters });
}}
Expand Down
12 changes: 9 additions & 3 deletions clients/banking/src/components/CardListFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dict } from "@swan-io/boxed";
import { Dict, Future } from "@swan-io/boxed";
import { Box } from "@swan-io/lake/src/components/Box";
import { Fill } from "@swan-io/lake/src/components/Fill";
import { FilterChooser } from "@swan-io/lake/src/components/FilterChooser";
Expand Down Expand Up @@ -50,7 +50,7 @@ type TransactionListFilterProps = {
search: string | undefined;
status: "Active" | "Canceled";
onChangeFilters: (filters: Partial<CardFilters>) => void;
onRefresh: () => void;
onRefresh: () => Future<unknown>;
onChangeSearch: (search: string | undefined) => void;
onChangeStatus: (status: "Active" | "Canceled") => void;
};
Expand Down Expand Up @@ -100,6 +100,8 @@ export const CardListFilter = ({
});
}, [filters]);

const [isRefreshing, setIsRefreshing] = useState(false);

return (
<>
<Box direction="row" alignItems="center">
Expand Down Expand Up @@ -129,7 +131,11 @@ export const CardListFilter = ({
mode="secondary"
size="small"
icon="arrow-counterclockwise-filled"
onPress={onRefresh}
loading={isRefreshing}
onPress={() => {
setIsRefreshing(true);
onRefresh().tap(() => setIsRefreshing(false));
}}
/>
</>
) : null}
Expand Down
12 changes: 9 additions & 3 deletions clients/banking/src/components/MembershipListFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsyncData, Dict, Result } from "@swan-io/boxed";
import { AsyncData, Dict, Future, Result } from "@swan-io/boxed";
import { Box } from "@swan-io/lake/src/components/Box";
import { Fill } from "@swan-io/lake/src/components/Fill";
import { FilterChooser } from "@swan-io/lake/src/components/FilterChooser";
Expand Down Expand Up @@ -107,7 +107,7 @@ type MembershipListFilterProps = {
search: string | undefined;
totalCount: AsyncData<Result<number, unknown>>;
onChangeFilters: (filters: Partial<MembershipFilters>) => void;
onRefresh: () => void;
onRefresh: () => Future<unknown>;
onChangeSearch: (search: string | undefined) => void;
};

Expand Down Expand Up @@ -182,6 +182,8 @@ export const MembershipListFilter = ({
});
}, [filters]);

const [isRefreshing, setIsRefreshing] = useState(false);

return (
<>
<Box direction="row" alignItems="center">
Expand Down Expand Up @@ -211,7 +213,11 @@ export const MembershipListFilter = ({
mode="secondary"
size="small"
icon="arrow-counterclockwise-filled"
onPress={onRefresh}
loading={isRefreshing}
onPress={() => {
setIsRefreshing(true);
onRefresh().tap(() => setIsRefreshing(false));
}}
/>
</>
) : null}
Expand Down
4 changes: 1 addition & 3 deletions clients/banking/src/components/MembershipsArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ export const MembershipsArea = ({
onChangeSearch={search => {
Router.replace("AccountMembersList", { accountMembershipId, ...params, search });
}}
onRefresh={() => {
reload();
}}
onRefresh={reload}
totalCount={data.mapOk(data => data.account?.memberships.totalCount ?? 0)}
large={large}
>
Expand Down
8 changes: 6 additions & 2 deletions clients/banking/src/components/MerchantList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ColumnConfig, PlainListView } from "@swan-io/lake/src/components/PlainL
import { Tag } from "@swan-io/lake/src/components/Tag";
import { Toggle } from "@swan-io/lake/src/components/Toggle";
import { colors, spacings } from "@swan-io/lake/src/constants/design";
import { useMemo } from "react";
import { useMemo, useState } from "react";
import { StyleSheet } from "react-native";
import { P, match } from "ts-pattern";
import {
Expand Down Expand Up @@ -210,6 +210,8 @@ export const MerchantList = ({ accountId, accountMembershipId, params, large }:
accountId,
});

const [isRefreshing, setIsRefreshing] = useState(false);

return (
<>
<Box
Expand All @@ -222,8 +224,10 @@ export const MerchantList = ({ accountId, accountMembershipId, params, large }:
mode="secondary"
size="small"
icon="arrow-counterclockwise-filled"
loading={isRefreshing}
onPress={() => {
reload();
setIsRefreshing(true);
reload().tap(() => setIsRefreshing(false));
}}
/>

Expand Down
14 changes: 10 additions & 4 deletions clients/banking/src/components/RecurringTransferList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ const RecurringTransferHistory = ({
canViewAccount,
});

const [isRefreshing, setIsRefreshing] = useState(false);

return (
<>
<Space height={24} />
Expand All @@ -130,9 +132,10 @@ const RecurringTransferHistory = ({
mode="secondary"
size="small"
icon="arrow-counterclockwise-filled"
loading={data.isLoading()}
loading={isRefreshing}
onPress={() => {
reload();
setIsRefreshing(true);
reload().tap(() => setIsRefreshing(false));
}}
/>
</ListRightPanelContent>
Expand Down Expand Up @@ -675,6 +678,8 @@ export const RecurringTransferList = ({
[],
);

const [isRefreshing, setIsRefreshing] = useState(false);

return (
<>
<Box
Expand All @@ -687,9 +692,10 @@ export const RecurringTransferList = ({
mode="secondary"
size="small"
icon="arrow-counterclockwise-filled"
loading={data.isLoading()}
loading={isRefreshing}
onPress={() => {
reload();
setIsRefreshing(true);
reload().tap(() => setIsRefreshing(false));
}}
/>

Expand Down
12 changes: 9 additions & 3 deletions clients/banking/src/components/TransactionListFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dict } from "@swan-io/boxed";
import { Dict, Future } from "@swan-io/boxed";
import { Box } from "@swan-io/lake/src/components/Box";
import { Fill } from "@swan-io/lake/src/components/Fill";
import { FilterChooser } from "@swan-io/lake/src/components/FilterChooser";
Expand Down Expand Up @@ -89,7 +89,7 @@ type TransactionListFilterProps = {
filters: TransactionFilters;
search: string | undefined;
onChangeFilters: (filters: Partial<TransactionFilters>) => void;
onRefresh: () => void;
onRefresh: () => Future<unknown>;
onChangeSearch: (search: string | undefined) => void;
filtersDefinition?: {
isAfterUpdatedAt: FilterDateDef;
Expand Down Expand Up @@ -161,6 +161,8 @@ export const TransactionListFilter = ({
});
}, [filters]);

const [isRefreshing, setIsRefreshing] = useState(false);

return (
<>
<Box direction="row" alignItems="center">
Expand Down Expand Up @@ -190,7 +192,11 @@ export const TransactionListFilter = ({
mode="secondary"
size="small"
icon="arrow-counterclockwise-filled"
onPress={onRefresh}
loading={isRefreshing}
onPress={() => {
setIsRefreshing(true);
onRefresh().tap(() => setIsRefreshing(false));
}}
/>
</>
) : null}
Expand Down
4 changes: 1 addition & 3 deletions clients/banking/src/components/TransferList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export const TransferList = ({
large={large}
filters={filters}
search={search}
onRefresh={() => {
reload();
}}
onRefresh={reload}
onChangeFilters={({ status, ...filters }) =>
Router.replace("AccountPaymentsRoot", {
...params,
Expand Down
4 changes: 1 addition & 3 deletions clients/banking/src/pages/CardListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ export const CardListPage = ({
filters={filters}
search={search}
status={status}
onRefresh={() => {
reload();
}}
onRefresh={reload}
onChangeFilters={filters => {
Router.replace("AccountCardsList", { accountMembershipId, ...params, ...filters });
}}
Expand Down
4 changes: 1 addition & 3 deletions clients/banking/src/pages/TransactionListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ export const TransactionListPage = ({
large={large}
filters={filters}
search={search}
onRefresh={() => {
reload();
}}
onRefresh={reload}
onChangeFilters={({ status, ...filters }) => {
Router.replace("AccountTransactionsListRoot", {
...params,
Expand Down

0 comments on commit 48cc86d

Please sign in to comment.