Skip to content

Commit

Permalink
Added transition to the skeletons
Browse files Browse the repository at this point in the history
  • Loading branch information
PsychoSanchez committed Nov 11, 2024
1 parent 8f3904c commit 9566d3a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
31 changes: 28 additions & 3 deletions src/popup/components/AppLoadingSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import React from 'react';
import React, { useCallback } from 'react';

import { Skeleton } from '@shared/ui/skeleton';
import { cn } from '@shared/utils';

export const AppLoadingSkeleton = () => {
export const AppLoadingSkeleton = ({
className,
isVisible,
}: {
className?: string;
isVisible: boolean;
}) => {
const handleTransitionEnd = useCallback(
(e: React.TransitionEvent<HTMLDivElement>): void => {
if (e.propertyName === 'opacity') {
const displayStyle = e.currentTarget.classList.contains('opacity-0')
? 'none'
: '';
e.currentTarget.style.display = displayStyle;
}
},
[],
);
return (
<div className="flex flex-col gap-2 w-full p-2">
<div
className={cn(
'flex flex-col gap-2 w-full p-2 bg-background absolute top-0 transition-opacity duration-500 pointer-events-none overflow-hidden max-h-full',
className,
isVisible ? 'opacity-100' : 'opacity-0',
)}
onTransitionEnd={handleTransitionEnd}
>
<Skeleton className="h-10 min-w-32 w-full bg-gray-500/20 dark:bg-gray-500/10" />
<Skeleton className="h-32 min-w-32 w-full bg-gray-500/20 dark:bg-gray-500/10" />
<Skeleton className="h-32 min-w-32 w-full bg-gray-500/20 dark:bg-gray-500/10" />
Expand Down
5 changes: 3 additions & 2 deletions src/popup/components/_stories/AppLoadingSkeleton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ type Story = StoryObj<Meta<typeof AppLoadingSkeleton>>;

export const Default: Story = {
render: () => (
<div className="min-w-[600px]">
<AppLoadingSkeleton />
<div className="min-w-[600px] relative">
<div className="min-w-[600px] min-h-[1000px] bg-red-600"></div>
<AppLoadingSkeleton className="absolute top-0 bg-background" isVisible />
</div>
),
parameters: {
Expand Down
5 changes: 4 additions & 1 deletion src/popup/hooks/PopupContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export const PopupContextProvider = ({ children }: React.PropsWithChildren) => {
updateSettings,
}}
>
{isLoaded ? children : <AppLoadingSkeleton />}
<div className="relative">
{children}
<AppLoadingSkeleton isVisible={!isLoaded} />
</div>
</PopupContext.Provider>
);
};
10 changes: 1 addition & 9 deletions src/popup/hooks/useTimeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const useTimeStore = () => {
const [isLoaded, setIsLoaded] = React.useState(false);

React.useEffect(() => {
const startDate = new Date();
Promise.all([getTotalActivity(), getActiveTabRecord()]).then(
([activity, activeRecord]) => {
if (activeRecord?.hostname) {
Expand All @@ -26,14 +25,7 @@ export const useTimeStore = () => {
}

setStore(activity);

const endDate = new Date();
// Should be at least 150ms to avoid flickering
const delay = Math.max(
150 - (endDate.getTime() - startDate.getTime()),
0,
);
setTimeout(() => setIsLoaded(true), delay);
setIsLoaded(true);
},
);
}, []);
Expand Down
3 changes: 2 additions & 1 deletion src/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@tailwind components;
@tailwind utilities;


@layer base {
:root {
--background: 0 0% 100%;
Expand All @@ -23,7 +24,7 @@
--border: 20 5.9% 90%;
--input: 20 5.9% 90%;
--ring: 24.6 95% 53.1%;
--radius: 0.5rem;
--radius: 0.75rem;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
Expand Down

0 comments on commit 9566d3a

Please sign in to comment.