From 21e3492e15443cdafacd97b8895666e1a8118c61 Mon Sep 17 00:00:00 2001 From: Galin Chung Nguyen Date: Sat, 28 Dec 2024 14:53:39 +0700 Subject: [PATCH] delay popup rendering until extension settings are fetched --- pages/popup/src/Popup.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pages/popup/src/Popup.tsx b/pages/popup/src/Popup.tsx index cd04ac7..95a99bd 100644 --- a/pages/popup/src/Popup.tsx +++ b/pages/popup/src/Popup.tsx @@ -1,23 +1,25 @@ import '@src/Popup.css'; import { useStorage, withErrorBoundary, withSuspense } from '@extension/shared'; +import type { ZenSettings } from '@extension/storage'; import { themeStorage, zenStorage } from '@extension/storage'; import { useState } from 'react'; import { availableApps, type App } from '@extension/shared/lib/constants/apps'; import Timer from './Timer'; import ThemeSwitcher from './components/ThemeSwitcher'; -const Popup = () => { +const Popup = ({ zenSettings }: { zenSettings: ZenSettings }) => { const theme = useStorage(themeStorage); - const zenSettings = useStorage(zenStorage); + + console.log('zenSettings loaded is ', zenSettings); const isLight = theme === 'light'; - const [sessions, setSessions] = useState(zenSettings?.sessions ?? 4); - const [focusMinutes, setFocusMinutes] = useState(zenSettings?.focusMinutes ?? 25); - const [breakMinutes, setBreakMinutes] = useState(zenSettings?.breakMinutes ?? 5); - const [blockedApps, setBlockedApps] = useState(zenSettings?.blockedApps ?? []); + const [sessions, setSessions] = useState(zenSettings.sessions ?? 4); + const [focusMinutes, setFocusMinutes] = useState(zenSettings.focusMinutes ?? 25); + const [breakMinutes, setBreakMinutes] = useState(zenSettings.breakMinutes ?? 5); + const [blockedApps, setBlockedApps] = useState(zenSettings.blockedApps ?? []); const [newBlockedApp, setNewBlockedApp] = useState(''); const [searchResults, setSearchResults] = useState([]); - const [isTimerView, setIsTimerView] = useState(zenSettings?.timerActive ?? false); + const [isTimerView, setIsTimerView] = useState(zenSettings.timerActive ?? false); const handleSearch = (e: React.ChangeEvent) => { const searchTerm = e.target.value; @@ -359,4 +361,9 @@ const NumberInput = ({ label, value, onChange, suffix, isLight, type }: NumberIn ); }; -export default withErrorBoundary(withSuspense(Popup,
Loading ...
),
Error Occur
); +const PopupWrapper = () => { + const zenSettings = useStorage(zenStorage); + + return <>{zenSettings && }; +}; +export default withErrorBoundary(withSuspense(PopupWrapper,
Loading ...
),
Error Occur
);