|
2 | 2 | import LazyLoad from "$lib/LazyLoad.svelte";
|
3 | 3 | import watermelon_image from "../images/watermelon.png?enhanced";
|
4 | 4 | import { onMount } from "svelte";
|
5 | | - import { page_views } from "../store"; |
| 5 | + import { did_update } from "../store"; |
6 | 6 |
|
| 7 | + let page_views = 0; |
7 | 8 | onMount(() => {
|
8 | | - conststoredValue=localStorage.getItem("page_views"); |
9 | | - if (storedValue) { |
10 | | - console.log("Stored value: ", storedValue); |
11 | | - page_views.set(storedValue); |
| 9 | + page_views =parseInt(localStorage.getItem("page_views")||0) +1; |
| 10 | + if (!$did_update) { |
| 11 | + localStorage.setItem("page_views", page_views); |
| 12 | + did_update.update((value) =>!value); |
12 | 13 | }
|
13 | | - |
14 | | - page_views.subscribe((value) => { |
15 | | - localStorage.setItem("page_views", ++value); // add page_views by one |
16 | | - }); |
17 | 14 | });
|
18 | 15 | </script>
|
19 | 16 |
|
|
22 | 19 | >
|
23 | 20 | <LazyLoad>
|
24 | 21 | <h1
|
25 | | - class="text-center font-bold text-2xl sm:text-3xl xl:text-5xl px-5 md:px-12 xl:px-24 text-primary py-5" |
| 22 | + class="text-center font-bold text-2xl sm:text-3xl xl:text-5xl px-5 md:px-12 xl:px-24 text-primary" |
26 | 23 | >
|
27 | | - {$page_views < 1 |
| 24 | + {page_views === 1 |
28 | 25 | ? "Welcome to the Svelte Netlify Demo"
|
29 | 26 | : "Welcome back!"}
|
30 | 27 | </h1>
|
31 | 28 |
|
32 | | - <div class="flex justify-center items-center px-5 sm:px-12"> |
| 29 | + <div |
| 30 | + class="flex justify-center items-center px-5 sm:px-12 bg-slate-300 my-10" |
| 31 | + > |
33 | 32 | <enhanced:img
|
34 | 33 | src={watermelon_image}
|
35 | 34 | alt="watermelon"
|
36 | | - class="h-[50vh] object-contain" |
| 35 | + class="h-[40vh] object-contain" |
37 | 36 | />
|
38 | 37 | </div>
|
39 | | - {#if $page_views > 1} |
| 38 | + {#if page_views > 1} |
40 | 39 | <h2
|
41 | | - class="text-primary px-5 sm:px-12 text-md py-5 flex items-center text-center justify-center" |
| 40 | + class="text-primary px-5 sm:px-12 text-md flex items-center text-center justify-center" |
42 | 41 | >
|
43 | | - You have visited this site {$page_views} times |
| 42 | + You have visited this site {page_views} times |
44 | 43 | </h2>
|
45 | 44 | {/if}
|
46 | 45 | </LazyLoad>
|
|
0 commit comments