fix: prevent repeated redirect when switching from grid to sidebar view

The default-view redirect in HomePage fired on every mount, not just the
initial page load. A module-level flag now gates the redirect so it only
applies once per session, allowing users to switch to sidebar view when
grid is the default.

Closes #128
This commit is contained in:
SnapOtter
2026-05-07 22:16:26 +08:00
parent ff8a280b45
commit 14810c3c78
3 changed files with 168 additions and 1 deletions
+9 -1
View File
@@ -13,6 +13,8 @@ import { useSettingsStore } from "@/stores/settings-store";
// Tools shown prominently as "quick actions" at the top
const QUICK_ACTION_IDS = ["resize", "compress", "convert", "remove-background"];
let hasAppliedDefaultRedirect = false;
export function HomePage() {
const {
setFiles,
@@ -37,7 +39,13 @@ export function HomePage() {
}, [fetchSettings, fetchFeatures]);
useEffect(() => {
if (settingsLoaded && defaultToolView === "fullscreen" && files.length === 0) {
if (
!hasAppliedDefaultRedirect &&
settingsLoaded &&
defaultToolView === "fullscreen" &&
files.length === 0
) {
hasAppliedDefaultRedirect = true;
navigate("/fullscreen", { replace: true });
}
}, [settingsLoaded, defaultToolView, files.length, navigate]);