Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beasy-mobile
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
G
beasy-mobile
Commits
1efc9808
Commit
1efc9808
authored
May 30, 2024
by
G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle filtering of transactions by references
parent
b6aedca7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
11 deletions
+23
-11
useTransactionsHistory.tsx
src/hooks/useTransactionsHistory.tsx
+15
-2
TransactionHistoryScreen.tsx
src/screens/TransactionHistoryScreen.tsx
+8
-9
No files found.
src/hooks/useTransactionsHistory.tsx
View file @
1efc9808
import
{
type
Transaction
,
getTransactionsHistory
}
from
"@/utils/requests/transactions"
;
import
{
LOG
}
from
"@logger"
;
import
{
useQuery
}
from
"@tanstack/react-query"
;
import
{
use
Memo
}
from
"react"
;
import
{
use
Callback
,
useMemo
,
useState
}
from
"react"
;
const
log
=
LOG
.
extend
(
"useTransactionsHistory"
);
const
useTransactionsHistory
=
()
=>
{
const
[
referenceFilter
,
setReferenceFilter
]
=
useState
<
string
>
(
""
);
log
.
verbose
(
"useTransactionsHistory"
);
const
{
data
,
isLoading
,
error
,
refetch
}
=
useQuery
({
...
...
@@ -13,13 +15,24 @@ const useTransactionsHistory = () => {
queryFn
:
getTransactionsHistory
,
});
const
transactionsHistory
:
Transaction
[]
=
useMemo
(()
=>
data
||
[],
[
data
]);
const
filterByReference
=
useCallback
(
(
reference
:
string
)
=>
{
if
(
!
data
?.
length
)
return
[];
return
data
.
filter
((
transaction
)
=>
transaction
.
reference
.
includes
(
reference
));
},
[
data
],
);
const
transactionsHistory
:
Transaction
[]
=
useMemo
(()
=>
{
if
(
!
data
)
return
[];
return
filterByReference
(
referenceFilter
);
},
[
data
,
filterByReference
,
referenceFilter
]);
return
{
transactionsHistory
,
isLoading
,
error
,
refetch
,
setReferenceFilter
,
};
};
...
...
src/screens/TransactionHistoryScreen.tsx
View file @
1efc9808
...
...
@@ -11,20 +11,19 @@ const log = LOG.extend("TransactionHistoryScreen");
const
TransactionHistoryScreen
=
()
=>
{
log
.
verbose
(
"TransactionHistoryScreen"
);
const
{
transactionsHistory
:
data
,
isLoading
,
error
,
refetch
}
=
useTransactionsHistory
();
// const { data, isLoading, error, refetch } = useQuery({
// queryKey: ["transactionsHistory"],
// queryFn: getTransactionsHistory,
// });
console
.
info
(
"Data"
,
data
);
const
{
transactionsHistory
:
data
,
isLoading
,
error
,
refetch
,
setReferenceFilter
,
}
=
useTransactionsHistory
();
return
(
<
BackgroundWithBeasyIconAndWhiteContentArea
>
<>
<
Box
px=
{
"m"
}
mt=
{
"m"
}
>
<
Input
label=
{
"Reference"
}
/>
<
Input
label=
{
"Reference"
}
onChangeText=
{
setReferenceFilter
}
/>
</
Box
>
<
ScrollView
refreshControl=
{
<
RefreshControl
refreshing=
{
isLoading
}
onRefresh=
{
refetch
}
/>
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment