From 503682e4166f578930dba3c51f40e99d43c25c44 Mon Sep 17 00:00:00 2001 From: Aronov Aleksandr Date: Sat, 16 Nov 2024 15:46:17 +0100 Subject: [PATCH] Fixed placeholder jittering --- src/popup/App.tsx | 51 +++++++++++---------- src/popup/components/AppLoadingSkeleton.tsx | 27 ++++++++--- src/popup/hooks/PopupContext.tsx | 9 ++-- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/popup/App.tsx b/src/popup/App.tsx index 7766356..c17a310 100644 --- a/src/popup/App.tsx +++ b/src/popup/App.tsx @@ -12,6 +12,7 @@ import { PreferencesPage } from '@popup/pages/preferences/PreferencesPage'; import '../tailwind.css'; import './App.css'; +import { AppLoadingSkeletonWrapper } from './components/AppLoadingSkeleton'; enum Pages { Overall = 'overall', @@ -39,30 +40,32 @@ export const PopupApp = () => { return ( - - - - {i18n('PopupApp_OverallTabTitle')} - - - {i18n('PopupApp_DetailedTabTitle')} - - - - - - - - - - - - - - - + + + + + {i18n('PopupApp_OverallTabTitle')} + + + {i18n('PopupApp_DetailedTabTitle')} + + + + + + + + + + + + + + + + ); }; diff --git a/src/popup/components/AppLoadingSkeleton.tsx b/src/popup/components/AppLoadingSkeleton.tsx index a55b734..049f40f 100644 --- a/src/popup/components/AppLoadingSkeleton.tsx +++ b/src/popup/components/AppLoadingSkeleton.tsx @@ -3,6 +3,8 @@ import React, { useCallback } from 'react'; import { Skeleton } from '@shared/ui/skeleton'; import { cn } from '@shared/utils'; +import { usePopupContext } from '@popup/hooks/PopupContext'; + export const AppLoadingSkeleton = ({ className, isVisible, @@ -24,17 +26,30 @@ export const AppLoadingSkeleton = ({ return (
- - - - - + + + + + +
+ ); +}; + +export const AppLoadingSkeletonWrapper = ({ + children, +}: React.PropsWithChildren) => { + const { isStoreLoaded } = usePopupContext(); + + return ( +
+ {children} +
); }; diff --git a/src/popup/hooks/PopupContext.tsx b/src/popup/hooks/PopupContext.tsx index b2e2ad8..3707850 100644 --- a/src/popup/hooks/PopupContext.tsx +++ b/src/popup/hooks/PopupContext.tsx @@ -4,7 +4,6 @@ import { DeepReadonly } from 'utility-types'; import { Preferences } from '@shared/db/types'; import { DEFAULT_PREFERENCES } from '@shared/preferences'; -import { AppLoadingSkeleton } from '@popup/components/AppLoadingSkeleton'; import { getFilteredWebsiteTimeStoreSlice } from '@popup/services/time-store'; import { useActiveTabHostname } from './useActiveTab'; @@ -12,6 +11,7 @@ import { useSettings } from './useSettings'; import { TimeStore, useTimeStore } from './useTimeStore'; export type PopupContextType = { + isStoreLoaded: boolean; store: TimeStore; activeHostname: string; settings: DeepReadonly; @@ -19,6 +19,7 @@ export type PopupContextType = { }; const DEFAULT_CONTEXT: PopupContextType = { + isStoreLoaded: false, store: {}, activeHostname: '', settings: DEFAULT_PREFERENCES, @@ -46,16 +47,14 @@ export const PopupContextProvider = ({ children }: React.PropsWithChildren) => { return ( -
- {children} - -
+ {children}
); };