Initial commit: YesChef family shopping list and recipe app
Backend (.NET 10 minimal API): - Vertical slice architecture with feature folders - Postgres via EF Core with initial migration - JWT auth with family invite code registration - REST endpoints for stores, shopping lists, items, recipes - SignalR hub for real-time list collaboration (per-list groups and lists-overview group for live list creation/archival/progress) - Multi-stage Dockerfile Frontend (SvelteKit + Svelte 5 runes, Tailwind v4): - Mobile-first PWA with web manifest and service worker - Bottom-nav layout, login/register, lists overview, list detail, stores management, recipes (list/create/detail with add-to-list) - SignalR client with reference-counted connection - Real-time updates on both lists overview and list detail pages Infrastructure: - docker-compose.yml with postgres, backend, frontend services and Traefik labels for path-based routing (/api, /hubs to backend) - .env.example with required config End-to-end tests (Playwright): - test-e2e.mjs: single-user flow (auth, stores, lists, items, recipes) - test-e2e-multiuser.mjs: two-user real-time sync coverage Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
node_modules
|
||||
|
||||
# Output
|
||||
.output
|
||||
.vercel
|
||||
.netlify
|
||||
.wrangler
|
||||
/.svelte-kit
|
||||
/build
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.test
|
||||
|
||||
# Vite
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
@@ -0,0 +1 @@
|
||||
engine-strict=true
|
||||
@@ -0,0 +1,15 @@
|
||||
FROM node:22-slim AS build
|
||||
WORKDIR /app
|
||||
COPY package*.json .
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
FROM node:22-slim
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/build .
|
||||
COPY --from=build /app/package.json .
|
||||
RUN npm ci --omit=dev
|
||||
EXPOSE 3000
|
||||
ENV PORT=3000
|
||||
CMD ["node", "index.js"]
|
||||
@@ -0,0 +1,42 @@
|
||||
# sv
|
||||
|
||||
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
|
||||
|
||||
## Creating a project
|
||||
|
||||
If you're seeing this, you've probably already done this step. Congrats!
|
||||
|
||||
```sh
|
||||
# create a new project
|
||||
npx sv create my-app
|
||||
```
|
||||
|
||||
To recreate this project with the same configuration:
|
||||
|
||||
```sh
|
||||
# recreate this project
|
||||
npx sv@0.15.2 create --template minimal --types ts --no-install src/frontend
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
To create a production version of your app:
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
||||
Generated
+2388
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^7.0.1",
|
||||
"@sveltejs/kit": "^2.57.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
||||
"svelte": "^5.55.2",
|
||||
"svelte-check": "^4.4.6",
|
||||
"typescript": "^6.0.2",
|
||||
"vite": "^8.0.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/signalr": "^10.0.0",
|
||||
"@sveltejs/adapter-node": "^5.5.4",
|
||||
"@tailwindcss/vite": "^4.2.4",
|
||||
"tailwindcss": "^4.2.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
@import 'tailwindcss';
|
||||
|
||||
@theme {
|
||||
--color-primary: #16a34a;
|
||||
--color-primary-dark: #15803d;
|
||||
--color-primary-light: #22c55e;
|
||||
--color-danger: #dc2626;
|
||||
--color-danger-dark: #b91c1c;
|
||||
}
|
||||
|
||||
html {
|
||||
font-family:
|
||||
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-gray-50 text-gray-900;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
button {
|
||||
@apply cursor-pointer;
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// See https://svelte.dev/docs/kit/types#app.d.ts
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#16a34a" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
||||
<link rel="apple-touch-icon" href="/icons/icon-192.png" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,48 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { setLoggedIn } from '$lib/auth.svelte';
|
||||
|
||||
let token: string | null = null;
|
||||
|
||||
export function getToken(): string | null {
|
||||
if (token === null && typeof localStorage !== 'undefined') {
|
||||
token = localStorage.getItem('token');
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
export function setToken(t: string) {
|
||||
token = t;
|
||||
localStorage.setItem('token', t);
|
||||
setLoggedIn(true);
|
||||
}
|
||||
|
||||
export function clearToken() {
|
||||
token = null;
|
||||
localStorage.removeItem('token');
|
||||
setLoggedIn(false);
|
||||
}
|
||||
|
||||
export async function api<T>(path: string, options: RequestInit = {}): Promise<T> {
|
||||
const t = getToken();
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers as Record<string, string>)
|
||||
};
|
||||
if (t) headers['Authorization'] = `Bearer ${t}`;
|
||||
|
||||
const res = await fetch(path, { ...options, headers });
|
||||
|
||||
if (res.status === 401) {
|
||||
clearToken();
|
||||
goto('/login');
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.error || `Request failed: ${res.status}`);
|
||||
}
|
||||
|
||||
if (res.status === 204) return undefined as T;
|
||||
return res.json();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.157 22.819c-10.4-14.885-30.94-19.297-45.792-9.835L22.282 29.608A29.92 29.92 0 0 0 8.764 49.65a31.5 31.5 0 0 0 3.108 20.231 30 30 0 0 0-4.477 11.183 31.9 31.9 0 0 0 5.448 24.116c10.402 14.887 30.942 19.297 45.791 9.835l26.083-16.624A29.92 29.92 0 0 0 98.235 78.35a31.53 31.53 0 0 0-3.105-20.232 30 30 0 0 0 4.474-11.182 31.88 31.88 0 0 0-5.447-24.116" style="fill:#ff3e00"/><path d="M45.817 106.582a20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.503 18 18 0 0 1 .624-2.435l.49-1.498 1.337.981a33.6 33.6 0 0 0 10.203 5.098l.97.294-.09.968a5.85 5.85 0 0 0 1.052 3.878 6.24 6.24 0 0 0 6.695 2.485 5.8 5.8 0 0 0 1.603-.704L69.27 76.28a5.43 5.43 0 0 0 2.45-3.631 5.8 5.8 0 0 0-.987-4.371 6.24 6.24 0 0 0-6.698-2.487 5.7 5.7 0 0 0-1.6.704l-9.953 6.345a19 19 0 0 1-5.296 2.326 20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.502 17.99 17.99 0 0 1 8.13-12.052l26.081-16.623a19 19 0 0 1 5.3-2.329 20.72 20.72 0 0 1 22.237 8.243 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-.624 2.435l-.49 1.498-1.337-.98a33.6 33.6 0 0 0-10.203-5.1l-.97-.294.09-.968a5.86 5.86 0 0 0-1.052-3.878 6.24 6.24 0 0 0-6.696-2.485 5.8 5.8 0 0 0-1.602.704L37.73 51.72a5.42 5.42 0 0 0-2.449 3.63 5.79 5.79 0 0 0 .986 4.372 6.24 6.24 0 0 0 6.698 2.486 5.8 5.8 0 0 0 1.602-.704l9.952-6.342a19 19 0 0 1 5.295-2.328 20.72 20.72 0 0 1 22.237 8.242 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-8.13 12.053l-26.081 16.622a19 19 0 0 1-5.3 2.328" style="fill:#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,15 @@
|
||||
let loggedIn = $state(false);
|
||||
|
||||
export function initAuth() {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
loggedIn = !!localStorage.getItem('token');
|
||||
}
|
||||
}
|
||||
|
||||
export function setLoggedIn(value: boolean) {
|
||||
loggedIn = value;
|
||||
}
|
||||
|
||||
export function isLoggedIn() {
|
||||
return loggedIn;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
||||
@@ -0,0 +1,37 @@
|
||||
import { HubConnectionBuilder, HubConnectionState, type HubConnection } from '@microsoft/signalr';
|
||||
import { getToken } from './api';
|
||||
|
||||
let connection: HubConnection | null = null;
|
||||
let refCount = 0;
|
||||
|
||||
function getConnection(): HubConnection {
|
||||
if (connection && connection.state !== HubConnectionState.Disconnected) {
|
||||
return connection;
|
||||
}
|
||||
|
||||
connection = new HubConnectionBuilder()
|
||||
.withUrl('/hubs/shopping-list', {
|
||||
accessTokenFactory: () => getToken() ?? ''
|
||||
})
|
||||
.withAutomaticReconnect([0, 1000, 5000, 10000, 30000])
|
||||
.build();
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
export async function startConnection(): Promise<HubConnection> {
|
||||
const conn = getConnection();
|
||||
if (conn.state === HubConnectionState.Disconnected) {
|
||||
await conn.start();
|
||||
}
|
||||
refCount++;
|
||||
return conn;
|
||||
}
|
||||
|
||||
export async function stopConnection() {
|
||||
refCount--;
|
||||
if (refCount <= 0 && connection && connection.state !== HubConnectionState.Disconnected) {
|
||||
refCount = 0;
|
||||
await connection.stop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<script lang="ts">
|
||||
import '../app.css';
|
||||
import { page } from '$app/state';
|
||||
import { clearToken } from '$lib/api';
|
||||
import { initAuth, isLoggedIn } from '$lib/auth.svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
onMount(() => initAuth());
|
||||
|
||||
const loggedIn = $derived(isLoggedIn());
|
||||
const currentPath = $derived(page.url.pathname);
|
||||
|
||||
const navItems = [
|
||||
{ href: '/lists', label: 'Lists', icon: '📋' },
|
||||
{ href: '/recipes', label: 'Recipes', icon: '📖' },
|
||||
{ href: '/stores', label: 'Stores', icon: '🏪' }
|
||||
];
|
||||
|
||||
function logout() {
|
||||
clearToken();
|
||||
goto('/login');
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if loggedIn && currentPath !== '/login'}
|
||||
<div class="flex min-h-dvh flex-col pb-16">
|
||||
<header class="sticky top-0 z-40 border-b border-gray-200 bg-white px-4 py-3">
|
||||
<div class="mx-auto flex max-w-lg items-center justify-between">
|
||||
<h1 class="text-xl font-bold text-primary">YesChef</h1>
|
||||
<button onclick={logout} class="text-sm text-gray-500">Sign out</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="mx-auto w-full max-w-lg flex-1 px-4 py-4">
|
||||
{@render children()}
|
||||
</main>
|
||||
|
||||
<nav class="fixed bottom-0 left-0 right-0 z-50 border-t border-gray-200 bg-white safe-bottom">
|
||||
<div class="mx-auto flex max-w-lg justify-around">
|
||||
{#each navItems as item}
|
||||
<a
|
||||
href={item.href}
|
||||
class="flex flex-1 flex-col items-center py-2 text-xs transition-colors {currentPath.startsWith(
|
||||
item.href
|
||||
)
|
||||
? 'text-primary font-semibold'
|
||||
: 'text-gray-500'}"
|
||||
>
|
||||
<span class="text-xl">{item.icon}</span>
|
||||
<span class="mt-0.5">{item.label}</span>
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
{:else}
|
||||
{@render children()}
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.safe-bottom {
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { getToken } from '$lib/api';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
onMount(() => {
|
||||
if (getToken()) {
|
||||
goto('/lists');
|
||||
} else {
|
||||
goto('/login');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,151 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { api } from '$lib/api';
|
||||
import { startConnection, stopConnection } from '$lib/signalr';
|
||||
import type { HubConnection } from '@microsoft/signalr';
|
||||
|
||||
interface ListSummary {
|
||||
id: number;
|
||||
name: string;
|
||||
store: { id: number; name: string };
|
||||
itemCount: number;
|
||||
checkedCount: number;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
interface Store {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
let lists = $state<ListSummary[]>([]);
|
||||
let stores = $state<Store[]>([]);
|
||||
let showCreate = $state(false);
|
||||
let newName = $state('');
|
||||
let newStoreId = $state<number | null>(null);
|
||||
let loading = $state(true);
|
||||
let connection: HubConnection | null = null;
|
||||
|
||||
onMount(async () => {
|
||||
[lists, stores] = await Promise.all([
|
||||
api<ListSummary[]>('/api/lists'),
|
||||
api<Store[]>('/api/stores')
|
||||
]);
|
||||
loading = false;
|
||||
|
||||
connection = await startConnection();
|
||||
await connection.invoke('JoinListsOverview');
|
||||
|
||||
connection.on('ListCreated', (data: ListSummary) => {
|
||||
if (!lists.find((l) => l.id === data.id)) {
|
||||
lists = [data, ...lists];
|
||||
}
|
||||
});
|
||||
|
||||
connection.on('ListArchived', (data: { id: number }) => {
|
||||
lists = lists.filter((l) => l.id !== data.id);
|
||||
});
|
||||
|
||||
connection.on('ListSummaryUpdated', (data: ListSummary) => {
|
||||
lists = lists.map((l) =>
|
||||
l.id === data.id ? { ...l, itemCount: data.itemCount, checkedCount: data.checkedCount, updatedAt: data.updatedAt } : l
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
onDestroy(async () => {
|
||||
if (connection) {
|
||||
try { await connection.invoke('LeaveListsOverview'); } catch {}
|
||||
}
|
||||
await stopConnection();
|
||||
});
|
||||
|
||||
async function createList() {
|
||||
if (!newName.trim() || !newStoreId) return;
|
||||
await api<{ id: number }>('/api/lists', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ name: newName, storeId: newStoreId })
|
||||
});
|
||||
newName = '';
|
||||
showCreate = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h2 class="text-2xl font-bold">Shopping Lists</h2>
|
||||
<button
|
||||
onclick={() => (showCreate = !showCreate)}
|
||||
class="rounded-full bg-primary px-4 py-2 text-sm font-semibold text-white"
|
||||
>
|
||||
{showCreate ? 'Cancel' : '+ New list'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if showCreate}
|
||||
<form onsubmit={e => { e.preventDefault(); createList(); }} class="mb-4 rounded-lg border border-gray-200 bg-white p-4 shadow-sm">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={newName}
|
||||
placeholder="List name"
|
||||
required
|
||||
class="mb-3 w-full rounded-lg border border-gray-300 px-3 py-2 focus:border-primary focus:outline-none"
|
||||
/>
|
||||
<select
|
||||
bind:value={newStoreId}
|
||||
required
|
||||
class="mb-3 w-full rounded-lg border border-gray-300 px-3 py-2 focus:border-primary focus:outline-none"
|
||||
>
|
||||
<option value={null} disabled>Select store</option>
|
||||
{#each stores as store}
|
||||
<option value={store.id}>{store.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full rounded-lg bg-primary py-2 font-semibold text-white"
|
||||
>
|
||||
Create
|
||||
</button>
|
||||
</form>
|
||||
{/if}
|
||||
|
||||
{#if loading}
|
||||
<p class="py-8 text-center text-gray-400">Loading...</p>
|
||||
{:else if lists.length === 0}
|
||||
<div class="py-12 text-center">
|
||||
<p class="text-lg text-gray-400">No shopping lists yet</p>
|
||||
<p class="mt-1 text-sm text-gray-400">Create one to get started</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="space-y-3">
|
||||
{#each lists as list (list.id)}
|
||||
<a
|
||||
href="/lists/{list.id}"
|
||||
class="block rounded-lg border border-gray-200 bg-white p-4 shadow-sm transition-shadow active:shadow-md"
|
||||
>
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 class="font-semibold">{list.name}</h3>
|
||||
<p class="mt-0.5 text-sm text-gray-500">{list.store.name}</p>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<p class="text-sm font-medium">
|
||||
{list.checkedCount}/{list.itemCount}
|
||||
</p>
|
||||
<p class="text-xs text-gray-400">items</p>
|
||||
</div>
|
||||
</div>
|
||||
{#if list.itemCount > 0}
|
||||
<div class="mt-2 h-1.5 overflow-hidden rounded-full bg-gray-100">
|
||||
<div
|
||||
class="h-full rounded-full bg-primary transition-all"
|
||||
style="width: {(list.checkedCount / list.itemCount) * 100}%"
|
||||
></div>
|
||||
</div>
|
||||
{/if}
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,207 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { page } from '$app/state';
|
||||
import { goto } from '$app/navigation';
|
||||
import { api } from '$lib/api';
|
||||
import { startConnection, stopConnection } from '$lib/signalr';
|
||||
import type { HubConnection } from '@microsoft/signalr';
|
||||
|
||||
interface ListItem {
|
||||
id: number;
|
||||
name: string;
|
||||
isChecked: boolean;
|
||||
checkedByUserName: string | null;
|
||||
sortOrder: number;
|
||||
recipeTitle: string | null;
|
||||
}
|
||||
|
||||
interface ShoppingListDetail {
|
||||
id: number;
|
||||
name: string;
|
||||
store: { id: number; name: string };
|
||||
isArchived: boolean;
|
||||
items: ListItem[];
|
||||
}
|
||||
|
||||
let list = $state<ShoppingListDetail | null>(null);
|
||||
let items = $state<ListItem[]>([]);
|
||||
let newItemName = $state('');
|
||||
let loading = $state(true);
|
||||
let connection: HubConnection | null = null;
|
||||
|
||||
const listId = $derived(Number(page.params.id));
|
||||
const uncheckedItems = $derived(items.filter((i) => !i.isChecked));
|
||||
const checkedItems = $derived(items.filter((i) => i.isChecked));
|
||||
|
||||
onMount(async () => {
|
||||
const data = await api<ShoppingListDetail>(`/api/lists/${listId}`);
|
||||
list = data;
|
||||
items = data.items;
|
||||
loading = false;
|
||||
|
||||
connection = await startConnection();
|
||||
await connection.invoke('JoinList', listId);
|
||||
|
||||
connection.on('ItemAdded', (data: { id: number; name: string; sortOrder: number; recipeTitle?: string }) => {
|
||||
if (!items.find((i) => i.id === data.id)) {
|
||||
items = [
|
||||
...items,
|
||||
{
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
isChecked: false,
|
||||
checkedByUserName: null,
|
||||
sortOrder: data.sortOrder,
|
||||
recipeTitle: data.recipeTitle ?? null
|
||||
}
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
connection.on('ItemChecked', (data: { id: number; isChecked: boolean; checkedByUserName: string | null }) => {
|
||||
items = items.map((i) =>
|
||||
i.id === data.id
|
||||
? { ...i, isChecked: data.isChecked, checkedByUserName: data.checkedByUserName }
|
||||
: i
|
||||
);
|
||||
});
|
||||
|
||||
connection.on('ItemRemoved', (data: { id: number }) => {
|
||||
items = items.filter((i) => i.id !== data.id);
|
||||
});
|
||||
|
||||
connection.on('ListUpdated', (data: { id: number; name: string; storeId: number }) => {
|
||||
if (list) list = { ...list, name: data.name };
|
||||
});
|
||||
});
|
||||
|
||||
onDestroy(async () => {
|
||||
if (connection) {
|
||||
try {
|
||||
await connection.invoke('LeaveList', listId);
|
||||
} catch {}
|
||||
}
|
||||
await stopConnection();
|
||||
});
|
||||
|
||||
async function addItem() {
|
||||
if (!newItemName.trim()) return;
|
||||
const maxSort = items.length > 0 ? Math.max(...items.map((i) => i.sortOrder)) : 0;
|
||||
await api('/api/lists/' + listId + '/items', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ name: newItemName, sortOrder: maxSort + 1 })
|
||||
});
|
||||
newItemName = '';
|
||||
}
|
||||
|
||||
async function toggleItem(itemId: number) {
|
||||
await api(`/api/lists/${listId}/items/${itemId}/check`, { method: 'PATCH' });
|
||||
}
|
||||
|
||||
async function removeItem(itemId: number) {
|
||||
await api(`/api/lists/${listId}/items/${itemId}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
async function archiveList() {
|
||||
await api(`/api/lists/${listId}`, { method: 'DELETE' });
|
||||
goto('/lists');
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if loading}
|
||||
<p class="py-8 text-center text-gray-400">Loading...</p>
|
||||
{:else if list}
|
||||
<div>
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<div>
|
||||
<button onclick={() => goto('/lists')} class="text-sm text-gray-500">← Back</button>
|
||||
<h2 class="text-2xl font-bold">{list.name}</h2>
|
||||
<p class="text-sm text-gray-500">{list.store.name}</p>
|
||||
</div>
|
||||
<button
|
||||
onclick={archiveList}
|
||||
class="rounded-lg border border-gray-300 px-3 py-1.5 text-sm text-gray-500"
|
||||
>
|
||||
Archive
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form onsubmit={e => { e.preventDefault(); addItem(); }} class="mb-4 flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={newItemName}
|
||||
placeholder="Add an item..."
|
||||
class="flex-1 rounded-lg border border-gray-300 px-3 py-2.5 text-base focus:border-primary focus:outline-none"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
class="rounded-lg bg-primary px-4 py-2.5 font-semibold text-white"
|
||||
>
|
||||
Add
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{#if uncheckedItems.length > 0}
|
||||
<ul class="space-y-1">
|
||||
{#each uncheckedItems as item (item.id)}
|
||||
<li class="flex items-center gap-3 rounded-lg bg-white px-3 py-3 shadow-sm">
|
||||
<button
|
||||
onclick={() => toggleItem(item.id)}
|
||||
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full border-2 border-gray-300"
|
||||
aria-label="Check {item.name}"
|
||||
></button>
|
||||
<div class="min-w-0 flex-1">
|
||||
<span class="text-base">{item.name}</span>
|
||||
{#if item.recipeTitle}
|
||||
<span class="ml-1 text-xs text-gray-400">from {item.recipeTitle}</span>
|
||||
{/if}
|
||||
</div>
|
||||
<button
|
||||
onclick={() => removeItem(item.id)}
|
||||
class="shrink-0 p-1 text-gray-300 active:text-danger"
|
||||
aria-label="Remove {item.name}"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{:else if checkedItems.length === 0}
|
||||
<p class="py-8 text-center text-gray-400">No items yet — add some above</p>
|
||||
{/if}
|
||||
|
||||
{#if checkedItems.length > 0}
|
||||
<div class="mt-6">
|
||||
<h3 class="mb-2 text-sm font-medium text-gray-400">
|
||||
Checked ({checkedItems.length})
|
||||
</h3>
|
||||
<ul class="space-y-1">
|
||||
{#each checkedItems as item (item.id)}
|
||||
<li class="flex items-center gap-3 rounded-lg bg-white/60 px-3 py-3 shadow-sm">
|
||||
<button
|
||||
onclick={() => toggleItem(item.id)}
|
||||
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full border-2 border-primary bg-primary text-white"
|
||||
aria-label="Uncheck {item.name}"
|
||||
>
|
||||
✓
|
||||
</button>
|
||||
<div class="min-w-0 flex-1">
|
||||
<span class="text-base text-gray-400 line-through">{item.name}</span>
|
||||
{#if item.checkedByUserName}
|
||||
<span class="ml-1 text-xs text-gray-300">{item.checkedByUserName}</span>
|
||||
{/if}
|
||||
</div>
|
||||
<button
|
||||
onclick={() => removeItem(item.id)}
|
||||
class="shrink-0 p-1 text-gray-300 active:text-danger"
|
||||
aria-label="Remove {item.name}"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,104 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { api, setToken } from '$lib/api';
|
||||
|
||||
let mode = $state<'login' | 'register'>('login');
|
||||
let name = $state('');
|
||||
let password = $state('');
|
||||
let familyCode = $state('');
|
||||
let error = $state('');
|
||||
let loading = $state(false);
|
||||
|
||||
async function handleSubmit() {
|
||||
error = '';
|
||||
loading = true;
|
||||
try {
|
||||
const endpoint = mode === 'login' ? '/api/auth/login' : '/api/auth/register';
|
||||
const body =
|
||||
mode === 'login'
|
||||
? { name, password }
|
||||
: { name, password, familyCode };
|
||||
|
||||
const res = await api<{ token: string }>(endpoint, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
|
||||
setToken(res.token);
|
||||
goto('/lists');
|
||||
} catch (e: any) {
|
||||
error = e.message || 'Something went wrong';
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex min-h-dvh items-center justify-center bg-gray-50 px-4">
|
||||
<div class="w-full max-w-sm">
|
||||
<div class="mb-8 text-center">
|
||||
<h1 class="text-4xl font-bold text-primary">YesChef</h1>
|
||||
<p class="mt-2 text-gray-500">Family shopping & recipes</p>
|
||||
</div>
|
||||
|
||||
<form onsubmit={e => { e.preventDefault(); handleSubmit(); }} class="space-y-4">
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
bind:value={name}
|
||||
placeholder="Name"
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 px-4 py-3 text-lg focus:border-primary focus:ring-2 focus:ring-primary/20 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input
|
||||
type="password"
|
||||
bind:value={password}
|
||||
placeholder="Password"
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 px-4 py-3 text-lg focus:border-primary focus:ring-2 focus:ring-primary/20 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if mode === 'register'}
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
bind:value={familyCode}
|
||||
placeholder="Family code"
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 px-4 py-3 text-lg focus:border-primary focus:ring-2 focus:ring-primary/20 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<p class="text-sm text-danger">{error}</p>
|
||||
{/if}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
class="w-full rounded-lg bg-primary py-3 text-lg font-semibold text-white transition-colors hover:bg-primary-dark disabled:opacity-50"
|
||||
>
|
||||
{loading ? '...' : mode === 'login' ? 'Sign in' : 'Create account'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="mt-6 text-center text-sm text-gray-500">
|
||||
{#if mode === 'login'}
|
||||
New here?
|
||||
<button onclick={() => (mode = 'register')} class="font-medium text-primary">
|
||||
Create account
|
||||
</button>
|
||||
{:else}
|
||||
Already have an account?
|
||||
<button onclick={() => (mode = 'login')} class="font-medium text-primary">
|
||||
Sign in
|
||||
</button>
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,72 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
interface RecipeSummary {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
servings: number | null;
|
||||
ingredientCount: number;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
let recipes = $state<RecipeSummary[]>([]);
|
||||
let search = $state('');
|
||||
let loading = $state(true);
|
||||
|
||||
const filtered = $derived(
|
||||
search.trim()
|
||||
? recipes.filter((r) => r.title.toLowerCase().includes(search.toLowerCase()))
|
||||
: recipes
|
||||
);
|
||||
|
||||
onMount(async () => {
|
||||
recipes = await api<RecipeSummary[]>('/api/recipes');
|
||||
loading = false;
|
||||
});
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h2 class="text-2xl font-bold">Recipes</h2>
|
||||
<a href="/recipes/new" class="rounded-full bg-primary px-4 py-2 text-sm font-semibold text-white">
|
||||
+ New recipe
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<input
|
||||
type="search"
|
||||
bind:value={search}
|
||||
placeholder="Search recipes..."
|
||||
class="mb-4 w-full rounded-lg border border-gray-300 px-3 py-2.5 focus:border-primary focus:outline-none"
|
||||
/>
|
||||
|
||||
{#if loading}
|
||||
<p class="py-8 text-center text-gray-400">Loading...</p>
|
||||
{:else if filtered.length === 0}
|
||||
<p class="py-12 text-center text-gray-400">
|
||||
{search ? 'No recipes match your search' : 'No recipes yet — add one above'}
|
||||
</p>
|
||||
{:else}
|
||||
<div class="space-y-3">
|
||||
{#each filtered as recipe (recipe.id)}
|
||||
<a
|
||||
href="/recipes/{recipe.id}"
|
||||
class="block rounded-lg border border-gray-200 bg-white p-4 shadow-sm active:shadow-md"
|
||||
>
|
||||
<h3 class="font-semibold">{recipe.title}</h3>
|
||||
{#if recipe.description}
|
||||
<p class="mt-0.5 line-clamp-2 text-sm text-gray-500">{recipe.description}</p>
|
||||
{/if}
|
||||
<div class="mt-2 flex gap-3 text-xs text-gray-400">
|
||||
<span>{recipe.ingredientCount} ingredients</span>
|
||||
{#if recipe.servings}
|
||||
<span>Serves {recipe.servings}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,148 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/state';
|
||||
import { goto } from '$app/navigation';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
interface Ingredient {
|
||||
id: number;
|
||||
name: string;
|
||||
quantity: string | null;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
interface Recipe {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
instructions: string | null;
|
||||
servings: number | null;
|
||||
sourceUrl: string | null;
|
||||
createdBy: string;
|
||||
ingredients: Ingredient[];
|
||||
}
|
||||
|
||||
interface ListSummary {
|
||||
id: number;
|
||||
name: string;
|
||||
store: { id: number; name: string };
|
||||
}
|
||||
|
||||
let recipe = $state<Recipe | null>(null);
|
||||
let lists = $state<ListSummary[]>([]);
|
||||
let loading = $state(true);
|
||||
let showAddToList = $state(false);
|
||||
let addingToList = $state<number | null>(null);
|
||||
|
||||
const recipeId = $derived(Number(page.params.id));
|
||||
|
||||
onMount(async () => {
|
||||
[recipe, lists] = await Promise.all([
|
||||
api<Recipe>(`/api/recipes/${recipeId}`),
|
||||
api<ListSummary[]>('/api/lists')
|
||||
]);
|
||||
loading = false;
|
||||
});
|
||||
|
||||
async function addToList(listId: number) {
|
||||
addingToList = listId;
|
||||
try {
|
||||
await api(`/api/lists/${listId}/add-recipe/${recipeId}`, { method: 'POST' });
|
||||
showAddToList = false;
|
||||
goto(`/lists/${listId}`);
|
||||
} finally {
|
||||
addingToList = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteRecipe() {
|
||||
if (!confirm('Delete this recipe?')) return;
|
||||
await api(`/api/recipes/${recipeId}`, { method: 'DELETE' });
|
||||
goto('/recipes');
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if loading}
|
||||
<p class="py-8 text-center text-gray-400">Loading...</p>
|
||||
{:else if recipe}
|
||||
<div>
|
||||
<button onclick={() => goto('/recipes')} class="mb-2 text-sm text-gray-500">← Back</button>
|
||||
|
||||
<div class="mb-4 flex items-start justify-between">
|
||||
<div>
|
||||
<h2 class="text-2xl font-bold">{recipe.title}</h2>
|
||||
{#if recipe.description}
|
||||
<p class="mt-1 text-gray-500">{recipe.description}</p>
|
||||
{/if}
|
||||
<div class="mt-2 flex gap-3 text-sm text-gray-400">
|
||||
{#if recipe.servings}
|
||||
<span>Serves {recipe.servings}</span>
|
||||
{/if}
|
||||
<span>By {recipe.createdBy}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4 flex gap-2">
|
||||
<button
|
||||
onclick={() => (showAddToList = !showAddToList)}
|
||||
class="flex-1 rounded-lg bg-primary py-2.5 font-semibold text-white"
|
||||
>
|
||||
Add to list
|
||||
</button>
|
||||
<button
|
||||
onclick={deleteRecipe}
|
||||
class="rounded-lg border border-danger px-4 py-2.5 text-sm text-danger"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if showAddToList}
|
||||
<div class="mb-4 rounded-lg border border-gray-200 bg-white p-3 shadow-sm">
|
||||
<p class="mb-2 text-sm font-medium text-gray-600">Choose a list:</p>
|
||||
{#if lists.length === 0}
|
||||
<p class="text-sm text-gray-400">No active lists. Create one first.</p>
|
||||
{:else}
|
||||
<div class="space-y-1">
|
||||
{#each lists as list}
|
||||
<button
|
||||
onclick={() => addToList(list.id)}
|
||||
disabled={addingToList === list.id}
|
||||
class="w-full rounded-lg px-3 py-2 text-left transition-colors hover:bg-gray-50 active:bg-gray-100"
|
||||
>
|
||||
<span class="font-medium">{list.name}</span>
|
||||
<span class="ml-1 text-sm text-gray-400">{list.store.name}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if recipe.ingredients.length > 0}
|
||||
<div class="mb-6">
|
||||
<h3 class="mb-2 text-lg font-semibold">Ingredients</h3>
|
||||
<ul class="space-y-1.5">
|
||||
{#each recipe.ingredients as ingredient}
|
||||
<li class="flex gap-2 rounded-lg bg-white px-3 py-2 shadow-sm">
|
||||
{#if ingredient.quantity}
|
||||
<span class="font-medium text-primary">{ingredient.quantity}</span>
|
||||
{/if}
|
||||
<span>{ingredient.name}</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if recipe.instructions}
|
||||
<div>
|
||||
<h3 class="mb-2 text-lg font-semibold">Instructions</h3>
|
||||
<div class="whitespace-pre-wrap rounded-lg bg-white p-4 text-gray-700 shadow-sm">
|
||||
{recipe.instructions}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,128 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
let title = $state('');
|
||||
let description = $state('');
|
||||
let instructions = $state('');
|
||||
let servings = $state<number | undefined>();
|
||||
let ingredients = $state<{ name: string; quantity: string }[]>([{ name: '', quantity: '' }]);
|
||||
let saving = $state(false);
|
||||
|
||||
function addIngredient() {
|
||||
ingredients = [...ingredients, { name: '', quantity: '' }];
|
||||
}
|
||||
|
||||
function removeIngredient(idx: number) {
|
||||
ingredients = ingredients.filter((_, i) => i !== idx);
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!title.trim()) return;
|
||||
saving = true;
|
||||
try {
|
||||
const res = await api<{ id: number }>('/api/recipes', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
title,
|
||||
description: description || null,
|
||||
instructions: instructions || null,
|
||||
servings: servings || null,
|
||||
sourceUrl: null,
|
||||
ingredients: ingredients
|
||||
.filter((i) => i.name.trim())
|
||||
.map((i, idx) => ({ name: i.name, quantity: i.quantity || null, sortOrder: idx }))
|
||||
})
|
||||
});
|
||||
goto(`/recipes/${res.id}`);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<button onclick={() => goto('/recipes')} class="mb-2 text-sm text-gray-500">← Back</button>
|
||||
<h2 class="mb-4 text-2xl font-bold">New Recipe</h2>
|
||||
|
||||
<form onsubmit={e => { e.preventDefault(); save(); }} class="space-y-4">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={title}
|
||||
placeholder="Recipe title"
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 px-3 py-2.5 text-lg focus:border-primary focus:outline-none"
|
||||
/>
|
||||
|
||||
<textarea
|
||||
bind:value={description}
|
||||
placeholder="Short description (optional)"
|
||||
rows={2}
|
||||
class="w-full rounded-lg border border-gray-300 px-3 py-2.5 focus:border-primary focus:outline-none"
|
||||
></textarea>
|
||||
|
||||
<div>
|
||||
<label class="mb-1 block text-sm font-medium text-gray-600">
|
||||
Servings
|
||||
<input
|
||||
type="number"
|
||||
bind:value={servings}
|
||||
min={1}
|
||||
placeholder="e.g. 4"
|
||||
class="mt-1 block w-24 rounded-lg border border-gray-300 px-3 py-2 focus:border-primary focus:outline-none"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="mb-2 block text-sm font-medium text-gray-600">Ingredients</span>
|
||||
{#each ingredients as ingredient, idx}
|
||||
<div class="mb-2 flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={ingredient.quantity}
|
||||
placeholder="Qty"
|
||||
class="w-20 rounded-lg border border-gray-300 px-2 py-2 text-sm focus:border-primary focus:outline-none"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
bind:value={ingredient.name}
|
||||
placeholder="Ingredient name"
|
||||
class="flex-1 rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-primary focus:outline-none"
|
||||
/>
|
||||
{#if ingredients.length > 1}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => removeIngredient(idx)}
|
||||
class="px-2 text-gray-300 active:text-danger"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
<button
|
||||
type="button"
|
||||
onclick={addIngredient}
|
||||
class="mt-1 text-sm font-medium text-primary"
|
||||
>
|
||||
+ Add ingredient
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
bind:value={instructions}
|
||||
placeholder="Instructions (optional)"
|
||||
rows={6}
|
||||
class="w-full rounded-lg border border-gray-300 px-3 py-2.5 focus:border-primary focus:outline-none"
|
||||
></textarea>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
class="w-full rounded-lg bg-primary py-3 font-semibold text-white disabled:opacity-50"
|
||||
>
|
||||
{saving ? 'Saving...' : 'Save Recipe'}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,101 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
interface Store {
|
||||
id: number;
|
||||
name: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
let stores = $state<Store[]>([]);
|
||||
let newName = $state('');
|
||||
let editingId = $state<number | null>(null);
|
||||
let editName = $state('');
|
||||
let loading = $state(true);
|
||||
|
||||
onMount(async () => {
|
||||
stores = await api<Store[]>('/api/stores');
|
||||
loading = false;
|
||||
});
|
||||
|
||||
async function addStore() {
|
||||
if (!newName.trim()) return;
|
||||
await api('/api/stores', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ name: newName, sortOrder: stores.length })
|
||||
});
|
||||
newName = '';
|
||||
stores = await api<Store[]>('/api/stores');
|
||||
}
|
||||
|
||||
function startEdit(store: Store) {
|
||||
editingId = store.id;
|
||||
editName = store.name;
|
||||
}
|
||||
|
||||
async function saveEdit() {
|
||||
if (!editName.trim() || !editingId) return;
|
||||
const store = stores.find((s) => s.id === editingId)!;
|
||||
await api(`/api/stores/${editingId}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ name: editName, sortOrder: store.sortOrder })
|
||||
});
|
||||
editingId = null;
|
||||
stores = await api<Store[]>('/api/stores');
|
||||
}
|
||||
|
||||
async function deleteStore(id: number) {
|
||||
try {
|
||||
await api(`/api/stores/${id}`, { method: 'DELETE' });
|
||||
stores = stores.filter((s) => s.id !== id);
|
||||
} catch (e: any) {
|
||||
alert(e.message);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<h2 class="mb-4 text-2xl font-bold">Stores</h2>
|
||||
|
||||
<form onsubmit={e => { e.preventDefault(); addStore(); }} class="mb-6 flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={newName}
|
||||
placeholder="New store name"
|
||||
required
|
||||
class="flex-1 rounded-lg border border-gray-300 px-3 py-2.5 focus:border-primary focus:outline-none"
|
||||
/>
|
||||
<button type="submit" class="rounded-lg bg-primary px-4 py-2.5 font-semibold text-white">
|
||||
Add
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{#if loading}
|
||||
<p class="py-8 text-center text-gray-400">Loading...</p>
|
||||
{:else if stores.length === 0}
|
||||
<p class="py-12 text-center text-gray-400">No stores yet — add one above</p>
|
||||
{:else}
|
||||
<ul class="space-y-2">
|
||||
{#each stores as store (store.id)}
|
||||
<li class="flex items-center gap-3 rounded-lg bg-white px-4 py-3 shadow-sm">
|
||||
{#if editingId === store.id}
|
||||
<form onsubmit={e => { e.preventDefault(); saveEdit(); }} class="flex flex-1 gap-2">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={editName}
|
||||
class="flex-1 rounded border border-gray-300 px-2 py-1 focus:border-primary focus:outline-none"
|
||||
/>
|
||||
<button type="submit" class="text-sm font-medium text-primary">Save</button>
|
||||
<button type="button" onclick={() => (editingId = null)} class="text-sm text-gray-400">Cancel</button>
|
||||
</form>
|
||||
{:else}
|
||||
<span class="flex-1 font-medium">{store.name}</span>
|
||||
<button onclick={() => startEdit(store)} class="text-sm text-gray-400">Edit</button>
|
||||
<button onclick={() => deleteStore(store.id)} class="text-sm text-danger">Delete</button>
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
/// <reference types="@sveltejs/kit" />
|
||||
/// <reference no-default-lib="true"/>
|
||||
/// <reference lib="esnext" />
|
||||
/// <reference lib="webworker" />
|
||||
|
||||
import { build, files, version } from '$service-worker';
|
||||
|
||||
const sw = self as unknown as ServiceWorkerGlobalScope;
|
||||
const CACHE = `cache-${version}`;
|
||||
const ASSETS = [...build, ...files];
|
||||
|
||||
sw.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches
|
||||
.open(CACHE)
|
||||
.then((cache) => cache.addAll(ASSETS))
|
||||
.then(() => sw.skipWaiting())
|
||||
);
|
||||
});
|
||||
|
||||
sw.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then(async (keys) => {
|
||||
for (const key of keys) {
|
||||
if (key !== CACHE) await caches.delete(key);
|
||||
}
|
||||
await sw.clients.claim();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
sw.addEventListener('fetch', (event) => {
|
||||
if (event.request.method !== 'GET') return;
|
||||
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
// Don't cache API or SignalR requests
|
||||
if (url.pathname.startsWith('/api/') || url.pathname.startsWith('/hubs/')) return;
|
||||
|
||||
event.respondWith(
|
||||
caches.match(event.request).then((cached) => {
|
||||
return cached || fetch(event.request);
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
||||
<rect width="64" height="64" rx="12" fill="#16a34a"/>
|
||||
<text x="32" y="44" font-size="36" text-anchor="middle" fill="white" font-family="sans-serif" font-weight="bold">Y</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 248 B |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "YesChef",
|
||||
"short_name": "YesChef",
|
||||
"start_url": "/lists",
|
||||
"display": "standalone",
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#16a34a",
|
||||
"icons": [
|
||||
{ "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png" },
|
||||
{ "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# allow crawling everything by default
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -0,0 +1,16 @@
|
||||
import adapter from '@sveltejs/adapter-node';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
compilerOptions: {
|
||||
runes: ({ filename }) => (filename.split(/[/\\]/).includes('node_modules') ? undefined : true)
|
||||
},
|
||||
kit: {
|
||||
adapter: adapter({ out: 'build' }),
|
||||
alias: {
|
||||
$lib: 'src/lib'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rewriteRelativeImportExtensions": true,
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler"
|
||||
}
|
||||
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
|
||||
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
|
||||
//
|
||||
// To make changes to top-level options such as include and exclude, we recommend extending
|
||||
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [tailwindcss(), sveltekit()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': 'http://localhost:5291',
|
||||
'/hubs': {
|
||||
target: 'http://localhost:5291',
|
||||
ws: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user