Skip to content

Commit f779037

Browse files
committed
better state management
1 parent 4476a57 commit f779037

4 files changed

Lines changed: 8 additions & 17 deletions

File tree

src/lib/adSlotConfig.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ export const adSlotConfig = {
1616
},
1717
};
1818

19-
export async function initializeAds(adSlots: {
20-
sidebar?: string;
21-
grid?: string;
22-
footer?: string;
23-
} | null) {
19+
export async function initializeAds() {
2420
let adBlock = false;
2521
let adsEnabled = true;
22+
let adSlots: { sidebar: string; grid: string; footer: string } | null = null;
2623
await detectAdBlockEnabled();
2724
console.log(
2825
"[R][CardGrid][Mount] AdBlock Enabled:",
@@ -65,5 +62,5 @@ export async function initializeAds(adSlots: {
6562
})();
6663
}
6764

68-
return { adBlock, adsEnabled };
65+
return { adBlock, adsEnabled, adSlots };
6966
}

src/lib/components/CardGrid.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import { browser } from "$app/environment";
2020
import { loadGames } from "$lib/loadCards.js";
2121
import { goto } from "$app/navigation";
22-
import { adSlotConfig, initializeAds } from "$lib/adSlotConfig.js";
22+
import { initializeAds } from "$lib/adSlotConfig.js";
2323
2424
let searchIsOpen = $state(false);
2525
let games = $state<Game[]>([]);
@@ -244,7 +244,7 @@
244244
245245
if (SessionState.ssr) return;
246246
247-
({ adBlock, adsEnabled } = await initializeAds(adSlots));
247+
({ adBlock, adsEnabled, adSlots } = await initializeAds());
248248
});
249249
250250
$effect(() => {

src/routes/play/+page.svelte

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
let commitHash = $state("");
7575
7676
let adsEnabled = $state(false);
77+
let adBlock = $state(false);
7778
let adSlots = $state<{
7879
sidebar: string;
7980
grid: string;
@@ -109,14 +110,7 @@
109110
} else {
110111
(async () => {
111112
if (!browser) return;
112-
113-
const hostname = window.location.hostname;
114-
const { adBlock, adsEnabled: adsOn } =
115-
await initializeAds(
116-
adSlots
117-
);
118-
adblock = adBlock;
119-
adsEnabled = adsOn;
113+
({ adBlock, adsEnabled, adSlots } = await initializeAds());
120114
})();
121115
}
122116
});

static/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-10-17T06:17:09.059Z
1+
2025-10-17T06:33:16.025Z

0 commit comments

Comments
 (0)