Skip to content

Commit

Permalink
fix(app): fix initial frameworks selected handling
Browse files Browse the repository at this point in the history
  • Loading branch information
matschik committed Mar 5, 2024
1 parent 84fc766 commit d2b82d1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import CodeEditor from "./components/CodeEditor.svelte";
import AppNotificationCenter from "./components/AppNotificationCenter.svelte";
import createLocaleStorage from "./lib/createLocaleStorage.js";
import { getContext, onMount } from "svelte";
import { getContext, onDestroy, onMount } from "svelte";
import Header from "./components/Header.svelte";
import Aside from "./components/Aside.svelte";
import GithubIcon from "./components/GithubIcon.svelte";
Expand Down Expand Up @@ -48,16 +48,18 @@
let isMounted = false;
const siteTitle = "Component Party";
// -- on route change --
$: {
const unsubscribeCurrentRoute = currentRoute.subscribe(($currentRoute) => {
window.scrollTo(0, 0);
isVersusFrameworks = false;
document.title = siteTitle;
if ($currentRoute.path === "/") {
if (isMounted) {
handleInitialFrameworkIdsSelectedFromStorage();
handleInitialFrameworkIdsSelectedFromStorage({ useDefaults: false });
} else {
onMountCallbacks.add(handleInitialFrameworkIdsSelectedFromStorage);
onMountCallbacks.add(() =>
handleInitialFrameworkIdsSelectedFromStorage({ useDefaults: true })
);
}
} else if ($currentRoute.params?.versus) {
const versusFrameworks = handleVersus($currentRoute.params.versus);
Expand All @@ -74,9 +76,11 @@
} else {
navigate("/");
}
}
});
onDestroy(unsubscribeCurrentRoute);
function handleInitialFrameworkIdsSelectedFromStorage() {
function handleInitialFrameworkIdsSelectedFromStorage({ useDefaults }) {
let frameworkIdsSelectedOnInit = [];
const url = new URL(window.location.href);
Expand All @@ -103,7 +107,7 @@
}
}
if (frameworkIdsSelectedOnInit.length === 0) {
if (useDefaults && frameworkIdsSelectedOnInit.length === 0) {
frameworkIdsSelectedOnInit = ["react", "svelte4"];
}
Expand Down

0 comments on commit d2b82d1

Please sign in to comment.