@@ -41,7 +41,7 @@ import type { T } from '@deltachat/jsonrpc-client'
41
41
import CreateChat from '../../dialogs/CreateChat'
42
42
import { runtime } from '@deltachat-desktop/runtime-interface'
43
43
import asyncThrottle from '@jcoreio/async-throttle'
44
- import { useFetch } from '../../../hooks/useFetch'
44
+ import { useFetch , useRpcFetch } from '../../../hooks/useFetch'
45
45
import { getLogger } from '@deltachat-desktop/shared/logger'
46
46
47
47
const log = getLogger ( 'MainScreen' )
@@ -481,29 +481,25 @@ function ChatNavButtons({ chat }: { chat: T.FullChat }) {
481
481
}
482
482
483
483
function AppIcon ( { accountId, app } : { accountId : number ; app : T . Message } ) {
484
- const [ webxdcInfo , setWebxdcInfo ] = useState < T . WebxdcMessageInfo | null > ( null )
485
- const [ isLoadingWebxdcInfo , setIsLoadingWebxdcInfo ] = useState ( true )
484
+ const tx = useTranslationFunction ( )
486
485
487
- useEffect ( ( ) => {
488
- if ( app . viewType === 'Webxdc' ) {
489
- setIsLoadingWebxdcInfo ( true )
490
- BackendRemote . rpc
491
- . getWebxdcInfo ( accountId , app . id )
492
- . then ( ( info : T . WebxdcMessageInfo ) => {
493
- setWebxdcInfo ( info )
494
- } )
495
- . catch ( ( error : any ) => {
496
- console . error ( 'Failed to load webxdc info for app:' , app . id , error )
497
- setWebxdcInfo ( null )
498
- } )
499
- . finally ( ( ) => {
500
- setIsLoadingWebxdcInfo ( false )
501
- } )
502
- }
503
- } , [ accountId , app . id , app . viewType ] )
486
+ const webxdcInfoFetch = useRpcFetch ( BackendRemote . rpc . getWebxdcInfo , [
487
+ accountId ,
488
+ app . id ,
489
+ ] )
490
+ if ( webxdcInfoFetch . result ?. ok === false ) {
491
+ log . error (
492
+ 'Failed to load webxdc info for app:' ,
493
+ app . id ,
494
+ webxdcInfoFetch . result . err
495
+ )
496
+ }
504
497
505
- const appName =
506
- webxdcInfo ?. name || ( isLoadingWebxdcInfo ? 'Loading...' : 'Unknown App' )
498
+ const appName = webxdcInfoFetch . loading
499
+ ? tx ( 'loading' )
500
+ : webxdcInfoFetch . result . ok
501
+ ? webxdcInfoFetch . result . value . name
502
+ : 'Unknown App'
507
503
508
504
return (
509
505
< Button
@@ -512,8 +508,12 @@ function AppIcon({ accountId, app }: { accountId: number; app: T.Message }) {
512
508
className = { styles . webxdcIconButton }
513
509
title = { appName }
514
510
aria-label = { appName }
511
+ aria-busy = { webxdcInfoFetch . loading }
515
512
onClick = { ( ) => {
516
- openWebxdc ( app , webxdcInfo ?? undefined )
513
+ openWebxdc (
514
+ app ,
515
+ webxdcInfoFetch . result ?. ok ? webxdcInfoFetch . result . value : undefined
516
+ )
517
517
} }
518
518
>
519
519
< img
0 commit comments