Skip to content

Commit 1bb2cb3

Browse files
authored
Merge pull request CyberTimon#1420 from RayJW/spinner-animation-gpu-usage-fix
Unload Spinner When Loading Is Done
2 parents 4ebfc45 + 00b8b28 commit 1bb2cb3

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/components/panel/MainLibrary.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export default function MainLibrary(props: MainLibraryProps) {
165165
const [isUpdateAvailable, setIsUpdateAvailable] = useState(false);
166166
const [latestVersion, setLatestVersion] = useState('');
167167
const [isBusyDelayed, setIsBusyDelayed] = useState(false);
168+
const [isBusyLoaderMounted, setIsBusyLoaderMounted] = useState(false);
168169
const [isProgressHovered, setIsProgressHovered] = useState(false);
169170
const isSettingsOpen = useUIStore((state) => state.isSettingsOpen);
170171

@@ -262,6 +263,12 @@ export default function MainLibrary(props: MainLibraryProps) {
262263
return () => clearTimeout(timer);
263264
}, [isBusy]);
264265

266+
useEffect(() => {
267+
if (isBusyDelayed) {
268+
setIsBusyLoaderMounted(true);
269+
}
270+
}, [isBusyDelayed]);
271+
265272
useEffect(() => {
266273
const compareVersions = (v1: string, v2: string) => {
267274
const parts1 = v1.split('.').map(Number);
@@ -511,8 +518,15 @@ export default function MainLibrary(props: MainLibraryProps) {
511518
className={`flex items-center gap-2 overflow-hidden transition-all duration-300 whitespace-nowrap ${
512519
isBusyDelayed ? 'max-w-xs opacity-100' : 'max-w-0 opacity-0'
513520
}`}
521+
onTransitionEnd={(e) => {
522+
if (e.propertyName === 'opacity' && !isBusyDelayed) {
523+
setIsBusyLoaderMounted(false);
524+
}
525+
}}
514526
>
515-
<Loader2 size={14} className="animate-spin text-text-secondary shrink-0" />
527+
{isBusyLoaderMounted && (
528+
<Loader2 size={14} className="animate-spin text-text-secondary shrink-0" />
529+
)}
516530
<div
517531
className={`flex items-center transition-all duration-300 ease-out overflow-hidden ${
518532
isProgressHovered && isBusyDelayed && (props.thumbnailProgress?.total ?? 0) > 0

src/components/panel/editor/EditorToolbar.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const EditorToolbar = memo(
4949
const { t } = useTranslation();
5050
const isAnyLoading = isLoading;
5151
const [isLoaderVisible, setIsLoaderVisible] = useState(false);
52+
const [isLoaderMounted, setIsLoaderMounted] = useState(false);
5253
const [disableLoaderTransition, setDisableLoaderTransition] = useState(false);
5354
const hideTimeoutRef = useRef<number | null>(null);
5455
const prevIsLoadingRef = useRef(isLoading);
@@ -138,6 +139,14 @@ const EditorToolbar = memo(
138139
};
139140
}, [isAnyLoading, isLoading, isLoaderVisible]);
140141

142+
useEffect(() => {
143+
if (isLoaderVisible) {
144+
setIsLoaderMounted(true);
145+
} else if (disableLoaderTransition) {
146+
setIsLoaderMounted(false);
147+
}
148+
}, [isLoaderVisible, disableLoaderTransition]);
149+
141150
useEffect(() => {
142151
if (!isHistoryVisible) return;
143152
const handleClickOutside = (e: MouseEvent) => {
@@ -433,8 +442,13 @@ const EditorToolbar = memo(
433442
isLoaderVisible ? 'max-w-4 opacity-100 ml-2' : 'max-w-0 opacity-0 ml-0',
434443
disableLoaderTransition ? 'transition-none' : 'transition-all duration-300',
435444
)}
445+
onTransitionEnd={(e) => {
446+
if (e.propertyName === 'opacity' && !isLoaderVisible) {
447+
setIsLoaderMounted(false);
448+
}
449+
}}
436450
>
437-
<Loader2 size={12} className="text-text-secondary animate-spin" />
451+
{isLoaderMounted && <Loader2 size={12} className="text-text-secondary animate-spin" />}
438452
</div>
439453
</div>
440454

0 commit comments

Comments
 (0)