From 74af825c3603c8a46c8fc3fc879d01dee0f4dfe9 Mon Sep 17 00:00:00 2001 From: drafish Date: Sat, 21 Sep 2024 11:22:55 +0800 Subject: [PATCH] fix load repo on first loading --- apps/learneth/src/App.tsx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/learneth/src/App.tsx b/apps/learneth/src/App.tsx index 517394cbe7..7b7bcdc378 100644 --- a/apps/learneth/src/App.tsx +++ b/apps/learneth/src/App.tsx @@ -34,20 +34,28 @@ export const router = createHashRouter([ function App(): JSX.Element { const dispatch = useAppDispatch() + const loadRepo = (locale: any) => { + dispatch({ + type: 'remixide/save', + payload: { localeCode: locale.code }, + }) + dispatch({ + type: 'workshop/loadRepo', + payload: repoMap[locale.code] || repoMap.en, + }) + } + useEffect(() => { dispatch({ type: 'remixide/connect', callback: () => { + // @ts-ignore + remixClient.call('locale', 'currentLocale').then((locale: any) => { + loadRepo(locale) + }) // @ts-ignore remixClient.on('locale', 'localeChanged', (locale: any) => { - dispatch({ - type: 'remixide/save', - payload: { localeCode: locale.code }, - }) - dispatch({ - type: 'workshop/loadRepo', - payload: repoMap[locale.code] || repoMap.en, - }) + loadRepo(locale) }) } })