diff --git a/src/data/RouterEvents.ts b/src/data/RouterEvents.ts index 7e6ecdf..9706eb1 100644 --- a/src/data/RouterEvents.ts +++ b/src/data/RouterEvents.ts @@ -1,41 +1,42 @@ import { navigating, page } from '$app/stores'; -import { derived, type Readable } from 'svelte/store'; +import { derived } from 'svelte/store'; +import type { Readable } from 'svelte/store'; export interface RouterEvent { - // URL of the current page or the page we are navigating to. - target_url: URL; - // Are we navigating? - navigating: boolean; + // URL of the current page or the page we are navigating to. + target_url: URL; + // Are we navigating? + navigating: boolean; } function makeStore(): Readable { - // This stuff will run both client side and server side. + // This stuff will run both client side and server side. - if (typeof location === 'undefined') { - // `location` does not exist on the server. - // Return a derived store based on `page` for SSR. - // Server will never navigate so this is fine. - return derived(page, $page => { - return { navigating: false, target_url: $page.url }; - }); - } else { - // On client. - let current = new URL(location); + if (typeof location === 'undefined') { + // `location` does not exist on the server. + // Return a derived store based on `page` for SSR. + // Server will never navigate so this is fine. + return derived(page, ($page) => { + return { navigating: false, target_url: $page.url }; + }); + } else { + // On client. + let current = new URL(location as any); - // Return store that responds to navigation events. - // The `navigating` store immediately "pushes" `null`. - // This in turn causes this derived store to immediately "push" the current URL. - return derived(navigating, $nav => { - let navigating = false; - // $nav is null when navigation finishes. - if ($nav != null && $nav.to != null) { - current = $nav.to.url; - navigating = true; - } + // Return store that responds to navigation events. + // The `navigating` store immediately "pushes" `null`. + // This in turn causes this derived store to immediately "push" the current URL. + return derived(navigating, ($nav) => { + let navigating = false; + // $nav is null when navigation finishes. + if ($nav != null && $nav.to != null) { + current = $nav.to.url; + navigating = true; + } - return { navigating, target_url: current }; - }); - } + return { navigating, target_url: current }; + }); + } } // Do not subscribe to it outside of components! diff --git a/src/lib/components/atoms/LogoOption.svelte b/src/lib/components/atoms/LogoOption.svelte index aa9b819..da1f4db 100644 --- a/src/lib/components/atoms/LogoOption.svelte +++ b/src/lib/components/atoms/LogoOption.svelte @@ -5,10 +5,11 @@ import next from '$lib/assets/icons/next.svg'; import previous from '$lib/assets/icons/previous.svg'; + import type { APILogo } from '$lib/types'; export let name = ''; - export let selected: Array; - export let variants; + export let selected: string[]; + export let variants: APILogo[]; export let clicked = false; export let hideDetails = false; @@ -17,7 +18,7 @@ let i = 0; $: current = variants[i]; - let interval = null; + let interval = 0; onMount(() => { if (!hasVariants) { return; @@ -28,12 +29,12 @@ } else { i += 1; } - }, 2500); + }, 2500) as unknown as number; // stfu typescript return () => clearInterval(interval); }); - function select_logo(id) { + function select_logo(id: string) { clicked = !clicked; if (selected.includes(id)) { selected = selected.filter((e) => e !== id); diff --git a/src/lib/types.ts b/src/lib/types.ts new file mode 100644 index 0000000..59efd8d --- /dev/null +++ b/src/lib/types.ts @@ -0,0 +1,19 @@ +export interface APILogo { + id: string; + gdrive_direct_url: string; +} + +export interface LogoAPIResponse { + [key: string]: { + logos: APILogo[]; + }; +} + +export interface Logo { + name: string; + variants: APILogo[]; +} + +// export interface Selected { + +// } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 8ac5bb5..46a9ef0 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,8 +1,8 @@ -import { dev } from "$app/environment"; +import { dev } from '$app/environment'; // console.log, but only if in dev environment. -export function dev_log(part: string, ...args) { - if (dev) { - console.log(`[${part}]:`, ...args); - } +export function dev_log(part: string, ...args: string[]) { + if (dev) { + console.log(`[${part}]:`, ...args); + } } diff --git a/src/routes/poll/+page.svelte b/src/routes/poll/+page.svelte index f73f4ca..50ee1a2 100644 --- a/src/routes/poll/+page.svelte +++ b/src/routes/poll/+page.svelte @@ -2,14 +2,19 @@ import { onMount } from 'svelte'; import { fly } from 'svelte/transition'; import { expoOut } from 'svelte/easing'; + import type { Logo, LogoAPIResponse } from '$lib/types'; import Modal from '$lib/components/atoms/Dialogue.svelte'; import LogoOption from '$lib/components/atoms/LogoOption.svelte'; import Button from '$lib/components/atoms/Button.svelte'; + interface Selected { + [key: string] : string[]; + } + let modalOpen = false; - let selected = {}; - function calc_ui_selected_count(v) { + let selected: Selected = {}; + function calc_ui_selected_count(v: Selected) { let n = 0; for (const item of Object.values(v)) { if (item.length != 0) { @@ -22,15 +27,15 @@ // afn please don't do this lol this is shitty code $: ui_selected_count = calc_ui_selected_count(selected); - let logos = []; - let logo_ids = []; + let logos: Logo[] = []; + let logo_ids: string[] = []; let transitionDirection = 5; let logoAmount = 4; let currentPage = 0; let logoPages = 1; let min = 0; let max = logoAmount; - let token: string = ''; + let token = ''; let submit = false; $: finalPage = currentPage >= logoPages; @@ -59,7 +64,7 @@ window['submit_poll'] = submitBallot; const response = await fetch('https://poll.revanced.app/logos'); - const json = await response.json(); + const json: LogoAPIResponse = await response.json(); for (const name of Object.keys(json)) { // lol the performance