diff options
| author | Fuwn <[email protected]> | 2023-11-19 04:50:51 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-11-19 04:50:51 -0800 |
| commit | d08a17cd88223843d6e9ee5de33d1e05a424c304 (patch) | |
| tree | beed9c12d87dce02ae976a70ba059814b41cf51a | |
| parent | deps: remove unused (diff) | |
| download | frontend-next-d08a17cd88223843d6e9ee5de33d1e05a424c304.tar.xz frontend-next-d08a17cd88223843d6e9ee5de33d1e05a424c304.zip | |
chore(typescript): add types
| -rw-r--r-- | src/lib/api.ts | 2 | ||||
| -rw-r--r-- | src/routes/+page.svelte | 8 | ||||
| -rw-r--r-- | src/routes/api/+page.svelte | 4 | ||||
| -rw-r--r-- | src/routes/language/+page.svelte | 19 | ||||
| -rw-r--r-- | src/routes/languages/+page.svelte | 4 |
5 files changed, 16 insertions, 21 deletions
diff --git a/src/lib/api.ts b/src/lib/api.ts index 080e03b..2ab78e3 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -19,7 +19,7 @@ export const baseURL = "https://api.senpy.club"; export const baseAPI = `${baseURL}/v2`; -interface RandomImage { +export interface RandomImage { language: string; image: string; } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 241d54d..8682ec2 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -15,11 +15,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. Copyright (C) 2022-2022 Fuwn <[email protected]> SPDX-License-Identifier: GPL-3.0-only --> -<script> +<script lang="ts"> import { onMount } from "svelte"; - import { fetchRandomImage } from "$lib/api"; + import { fetchRandomImage, type RandomImage } from "$lib/api"; - let image; + let image: RandomImage; let complete = false; onMount(async () => { @@ -34,7 +34,7 @@ SPDX-License-Identifier: GPL-3.0-only --> <section> {#if !complete} - <p>Fetching a random image ...</p> + <p>Fetching a random girl ...</p> {:else} <div class="highlighted-image"> <a href={`/language?language=${image.language}`}> diff --git a/src/routes/api/+page.svelte b/src/routes/api/+page.svelte index cf4e571..92d58c5 100644 --- a/src/routes/api/+page.svelte +++ b/src/routes/api/+page.svelte @@ -15,12 +15,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. Copyright (C) 2022-2022 Fuwn <[email protected]> SPDX-License-Identifier: GPL-3.0-only --> -<script> +<script lang="ts"> import { onMount } from "svelte"; import rst2html from "rst2html"; import { baseURL } from "$lib/api"; - let rst; + let rst: string; let complete = false; onMount(async () => { diff --git a/src/routes/language/+page.svelte b/src/routes/language/+page.svelte index cb1d4cf..a08952b 100644 --- a/src/routes/language/+page.svelte +++ b/src/routes/language/+page.svelte @@ -15,7 +15,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. Copyright (C) 2022-2022 Fuwn <[email protected]> SPDX-License-Identifier: GPL-3.0-only --> -<script> +<script lang="ts"> import { onMount } from "svelte"; import { fetchImages } from "$lib/api"; import { page } from "$app/stores"; @@ -34,12 +34,12 @@ SPDX-License-Identifier: GPL-3.0-only --> "https://i.imgur.com/TOgxESH.jpg", ]; - let images; + let images: any; let complete = false; - + $: language = $page.url.searchParams.get("language"); $: languageEncoded = encodeURIComponent( - $page.url.searchParams.get("language") + $page.url.searchParams.get("language") || "" ); $: imageQuery = $page.url.searchParams.get("image"); $: image = imageQuery @@ -49,19 +49,14 @@ SPDX-License-Identifier: GPL-3.0-only --> : null; onMount(async () => { - images = await fetchImages(language); + images = await fetchImages(language || ""); complete = true; if (imageQuery) { - // If the `imageQuery` is a string if (Number.isNaN(Number(imageQuery))) { - image = images.filter((i) => i.includes(imageQuery)); + image = images.filter((i: (string | null)[]) => i.includes(imageQuery)); - // Make sure that if there are no exact matches to the `imageQuery`; - // show error page - if (image[0] !== imageQuery) { - image[0] = undefined; - } + if (image[0] !== imageQuery) image[0] = undefined; if (!image[0]) { image = diff --git a/src/routes/languages/+page.svelte b/src/routes/languages/+page.svelte index bcbcbec..09e6868 100644 --- a/src/routes/languages/+page.svelte +++ b/src/routes/languages/+page.svelte @@ -15,11 +15,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. Copyright (C) 2022-2022 Fuwn <[email protected]> SPDX-License-Identifier: GPL-3.0-only --> -<script> +<script lang="ts"> import { onMount } from "svelte"; import { fetchLanguages } from "$lib/api"; - let languages; + let languages: string[]; let complete = false; onMount(async () => { |