Kurs Svelte i SvelteKit · Moduł 14: Hooki, API i wdrożenie
Projekt końcowy: Kroniki Wikingów
W tej lekcji4
Gratulacje! Ukończyłeś wszystkie 14 lokacji. Teraz czas na projekt końcowy!
Wymagania projektu
Zbuduj aplikację "Kroniki Wikingów" z następującymi funkcjami:
1. Autentykacja
- Rejestracja i logowanie
- Sesje z cookies
- Protected routes
2. CRUD Wojowników
- Lista wojowników
- Dodawanie nowych
- Edycja profilu
- Usuwanie
3. System wypraw
- Tworzenie wypraw
- Dołączanie wojowników
- Historia wypraw
4. Dashboard
- Statystyki
- Wykresy (używając Tween i Spring z svelte/motion)
- Real-time aktualizacje
5. Responsywność
- Mobile-first design
- Dark/light mode
Stack technologiczny
- SvelteKit 3 (start:
npx sv create kroniki-wikingow) - Svelte 5 Runes
- TypeScript
- Prisma + SQLite/PostgreSQL
- TailwindCSS
Struktura projektu
src/
├── lib/
│ ├── components/
│ ├── server/
│ │ └── db.ts
│ └── state/ # wspólny stan (runy w .svelte.js)
├── routes/
│ ├── (auth)/
│ │ ├── login/
│ │ └── register/
│ ├── (app)/
│ │ ├── dashboard/
│ │ ├── warriors/
│ │ └── expeditions/
│ └── api/
├── env.ts # deklaracje zmiennych środowiskowych
└── hooks.server.ts
vite.config.ts # SvelteKit i adapterWspólny stan (np. zalogowany wojownik) trzymaj w plikach .svelte.js w src/lib/state, a komponenty i moduły importuj przez #lib.
SKÅL!
Jarl Sven Runiczny jest z Ciebie dumny! Opanowałeś sztukę Svelte jak prawdziwy wiking opanowuje morza. Twoje umiejętności są teraz gotowe do budowy potężnych aplikacji.
Niech Twój kod będzie szybki jak drakkar, a Twoje komponenty trwałe jak mury Asgardu!
SKÅL, wojowniku!
Kod do tej lekcji: App.svelte
<script>
// Projekt końcowy - Podsumowanie
const modules = [
{ num: 1, name: 'Midgard', topic: 'Wprowadzenie do Svelte' },
{ num: 2, name: 'Yggdrasil', topic: 'Komponenty' },
{ num: 3, name: 'Komnata Run', topic: 'Reaktywność i Runes' },
{ num: 4, name: 'Asgard', topic: 'Props i Eventy' },
{ num: 5, name: 'Bifröst', topic: 'Bindings' },
{ num: 6, name: 'Norny', topic: 'Logika szablonów' },
{ num: 7, name: 'Walhalla', topic: 'Cykl życia' },
{ num: 8, name: 'Studnia Mimir', topic: 'Stores' },
{ num: 9, name: 'Ragnarök', topic: 'Animacje' },
{ num: 10, name: 'Mjölnir', topic: 'Actions' },
{ num: 11, name: 'Drakkar', topic: 'Routing' },
{ num: 12, name: 'Wölva', topic: 'SSR & Loading' },
{ num: 13, name: 'Birka', topic: 'Form Actions' },
{ num: 14, name: 'Heimdall', topic: 'Hooks & Deploy' }
];
let completed = $state(modules.map(() => false));
let allComplete = $derived(completed.every(c => c));
</script>
<main class="finale">
<h1>Kroniki Wikingów</h1>
<p class="subtitle">SKÅL! Ukończyłeś wielką podróż!</p>
<section class="journey">
<h2>Twoja podróż przez 14 lokacji</h2>
<div class="modules">
{#each modules as mod, i}
<label class="module" class:done={completed[i]}>
<input type="checkbox" bind:checked={completed[i]} />
<span class="num">{mod.num}</span>
<span class="name">{mod.name}</span>
<span class="topic">{mod.topic}</span>
</label>
{/each}
</div>
</section>
{#if allComplete}
<section class="celebration">
<h2>GRATULACJE!</h2>
<p>Opanowałeś Svelte i SvelteKit jak prawdziwy wiking opanowuje morza!</p>
<div class="badge">
<span class="icon">ᛏ</span>
<span class="title">Svelte Viking</span>
<span class="subtitle">Master of Runes</span>
</div>
</section>
{:else}
<section class="progress">
<h2>Postęp</h2>
<div class="bar">
<div
class="fill"
style="width: {(completed.filter(Boolean).length / modules.length) * 100}%"
></div>
</div>
<p>{completed.filter(Boolean).length} / {modules.length} lokacji</p>
</section>
{/if}
<section class="quote">
<blockquote>
"Niech Twój kod będzie szybki jak drakkar, a Twoje komponenty trwałe jak mury Asgardu!"
</blockquote>
<p class="author">- Jarl Sven Runiczny</p>
</section>
</main>
<style>
.finale {
font-family: 'Georgia', serif;
max-width: 600px;
margin: 0 auto;
padding: 2rem;
background: linear-gradient(135deg, #1a0f0a 0%, #2d1b0a 100%);
color: #e8d5b7;
min-height: 100vh;
}
h1 {
color: #ffd700;
text-align: center;
font-size: 2rem;
}
.subtitle {
text-align: center;
color: #d4af37;
font-size: 1.2rem;
}
section {
background: rgba(212, 175, 55, 0.1);
border: 1px solid #d4af37;
border-radius: 8px;
padding: 1rem;
margin: 1rem 0;
}
h2 {
color: #d4af37;
font-size: 1rem;
margin-top: 0;
}
.modules {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.module {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.5rem;
background: rgba(0,0,0,0.3);
border-radius: 4px;
cursor: pointer;
transition: all 0.2s;
}
.module:hover {
background: rgba(0,0,0,0.5);
}
.module.done {
background: rgba(144, 238, 144, 0.1);
}
.module input {
width: 20px;
height: 20px;
}
.num {
width: 25px;
height: 25px;
background: #d4af37;
color: #1a0f0a;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.8rem;
font-weight: bold;
}
.name {
color: #ffd700;
flex: 1;
}
.topic {
color: #8b7355;
font-size: 0.85rem;
}
.celebration {
text-align: center;
background: rgba(255, 215, 0, 0.2);
border-color: #ffd700;
}
.celebration h2 {
color: #ffd700;
font-size: 1.5rem;
}
.badge {
display: inline-flex;
flex-direction: column;
align-items: center;
padding: 1.5rem 2rem;
background: linear-gradient(135deg, #d4af37 0%, #ffd700 100%);
border-radius: 8px;
margin-top: 1rem;
}
.badge .icon {
font-size: 3rem;
}
.badge .title {
color: #1a0f0a;
font-size: 1.2rem;
font-weight: bold;
}
.badge .subtitle {
color: #3d2914;
font-size: 0.9rem;
}
.progress .bar {
height: 20px;
background: rgba(0,0,0,0.5);
border-radius: 10px;
overflow: hidden;
}
.progress .fill {
height: 100%;
background: linear-gradient(90deg, #d4af37, #ffd700);
transition: width 0.3s;
}
.progress p {
text-align: center;
margin-top: 0.5rem;
}
.quote {
text-align: center;
border-style: dashed;
}
blockquote {
font-style: italic;
color: #d4af37;
font-size: 1.1rem;
margin: 0;
}
.author {
color: #8b7355;
margin-top: 0.5rem;
}
</style>Widzisz błąd w tej lekcji?