typescript lol

This commit is contained in:
Ax333l 2023-02-13 17:43:12 +01:00
parent 10c3dad90f
commit ec2e8adfec
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
5 changed files with 71 additions and 45 deletions

View File

@ -1,5 +1,6 @@
import { navigating, page } from '$app/stores'; 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 { export interface RouterEvent {
// URL of the current page or the page we are navigating to. // URL of the current page or the page we are navigating to.
@ -15,17 +16,17 @@ function makeStore(): Readable<RouterEvent> {
// `location` does not exist on the server. // `location` does not exist on the server.
// Return a derived store based on `page` for SSR. // Return a derived store based on `page` for SSR.
// Server will never navigate so this is fine. // Server will never navigate so this is fine.
return derived(page, $page => { return derived(page, ($page) => {
return { navigating: false, target_url: $page.url }; return { navigating: false, target_url: $page.url };
}); });
} else { } else {
// On client. // On client.
let current = new URL(location); let current = new URL(location as any);
// Return store that responds to navigation events. // Return store that responds to navigation events.
// The `navigating` store immediately "pushes" `null`. // The `navigating` store immediately "pushes" `null`.
// This in turn causes this derived store to immediately "push" the current URL. // This in turn causes this derived store to immediately "push" the current URL.
return derived(navigating, $nav => { return derived(navigating, ($nav) => {
let navigating = false; let navigating = false;
// $nav is null when navigation finishes. // $nav is null when navigation finishes.
if ($nav != null && $nav.to != null) { if ($nav != null && $nav.to != null) {

View File

@ -5,10 +5,11 @@
import next from '$lib/assets/icons/next.svg'; import next from '$lib/assets/icons/next.svg';
import previous from '$lib/assets/icons/previous.svg'; import previous from '$lib/assets/icons/previous.svg';
import type { APILogo } from '$lib/types';
export let name = ''; export let name = '';
export let selected: Array<string>; export let selected: string[];
export let variants; export let variants: APILogo[];
export let clicked = false; export let clicked = false;
export let hideDetails = false; export let hideDetails = false;
@ -17,7 +18,7 @@
let i = 0; let i = 0;
$: current = variants[i]; $: current = variants[i];
let interval = null; let interval = 0;
onMount(() => { onMount(() => {
if (!hasVariants) { if (!hasVariants) {
return; return;
@ -28,12 +29,12 @@
} else { } else {
i += 1; i += 1;
} }
}, 2500); }, 2500) as unknown as number; // stfu typescript
return () => clearInterval(interval); return () => clearInterval(interval);
}); });
function select_logo(id) { function select_logo(id: string) {
clicked = !clicked; clicked = !clicked;
if (selected.includes(id)) { if (selected.includes(id)) {
selected = selected.filter((e) => e !== id); selected = selected.filter((e) => e !== id);

19
src/lib/types.ts Normal file
View File

@ -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 {
// }

View File

@ -1,7 +1,7 @@
import { dev } from "$app/environment"; import { dev } from '$app/environment';
// console.log, but only if in dev environment. // console.log, but only if in dev environment.
export function dev_log(part: string, ...args) { export function dev_log(part: string, ...args: string[]) {
if (dev) { if (dev) {
console.log(`[${part}]:`, ...args); console.log(`[${part}]:`, ...args);
} }

View File

@ -2,14 +2,19 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { fly } from 'svelte/transition'; import { fly } from 'svelte/transition';
import { expoOut } from 'svelte/easing'; import { expoOut } from 'svelte/easing';
import type { Logo, LogoAPIResponse } from '$lib/types';
import Modal from '$lib/components/atoms/Dialogue.svelte'; import Modal from '$lib/components/atoms/Dialogue.svelte';
import LogoOption from '$lib/components/atoms/LogoOption.svelte'; import LogoOption from '$lib/components/atoms/LogoOption.svelte';
import Button from '$lib/components/atoms/Button.svelte'; import Button from '$lib/components/atoms/Button.svelte';
interface Selected {
[key: string] : string[];
}
let modalOpen = false; let modalOpen = false;
let selected = {}; let selected: Selected = {};
function calc_ui_selected_count(v) { function calc_ui_selected_count(v: Selected) {
let n = 0; let n = 0;
for (const item of Object.values(v)) { for (const item of Object.values(v)) {
if (item.length != 0) { if (item.length != 0) {
@ -22,15 +27,15 @@
// afn please don't do this lol this is shitty code // afn please don't do this lol this is shitty code
$: ui_selected_count = calc_ui_selected_count(selected); $: ui_selected_count = calc_ui_selected_count(selected);
let logos = []; let logos: Logo[] = [];
let logo_ids = []; let logo_ids: string[] = [];
let transitionDirection = 5; let transitionDirection = 5;
let logoAmount = 4; let logoAmount = 4;
let currentPage = 0; let currentPage = 0;
let logoPages = 1; let logoPages = 1;
let min = 0; let min = 0;
let max = logoAmount; let max = logoAmount;
let token: string = ''; let token = '';
let submit = false; let submit = false;
$: finalPage = currentPage >= logoPages; $: finalPage = currentPage >= logoPages;
@ -59,7 +64,7 @@
window['submit_poll'] = submitBallot; window['submit_poll'] = submitBallot;
const response = await fetch('https://poll.revanced.app/logos'); 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)) { for (const name of Object.keys(json)) {
// lol the performance // lol the performance