From 42860fa15985401825d8d51e73ec497fe5876710 Mon Sep 17 00:00:00 2001 From: Melonai Date: Wed, 24 Mar 2021 09:51:36 +0100 Subject: Update SvelteKit to public beta --- client/src/actions/shorten.ts | 50 ------------------ client/src/components/Form.svelte | 64 ----------------------- client/src/components/Response.svelte | 33 ------------ client/src/components/Responses.svelte | 24 --------- client/src/components/Title.svelte | 22 -------- client/src/components/icons/ArrowIcon.svelte | 10 ---- client/src/components/icons/CrossIcon.svelte | 10 ---- client/src/data/links.ts | 17 ------ client/src/global.d.ts | 3 ++ client/src/globals.d.ts | 39 -------------- client/src/lib/actions/shorten.ts | 50 ++++++++++++++++++ client/src/lib/components/Form.svelte | 64 +++++++++++++++++++++++ client/src/lib/components/Response.svelte | 33 ++++++++++++ client/src/lib/components/Responses.svelte | 24 +++++++++ client/src/lib/components/Title.svelte | 22 ++++++++ client/src/lib/components/icons/ArrowIcon.svelte | 10 ++++ client/src/lib/components/icons/CrossIcon.svelte | 10 ++++ client/src/lib/data/links.ts | 18 +++++++ client/src/lib/utils/addProtocol.ts | 6 +++ client/src/lib/utils/checkUrl.ts | 10 ++++ client/src/lib/utils/debounce.ts | 12 +++++ client/src/routes/index.svelte | 66 ++++++++++++------------ client/src/utils/addProtocol.ts | 6 --- client/src/utils/checkUrl.ts | 10 ---- client/src/utils/debounce.ts | 12 ----- 25 files changed, 295 insertions(+), 330 deletions(-) delete mode 100644 client/src/actions/shorten.ts delete mode 100644 client/src/components/Form.svelte delete mode 100644 client/src/components/Response.svelte delete mode 100644 client/src/components/Responses.svelte delete mode 100644 client/src/components/Title.svelte delete mode 100644 client/src/components/icons/ArrowIcon.svelte delete mode 100644 client/src/components/icons/CrossIcon.svelte delete mode 100644 client/src/data/links.ts create mode 100644 client/src/global.d.ts delete mode 100644 client/src/globals.d.ts create mode 100644 client/src/lib/actions/shorten.ts create mode 100644 client/src/lib/components/Form.svelte create mode 100644 client/src/lib/components/Response.svelte create mode 100644 client/src/lib/components/Responses.svelte create mode 100644 client/src/lib/components/Title.svelte create mode 100644 client/src/lib/components/icons/ArrowIcon.svelte create mode 100644 client/src/lib/components/icons/CrossIcon.svelte create mode 100644 client/src/lib/data/links.ts create mode 100644 client/src/lib/utils/addProtocol.ts create mode 100644 client/src/lib/utils/checkUrl.ts create mode 100644 client/src/lib/utils/debounce.ts delete mode 100644 client/src/utils/addProtocol.ts delete mode 100644 client/src/utils/checkUrl.ts delete mode 100644 client/src/utils/debounce.ts (limited to 'client/src') diff --git a/client/src/actions/shorten.ts b/client/src/actions/shorten.ts deleted file mode 100644 index ca685c5..0000000 --- a/client/src/actions/shorten.ts +++ /dev/null @@ -1,50 +0,0 @@ -interface ShortenResponse { - hash: string; -} - -export interface ShortenRequest { - url: string; - nonce: string; - response: Promise; -} - -async function makeRequest(url: string): Promise { - let body; - - try { - const response = await fetch("/", { - headers: { - Accept: "application/json", - "Content-Type": "application/json", - }, - method: "post", - body: JSON.stringify({ url }), - }); - - body = await response.json(); - } catch (err) { - throw { - error: "Error!", - }; - } - - if (body.hash) { - return { - hash: body.hash, - }; - } else { - throw { - message: body.error || "Error!", - }; - } -} - -export default function shorten(url: string): ShortenRequest { - const nonce = Math.random().toString(36).substr(2, 5); - - return { - url, - nonce, - response: makeRequest(url), - }; -} diff --git a/client/src/components/Form.svelte b/client/src/components/Form.svelte deleted file mode 100644 index 327d25d..0000000 --- a/client/src/components/Form.svelte +++ /dev/null @@ -1,64 +0,0 @@ - - - - -
- - -
diff --git a/client/src/components/Response.svelte b/client/src/components/Response.svelte deleted file mode 100644 index 215af1b..0000000 --- a/client/src/components/Response.svelte +++ /dev/null @@ -1,33 +0,0 @@ - - - - -
- {info.url} - {#await info.response} - Loading... - {:then { hash }} - sho.rest/{hash} - {:catch { error }} - {error} - {/await} -
\ No newline at end of file diff --git a/client/src/components/Responses.svelte b/client/src/components/Responses.svelte deleted file mode 100644 index 7124f1e..0000000 --- a/client/src/components/Responses.svelte +++ /dev/null @@ -1,24 +0,0 @@ - - - - -
    - {#each $links as info (info.nonce)} -
  • - -
  • - {/each} -
\ No newline at end of file diff --git a/client/src/components/Title.svelte b/client/src/components/Title.svelte deleted file mode 100644 index 4266eb1..0000000 --- a/client/src/components/Title.svelte +++ /dev/null @@ -1,22 +0,0 @@ - - -
- -
-

sho.rest

-

Made with ❤ by Mel

-
-
diff --git a/client/src/components/icons/ArrowIcon.svelte b/client/src/components/icons/ArrowIcon.svelte deleted file mode 100644 index 52c79ae..0000000 --- a/client/src/components/icons/ArrowIcon.svelte +++ /dev/null @@ -1,10 +0,0 @@ - - - - - \ No newline at end of file diff --git a/client/src/components/icons/CrossIcon.svelte b/client/src/components/icons/CrossIcon.svelte deleted file mode 100644 index 55525d8..0000000 --- a/client/src/components/icons/CrossIcon.svelte +++ /dev/null @@ -1,10 +0,0 @@ - - - - - \ No newline at end of file diff --git a/client/src/data/links.ts b/client/src/data/links.ts deleted file mode 100644 index 3ccf100..0000000 --- a/client/src/data/links.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { ShortenRequest } from "$actions/shorten"; -import { Writable, writable } from "svelte/store"; - -function createLinks() { - const { subscribe, update }: Writable = writable([]); - - function add(request: ShortenRequest) { - update((l) => [request, ...l.slice(0, 2)]); - } - - return { - subscribe, - add, - }; -} - -export const links = createLinks(); diff --git a/client/src/global.d.ts b/client/src/global.d.ts new file mode 100644 index 0000000..79d7d7f --- /dev/null +++ b/client/src/global.d.ts @@ -0,0 +1,3 @@ +/// +/// +/// diff --git a/client/src/globals.d.ts b/client/src/globals.d.ts deleted file mode 100644 index 06d88b7..0000000 --- a/client/src/globals.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/// - -//#region Ensure Svelte file endings have a type for TypeScript -declare module '*.svelte' { - export { SvelteComponent as default } from 'svelte'; -} -//#endregion - -//#region Ensure image file endings have a type for TypeScript -declare module "*.gif" { - const value: string; - export = value; -} - -declare module "*.jpg" { - const value: string; - export = value; -} - -declare module "*.jpeg" { - const value: string; - export = value; -} - -declare module "*.png" { - const value: string; - export = value; -} - -declare module "*.svg" { - const value: string; - export = value; -} - -declare module "*.webp" { - const value: string; - export = value; -} -//#endregion diff --git a/client/src/lib/actions/shorten.ts b/client/src/lib/actions/shorten.ts new file mode 100644 index 0000000..ca685c5 --- /dev/null +++ b/client/src/lib/actions/shorten.ts @@ -0,0 +1,50 @@ +interface ShortenResponse { + hash: string; +} + +export interface ShortenRequest { + url: string; + nonce: string; + response: Promise; +} + +async function makeRequest(url: string): Promise { + let body; + + try { + const response = await fetch("/", { + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + method: "post", + body: JSON.stringify({ url }), + }); + + body = await response.json(); + } catch (err) { + throw { + error: "Error!", + }; + } + + if (body.hash) { + return { + hash: body.hash, + }; + } else { + throw { + message: body.error || "Error!", + }; + } +} + +export default function shorten(url: string): ShortenRequest { + const nonce = Math.random().toString(36).substr(2, 5); + + return { + url, + nonce, + response: makeRequest(url), + }; +} diff --git a/client/src/lib/components/Form.svelte b/client/src/lib/components/Form.svelte new file mode 100644 index 0000000..a05e868 --- /dev/null +++ b/client/src/lib/components/Form.svelte @@ -0,0 +1,64 @@ + + + + +
+ + +
diff --git a/client/src/lib/components/Response.svelte b/client/src/lib/components/Response.svelte new file mode 100644 index 0000000..0ed8cc9 --- /dev/null +++ b/client/src/lib/components/Response.svelte @@ -0,0 +1,33 @@ + + + + +
+ {info.url} + {#await info.response} + Loading... + {:then { hash }} + sho.rest/{hash} + {:catch { error }} + {error} + {/await} +
\ No newline at end of file diff --git a/client/src/lib/components/Responses.svelte b/client/src/lib/components/Responses.svelte new file mode 100644 index 0000000..6e83658 --- /dev/null +++ b/client/src/lib/components/Responses.svelte @@ -0,0 +1,24 @@ + + + + +
    + {#each $links as info (info.nonce)} +
  • + +
  • + {/each} +
\ No newline at end of file diff --git a/client/src/lib/components/Title.svelte b/client/src/lib/components/Title.svelte new file mode 100644 index 0000000..4266eb1 --- /dev/null +++ b/client/src/lib/components/Title.svelte @@ -0,0 +1,22 @@ + + +
+ +
+

sho.rest

+

Made with ❤ by Mel

+
+
diff --git a/client/src/lib/components/icons/ArrowIcon.svelte b/client/src/lib/components/icons/ArrowIcon.svelte new file mode 100644 index 0000000..52c79ae --- /dev/null +++ b/client/src/lib/components/icons/ArrowIcon.svelte @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/client/src/lib/components/icons/CrossIcon.svelte b/client/src/lib/components/icons/CrossIcon.svelte new file mode 100644 index 0000000..55525d8 --- /dev/null +++ b/client/src/lib/components/icons/CrossIcon.svelte @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/client/src/lib/data/links.ts b/client/src/lib/data/links.ts new file mode 100644 index 0000000..0f0a9ce --- /dev/null +++ b/client/src/lib/data/links.ts @@ -0,0 +1,18 @@ +import type { ShortenRequest } from "$lib/actions/shorten"; +import type { Writable } from "svelte/store"; +import { writable } from "svelte/store"; + +function createLinks() { + const { subscribe, update }: Writable = writable([]); + + function add(request: ShortenRequest) { + update((l) => [request, ...l.slice(0, 2)]); + } + + return { + subscribe, + add, + }; +} + +export const links = createLinks(); diff --git a/client/src/lib/utils/addProtocol.ts b/client/src/lib/utils/addProtocol.ts new file mode 100644 index 0000000..75c6214 --- /dev/null +++ b/client/src/lib/utils/addProtocol.ts @@ -0,0 +1,6 @@ +export default function (url: string) { + if (!/^https?:\/\//.test(url)) { + url = "https://" + url; + } + return url; +} diff --git a/client/src/lib/utils/checkUrl.ts b/client/src/lib/utils/checkUrl.ts new file mode 100644 index 0000000..8ed747f --- /dev/null +++ b/client/src/lib/utils/checkUrl.ts @@ -0,0 +1,10 @@ +import addProtocol from "./addProtocol"; + +export default function (url: string): string | null { + try { + const normalizedUrl = new URL(addProtocol(url)); + return normalizedUrl.toString(); + } catch (e) { + return null; + } +} \ No newline at end of file diff --git a/client/src/lib/utils/debounce.ts b/client/src/lib/utils/debounce.ts new file mode 100644 index 0000000..86ef3db --- /dev/null +++ b/client/src/lib/utils/debounce.ts @@ -0,0 +1,12 @@ +type Procedure = (...args: any[]) => any; + +export default function (f: F, duration: number) { + let timeout: ReturnType | null = null; + return function (...args: Parameters) { + if (timeout !== null) { + clearTimeout(timeout); + timeout = null; + } + timeout = setTimeout(() => f(...args), duration); + }; +} diff --git a/client/src/routes/index.svelte b/client/src/routes/index.svelte index 5e51f13..965d169 100644 --- a/client/src/routes/index.svelte +++ b/client/src/routes/index.svelte @@ -1,44 +1,44 @@
-
- - <Form/> - <div class="output"> - <Responses/> - </div> - </div> + <div class="content"> + <Title/> + <Form/> + <div class="output"> + <Responses/> + </div> + </div> </main> \ No newline at end of file diff --git a/client/src/utils/addProtocol.ts b/client/src/utils/addProtocol.ts deleted file mode 100644 index 75c6214..0000000 --- a/client/src/utils/addProtocol.ts +++ /dev/null @@ -1,6 +0,0 @@ -export default function (url: string) { - if (!/^https?:\/\//.test(url)) { - url = "https://" + url; - } - return url; -} diff --git a/client/src/utils/checkUrl.ts b/client/src/utils/checkUrl.ts deleted file mode 100644 index 8ed747f..0000000 --- a/client/src/utils/checkUrl.ts +++ /dev/null @@ -1,10 +0,0 @@ -import addProtocol from "./addProtocol"; - -export default function (url: string): string | null { - try { - const normalizedUrl = new URL(addProtocol(url)); - return normalizedUrl.toString(); - } catch (e) { - return null; - } -} \ No newline at end of file diff --git a/client/src/utils/debounce.ts b/client/src/utils/debounce.ts deleted file mode 100644 index 86ef3db..0000000 --- a/client/src/utils/debounce.ts +++ /dev/null @@ -1,12 +0,0 @@ -type Procedure = (...args: any[]) => any; - -export default function <F extends Procedure>(f: F, duration: number) { - let timeout: ReturnType<typeof setTimeout> | null = null; - return function (...args: Parameters<F>) { - if (timeout !== null) { - clearTimeout(timeout); - timeout = null; - } - timeout = setTimeout(() => f(...args), duration); - }; -} -- cgit 1.4.1