From 2b50fc438f3d2ee9a8fa4973311bbb54de9c8a04 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:53:01 +0700 Subject: [PATCH] improve startup time --- src/app/auth/import/step-3.tsx | 10 ++-- src/app/auth/onboarding/step-1.tsx | 27 ++++------ src/app/space/index.tsx | 4 +- src/app/splash.tsx | 57 ++++++++++---------- src/libs/ndk/instance.ts | 51 ++++++++---------- src/libs/storage/instance.ts | 7 ++- src/libs/storage/provider.tsx | 4 +- src/shared/widgets/emptyList.tsx | 61 +++++++++++++++++++++ src/shared/widgets/index.ts | 2 + src/shared/widgets/loadLatestEvents.tsx | 61 +++++++++++++++++++++ src/shared/widgets/local/network.tsx | 26 ++++----- src/stores/stronghold.ts | 6 +++ src/utils/hooks/useNostr.ts | 70 ++++++++++++------------- 13 files changed, 244 insertions(+), 142 deletions(-) create mode 100644 src/shared/widgets/emptyList.tsx create mode 100644 src/shared/widgets/loadLatestEvents.tsx diff --git a/src/app/auth/import/step-3.tsx b/src/app/auth/import/step-3.tsx index 66f9f6dc..2c51dbaa 100644 --- a/src/app/auth/import/step-3.tsx +++ b/src/app/auth/import/step-3.tsx @@ -16,7 +16,7 @@ export function ImportStep3Screen() { const setStep = useOnboarding((state) => state.setStep); const { db } = useStorage(); - const { fetchUserData, prefetchEvents } = useNostr(); + const { fetchUserData } = useNostr(); const [loading, setLoading] = useState(false); @@ -27,16 +27,14 @@ export function ImportStep3Screen() { // prefetch data const user = await fetchUserData(); - const data = await prefetchEvents(); // create default widget await db.createWidget(WidgetKinds.other.learnNostr, 'Learn Nostr', ''); // redirect to next step - if (user.status === 'ok' && data.status === 'ok') { + if (user.status === 'ok') { navigate('/auth/onboarding/step-2', { replace: true }); } else { - console.log('error: ', data.message); setLoading(false); } } catch (e) { @@ -82,8 +80,8 @@ export function ImportStep3Screen() { )} - By clicking 'Continue', Lume will download your old relay list and - all events from the last 24 hours. It may take a bit + By clicking 'Continue', Lume will sync your old relay list and + metadata. It may take a bit diff --git a/src/app/auth/onboarding/step-1.tsx b/src/app/auth/onboarding/step-1.tsx index 1f9d2dd0..08b4bc06 100644 --- a/src/app/auth/onboarding/step-1.tsx +++ b/src/app/auth/onboarding/step-1.tsx @@ -16,7 +16,7 @@ export function OnboardStep1Screen() { const navigate = useNavigate(); const setStep = useOnboarding((state) => state.setStep); - const { publish, fetchUserData, prefetchEvents } = useNostr(); + const { publish, fetchUserData } = useNostr(); const { db } = useStorage(); const { status, data } = useQuery(['trending-profiles-widget'], async () => { const res = await fetch('https://api.nostr.band/v0/trending/profiles'); @@ -46,14 +46,12 @@ export function OnboardStep1Screen() { // prefetch data const user = await fetchUserData(follows); - const data = await prefetchEvents(); // redirect to next step - if (event && user.status === 'ok' && data.status === 'ok') { + if (event && user.status === 'ok') { navigate('/auth/onboarding/step-2', { replace: true }); } else { setLoading(false); - console.log('error: ', data.message); } } catch (e) { setLoading(false); @@ -70,7 +68,7 @@ export function OnboardStep1Screen() {
Choose the account you want to follow. These accounts are trending in the last @@ -127,19 +125,12 @@ export function OnboardStep1Screen() { > )} - {!loading ? ( - - Skip, you can add later - - ) : ( - - By clicking 'Continue', Lume will download all events related to - your follows from the last 24 hours. It may take a bit - - )} + + Skip, you can add later +
- This may take a few seconds, please don't close app. -
+ {ndk ? ( ++ Ensure all your data is sync across all Nostr clients, it may take a few + seconds, please don't close app. +
+ ) : null}