Skip to content

Commit e47255e

Browse files
ralphtheninjanicodh
andauthored
Fix app picker caching (#4650)
* Fix app picker caching * Differentiate loading or offline (#4654) * Check apps for null before trying to sort --------- Co-authored-by: Nico de Haen <[email protected]>
1 parent 53c1d87 commit e47255e

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

packages/frontend/src/components/AppPicker/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ export function AppPicker({ className, onSelect, apps = [] }: Props) {
273273
))}
274274
</>
275275
) : (
276-
<div className={styles.offlineMessage}>{tx('loading')}</div>
276+
<div className={styles.offlineMessage}>
277+
{tx(isOffline ? 'offline' : 'loading')}
278+
</div>
277279
)}
278280
</div>
279281
<div className={styles.tabBar}>

packages/frontend/src/components/composer/AppPickerWrapper.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react'
1+
import React, { useEffect, useState } from 'react'
22
import { AppPicker, AppInfo, AppStoreUrl } from '../AppPicker'
33
import { getLogger } from '../../../../shared/logger'
44

@@ -27,11 +27,11 @@ const getJsonFromBase64 = (base64: string): any => {
2727

2828
type Props = {
2929
onAppSelected?: (app: AppInfo) => void
30-
apps: AppInfo[]
31-
setApps: (apps: AppInfo[]) => void
3230
}
3331

34-
export const AppPickerWrapper = ({ onAppSelected, apps, setApps }: Props) => {
32+
export const AppPickerWrapper = ({ onAppSelected }: Props) => {
33+
const [apps, setApps] = useState<AppInfo[]>([])
34+
3535
useEffect(() => {
3636
const fetchApps = async () => {
3737
try {
@@ -40,6 +40,7 @@ export const AppPickerWrapper = ({ onAppSelected, apps, setApps }: Props) => {
4040
AppStoreUrl + 'xdcget-lock.json'
4141
)
4242
const apps = getJsonFromBase64(response.blob) as AppInfo[]
43+
if (apps === null) return
4344
apps.sort((a: AppInfo, b: AppInfo) => {
4445
const dateA = new Date(a.date)
4546
const dateB = new Date(b.date)
@@ -52,17 +53,13 @@ export const AppPickerWrapper = ({ onAppSelected, apps, setApps }: Props) => {
5253
app.author = url.pathname.split('/')[1]
5354
app.date = moment(app.date).format('LL')
5455
}
55-
if (apps) {
56-
setApps(apps)
57-
}
56+
setApps(apps)
5857
} catch (error) {
5958
log.error('Failed to fetch apps:', error)
6059
}
6160
}
62-
if (!apps?.length) {
63-
fetchApps()
64-
}
65-
}, [apps, setApps])
61+
fetchApps()
62+
}, [setApps])
6663

6764
return (
6865
<div className={styles.appPickerContainer}>

packages/frontend/src/components/composer/Composer.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const Composer = forwardRef<
7777
const chatId = selectedChat.id
7878
const [showEmojiPicker, setShowEmojiPicker] = useState(false)
7979
const [showAppPicker, setShowAppPicker] = useState(false)
80-
const [apps, setApps] = useState<AppInfo[]>([])
8180

8281
const emojiAndStickerRef = useRef<HTMLDivElement>(null)
8382
const pickerButtonRef = useRef<HTMLButtonElement>(null)
@@ -429,11 +428,7 @@ const Composer = forwardRef<
429428
</div>
430429
{showAppPicker && (
431430
<OutsideClickHelper onClick={() => setShowAppPicker(false)}>
432-
<AppPickerWrapper
433-
onAppSelected={onAppSelected}
434-
apps={apps}
435-
setApps={setApps}
436-
/>
431+
<AppPickerWrapper onAppSelected={onAppSelected} />
437432
</OutsideClickHelper>
438433
)}
439434
{showEmojiPicker && (

0 commit comments

Comments
 (0)