From ac3b5be6351f02934eb84b836e8e943fb4d54182 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Fri, 9 Jul 2021 23:01:32 +0700 Subject: [PATCH] chore: typescript fix --- client/src/lib/form.ts | 2 +- client/src/routes/todos/[uid].json.ts | 16 -- client/src/routes/todos/_api.ts | 48 ------ client/src/routes/todos/index.json.ts | 30 ---- client/src/routes/todos/index.svelte | 222 -------------------------- client/static/robots.txt | 1 - 6 files changed, 1 insertion(+), 318 deletions(-) delete mode 100644 client/src/routes/todos/[uid].json.ts delete mode 100644 client/src/routes/todos/_api.ts delete mode 100644 client/src/routes/todos/index.json.ts delete mode 100644 client/src/routes/todos/index.svelte diff --git a/client/src/lib/form.ts b/client/src/lib/form.ts index 4dccc76..abbc575 100644 --- a/client/src/lib/form.ts +++ b/client/src/lib/form.ts @@ -12,7 +12,7 @@ export function enhance( result: (res: Response, form: HTMLFormElement) => void; } ) { - let current_token: {}; + let current_token: Record; async function handle_submit(e: Event) { const token = (current_token = {}); diff --git a/client/src/routes/todos/[uid].json.ts b/client/src/routes/todos/[uid].json.ts deleted file mode 100644 index 6b6ae81..0000000 --- a/client/src/routes/todos/[uid].json.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { api } from './_api'; -import type { RequestHandler } from '@sveltejs/kit'; -import type { Locals } from '$lib/types'; - -// PATCH /todos/:uid.json -export const patch: RequestHandler = async (request) => { - return api(request, `todos/${request.locals.userid}/${request.params.uid}`, { - text: request.body.get('text'), - done: request.body.has('done') ? !!request.body.get('done') : undefined, - }); -}; - -// DELETE /todos/:uid.json -export const del: RequestHandler = async (request) => { - return api(request, `todos/${request.locals.userid}/${request.params.uid}`); -}; diff --git a/client/src/routes/todos/_api.ts b/client/src/routes/todos/_api.ts deleted file mode 100644 index 8c3866c..0000000 --- a/client/src/routes/todos/_api.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { Request } from '@sveltejs/kit'; -import type { Locals } from '$lib/types'; - -/* - This module is used by the /todos.json and /todos/[uid].json - endpoints to make calls to api.svelte.dev, which stores todos - for each user. The leading underscore indicates that this is - a private module, _not_ an endpoint — visiting /todos/_api - will net you a 404 response. - - (The data on the todo app will expire periodically; no - guarantees are made. Don't use it to organise your life.) -*/ - -const base = 'https://api.svelte.dev'; - -export async function api(request: Request, resource: string, data?: {}) { - // user must have a cookie set - if (!request.locals.userid) { - return { status: 401 }; - } - - const res = await fetch(`${base}/${resource}`, { - method: request.method, - headers: { - 'content-type': 'application/json', - }, - body: data && JSON.stringify(data), - }); - - // if the request came from a
submission, the browser's default - // behaviour is to show the URL corresponding to the form's "action" - // attribute. in those cases, we want to redirect them back to the - // /todos page, rather than showing the response - if (res.ok && request.method !== 'GET' && request.headers.accept !== 'application/json') { - return { - status: 303, - headers: { - location: '/todos', - }, - }; - } - - return { - status: res.status, - body: await res.json(), - }; -} diff --git a/client/src/routes/todos/index.json.ts b/client/src/routes/todos/index.json.ts deleted file mode 100644 index 9aa2a33..0000000 --- a/client/src/routes/todos/index.json.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { api } from './_api'; -import type { RequestHandler } from '@sveltejs/kit'; -import type { Locals } from '$lib/types'; - -// GET /todos.json -export const get: RequestHandler = async (request) => { - // request.locals.userid comes from src/hooks.js - const response = await api(request, `todos/${request.locals.userid}`); - - if (response.status === 404) { - // user hasn't created a todo list. - // start with an empty array - return { body: [] }; - } - - return response; -}; - -// POST /todos.json -export const post: RequestHandler = async (request) => { - const response = await api(request, `todos/${request.locals.userid}`, { - // because index.svelte posts a FormData object, - // request.body is _also_ a (readonly) FormData - // object, which allows us to get form data - // with the `body.get(key)` method - text: request.body.get('text'), - }); - - return response; -}; diff --git a/client/src/routes/todos/index.svelte b/client/src/routes/todos/index.svelte deleted file mode 100644 index 6c94908..0000000 --- a/client/src/routes/todos/index.svelte +++ /dev/null @@ -1,222 +0,0 @@ - - - - - - Todos - - -
-

Todos

- - { - const created = await res.json(); - todos = [...todos, created]; - - form.reset(); - }, - }} - > - - - - {#each todos as todo (todo.uid)} -
-
{ - todo.done = !!data.get('done'); - }, - result: patch, - }} - > - -
- {/each} -
- - diff --git a/client/static/robots.txt b/client/static/robots.txt index e9e57dc..eb05362 100644 --- a/client/static/robots.txt +++ b/client/static/robots.txt @@ -1,3 +1,2 @@ -# https://www.robotstxt.org/robotstxt.html User-agent: * Disallow: