refactor(frontend): extract types, API, helpers, and preview from +page.svelte

This commit is contained in:
2026-06-01 19:12:21 +03:00
parent b561389175
commit c1bceae5e4
8 changed files with 264 additions and 174 deletions

View File

@@ -1,26 +1,19 @@
<script lang="ts">
import { submit } from "$lib/api";
let activeTab = $state<'login' | 'register'>('login');
let username = $state('');
let password = $state('');
let error = $state('');
async function handleSubmit() {
const endpoint = activeTab === 'login' ? '/api/auth/login' : '/api/auth/register';
const res = await fetch(`http://localhost:3000${endpoint}`, {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
if (res.ok) {
try {
await submit(activeTab, username, password);
window.location.href = '/';
} else {
} catch {
error = 'Invalid credentials';
}
}
</script>
<div class="flex-1 flex items-center justify-center -mt-16">
@@ -50,7 +43,7 @@
bind:value={username}
type="text"
autocomplete="username"
class="px-4 py-2 rounded-sm !bg-[#0f1117] border border-sky-200/15 transition-colors hover:bg-black/20 hover:border-sky-200/30 text-white/80 text-sm focus:outline-none focus:border-sky-200/40"
class="px-4 py-2 rounded-sm bg-[#0f1117]! border border-sky-200/15 transition-colors hover:bg-black/20 hover:border-sky-200/30 text-white/80 text-sm focus:outline-none focus:border-sky-200/40"
/>
</div>
<div class="flex flex-col gap-1">
@@ -60,7 +53,7 @@
bind:value={password}
type="password"
autocomplete="current-password"
class="px-4 py-2 rounded-sm !bg-[#0f1117] border border-sky-200/15 transition-colors hover:bg-black/20 hover:border-sky-200/30 text-white/80 text-sm focus:outline-none focus:border-sky-200/40"
class="px-4 py-2 rounded-sm bg-[#0f1117]! border border-sky-200/15 transition-colors hover:bg-black/20 hover:border-sky-200/30 text-white/80 text-sm focus:outline-none focus:border-sky-200/40"
/>
</div>
{#if error}<p class="text-red-400/60 text-xs">{error}</p>{/if}