Skip to content

Commit e954364

Browse files
committed
WIP
1 parent fe41520 commit e954364

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/components/scenes/CoinRankingScene.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { checkEnabledExchanges } from '../../actions/SettingsActions'
66
import { SCROLL_INDICATOR_INSET_FIX } from '../../constants/constantSettings'
77
import { useAbortable } from '../../hooks/useAbortable'
88
import { useHandler } from '../../hooks/useHandler'
9+
import { useMount } from '../../hooks/useMount'
10+
import { useUnmount } from '../../hooks/useUnmount'
911
import { lstrings } from '../../locales/strings'
1012
import { getCoingeckoFiat } from '../../selectors/SettingsSelectors'
1113
import { FooterRender } from '../../state/SceneFooterState'
@@ -142,24 +144,27 @@ const CoinRankingComponent = (props: Props) => {
142144
setFooterHeight(height)
143145
})
144146

145-
React.useEffect(() => {
146-
if (lastSceneFiat !== coingeckoFiat) {
147+
useMount(() => {
148+
console.debug('useMount')
149+
if (lastSceneFiat == null) {
150+
lastSceneFiat = coingeckoFiat
151+
} else if (lastSceneFiat !== coingeckoFiat) {
147152
// Clear cache if we changed the fiat while outside of this scene
148153
debugLog(LOG_COINRANK, 'Clearing coinRankingDatas cache')
149154
coinRanking.coinRankingDatas = []
150155
lastStartIndex.current = 1
151156
setDataSize(0)
152157
setRequestDataSize(QUERY_PAGE_SIZE)
153158
}
159+
})
154160

155-
return () => {
156-
mounted.current = false
161+
useUnmount(() => {
162+
console.debug('useUnmount')
163+
mounted.current = false
157164

158-
// Queries should update this, but just in case:
159-
lastSceneFiat = coingeckoFiat
160-
}
161-
// eslint-disable-next-line react-hooks/exhaustive-deps
162-
}, [])
165+
// Queries should update this, but just in case:
166+
lastSceneFiat = coingeckoFiat
167+
})
163168

164169
React.useEffect(() => {
165170
return navigation.addListener('focus', () => {
@@ -170,7 +175,7 @@ const CoinRankingComponent = (props: Props) => {
170175
// Start querying starting from either the last fetched index (scrolling) or
171176
// the first index (initial load/timed refresh)
172177
const queryLoop = useAbortable(maybeAbort => async (startIndex: number) => {
173-
debugLog(LOG_COINRANK, `queryLoop(start: ${startIndex})`)
178+
debugLog(LOG_COINRANK, `queryLoop(start: ${startIndex}, size: ${requestDataSize})`)
174179

175180
try {
176181
// Catch up to the total required items. Always fetch if requesting the
@@ -228,7 +233,8 @@ const CoinRankingComponent = (props: Props) => {
228233
}
229234

230235
return () => {
231-
// Reset related query state when this effect is unmounted (coingeckoFiat
236+
console.debug('queryLoop cleanup, mounted.current: ', mounted.current)
237+
// Reset related query state when this effect is cleaned up (coingeckoFiat
232238
// changed), but the scene is still mounted:
233239
if (mounted.current) {
234240
debugLog(LOG_COINRANK, `Clearing coinRankingDatas cache for new fiat: ${coingeckoFiat}`)
@@ -241,7 +247,6 @@ const CoinRankingComponent = (props: Props) => {
241247
setRequestDataSize(QUERY_PAGE_SIZE)
242248
}
243249
}
244-
// eslint-disable-next-line react-hooks/exhaustive-deps
245250
}, [coingeckoFiat /* reset subscription on fiat change */, queryLoop])
246251

247252
const listData: number[] = React.useMemo(() => {

src/util/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export const LOG_COINRANK = 0x0001
200200
export const debugLog = (type: number, ...args: any): void => {
201201
// Provides date formatting for the form '01-14 03:43:56.273'
202202
const dateTime = new Date().toISOString().slice(5, 23).replace('T', ' ')
203-
if (type & debugLogType) console.log(dateTime, ...args)
203+
console.debug(dateTime, ...args)
204204
}
205205

206206
export const enableDebugLogType = (type: number) => (debugLogType |= type)

0 commit comments

Comments
 (0)