File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed
Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,7 @@ import "@/ui-components/menu/menu.css";
55import { goto } from " $app/navigation" ;
66import { MAX_WORLD , SearchParamState } from " ./params.svelte.ts" ;
77
8- const search = $state (new SearchParamState ());
9- onMount (() => {
10- const params = new URLSearchParams (window .location .search );
11- search .world = Number (params .get (" world" ) || " 1" );
12- search .selected = Number (params .get (" selected" ) || " 1" );
13- });
8+ const search = new SearchParamState ();
149
1510const blocks = $derived (
1611 new Array (search .maxStage ).fill (null ).map ((_ , idx ) => ({
Original file line number Diff line number Diff line change 11import { browser } from "$app/environment" ;
22import { replaceState } from "$app/navigation" ;
3+ import { onMount } from "svelte" ;
34
45export const MAX_WORLD = 4 ;
56const WORLD_STAGES_MAP = new Map ( [
@@ -16,6 +17,12 @@ export class SearchParamState {
1617 constructor ( ) {
1718 this . #world = null ;
1819 this . #selected = null ;
20+
21+ onMount ( ( ) => {
22+ const params = new URLSearchParams ( window . location . search ) ;
23+ this . world = Number ( params . get ( "world" ) || "1" ) ;
24+ this . selected = Number ( params . get ( "selected" ) || "1" ) ;
25+ } ) ;
1926 }
2027
2128 get world ( ) : number | null {
@@ -82,11 +89,13 @@ export class SearchParamState {
8289 const url = new URL ( window . location . href ) ;
8390 url . searchParams . set ( "world" , String ( this . #world) ) ;
8491 url . searchParams . set ( "selected" , String ( this . #selected) ) ;
85- try {
86- replaceState ( url . toString ( ) , { } ) ;
87- } catch ( e ) {
88- // what do you mean "Cannot call replaceState(...) before router is initialized"
89- console . warn ( "Failed to update URL:" , e ) ;
90- }
92+ setTimeout ( ( ) => {
93+ try {
94+ replaceState ( url . toString ( ) , { } ) ;
95+ } catch ( e ) {
96+ // what do you mean "Cannot call replaceState(...) before router is initialized"
97+ console . warn ( "Failed to update URL:" , e ) ;
98+ }
99+ } , 0 ) ;
91100 }
92101}
You can’t perform that action at this time.
0 commit comments