Fix more button shown after logs deleted by wrapping setLogs
This commit is contained in:
parent
58c37bbd63
commit
0901f15249
|
@ -173,7 +173,7 @@ function tag (walletDef) {
|
|||
}
|
||||
|
||||
export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
|
||||
const [logs, setLogs] = useState([])
|
||||
const [logs, _setLogs] = useState([])
|
||||
const [page, setPage] = useState(initialPage)
|
||||
const [hasMore, setHasMore] = useState(true)
|
||||
const [total, setTotal] = useState(0)
|
||||
|
@ -183,6 +183,14 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
|
|||
const { getPage, error, notSupported } = useWalletLogDB()
|
||||
const [getWalletLogs] = useLazyQuery(WALLET_LOGS, SSR ? {} : { fetchPolicy: 'cache-and-network' })
|
||||
|
||||
const setLogs = useCallback((action) => {
|
||||
_setLogs(action)
|
||||
// action can be a React state dispatch function
|
||||
const newLogs = typeof action === 'function' ? action(logs) : action
|
||||
// make sure 'more' button is removed if logs were deleted
|
||||
if (newLogs.length === 0) setHasMore(false)
|
||||
}, [logs, _setLogs, setHasMore])
|
||||
|
||||
const loadLogsPage = useCallback(async (page, pageSize, walletDef) => {
|
||||
try {
|
||||
let result = { data: [], hasMore: false }
|
||||
|
@ -254,10 +262,5 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
|
|||
loadLogs()
|
||||
}, [wallet?.def])
|
||||
|
||||
useEffect(() => {
|
||||
// make sure 'more' button is removed if logs are deleted
|
||||
if (logs.length === 0) setHasMore(false)
|
||||
}, [logs?.length])
|
||||
|
||||
return { logs, hasMore, total, loadMore, loadLogs, setLogs, loading }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue