Skip to content

Commit

Permalink
alr home redir nr2
Browse files Browse the repository at this point in the history
  • Loading branch information
tizu69 committed Jan 3, 2024
1 parent 4258b72 commit 0e43251
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 60 deletions.
8 changes: 2 additions & 6 deletions src/lib/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ export const userPreferencesStore = localStorageStore<{
theme: string;
lightMode: boolean;
compact: boolean;
/* 0 = first visit, 1 = second visit, 2 = unchosen but visited
4 = prefers /home, 5 = prefers /s */
visitState: number;
// lastSearched: string;
alreadyVisited: boolean;
}>('preferences', {
sortBy: 'name',
theme: 'kjspkg',
lightMode: false,
compact: false,
visitState: 0,
// lastSearched: ''
alreadyVisited: true
});
43 changes: 6 additions & 37 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,15 @@
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { userPreferencesStore } from '$lib/stores';
import { getToastStore } from '@skeletonlabs/skeleton';
import { onMount } from 'svelte';
const toastStore = getToastStore();
onMount(() => {
switch ($userPreferencesStore.visitState) {
case 0:
$userPreferencesStore.visitState = 1;
goto(base + '/home');
break;
case 1:
$userPreferencesStore.visitState = 2;
goto(base + '/home');
break;
case 2:
goto(base + '/home');
toastStore.trigger({
message: 'Do you wish to be redirected to the package list automatically?',
timeout: 30_000,
background: 'variant-filled-success',
action: {
label: 'Sure!',
response: () => setTimeout(() => ($userPreferencesStore.visitState = 5), 1)
},
callback(response) {
if (response.status == 'closed') $userPreferencesStore.visitState = 4;
}
});
break;
case 4:
goto(base + '/home');
break;
case 5:
goto(base + '/s');
break;
default:
$userPreferencesStore.visitState = 0;
goto(base + '/home');
break;
if (!$userPreferencesStore.alreadyVisited) {
userPreferencesStore.update((prev) => ({ ...prev, alreadyVisited: true }));
goto(base + '/home');
return;
}
goto(base + '/s');
});
</script>
9 changes: 0 additions & 9 deletions src/routes/home/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,3 @@
This website serves as a means to share KJSPKG packages more easily. Use the search bar above to
search for packages, or <a href="{base}/s" class="anchor">browse all packages</a>.
</p>

{#if $userPreferencesStore.visitState == 5}
<button
class="text-center anchor w-full"
on:click={() => ($userPreferencesStore.visitState = 4)}
>
If you wish to get redirected to the home page on launch instead, click here.
</button>
{/if}
8 changes: 0 additions & 8 deletions src/routes/s/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,6 @@
sortBy={$userPreferencesStore.sortBy}
compact={$userPreferencesStore.compact}
/>
{#if $userPreferencesStore.visitState == 4 && !$packageStatusStore.search.v}
<button
class="card flex items-center justify-center p-4 hover:variant-soft-success"
on:click={() => ($userPreferencesStore.visitState = 5)}
>
Changed your mind? Click to be redirected to this page on launch instead.
</button>
{/if}
</dl>
{:else if state == 'fail'}
<p>Something went wrong</p>
Expand Down

0 comments on commit 0e43251

Please sign in to comment.