Rework the lists view: form below list, drop description, add count

HomeView now shows a "You have N lists." summary above the list, moves the
new-list form beneath the list, and drops the description input (title only).
lists store createList() loses its description parameter.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-03 18:48:48 +01:00
co-authored by Claude Sonnet 5
parent bc1142b929
commit dd2ab5b7d3
3 changed files with 55 additions and 45 deletions
+2 -2
View File
@@ -23,11 +23,11 @@ export const useListsStore = defineStore('lists', () => {
} }
} }
async function createList(title: string, description: string): Promise<TodoList> { async function createList(title: string): Promise<TodoList> {
const { list } = await apiRequest<{ list: TodoList }>('/lists', { const { list } = await apiRequest<{ list: TodoList }>('/lists', {
method: 'POST', method: 'POST',
auth: true, auth: true,
body: { title, description }, body: { title },
}) })
// Re-fetch so the new list lands in its correct alphabetical position. // Re-fetch so the new list lands in its correct alphabetical position.
+6
View File
@@ -148,6 +148,12 @@ h1 {
margin: 1.25rem 0; margin: 1.25rem 0;
} }
.form--new-list {
margin-top: 1.5rem;
padding-top: 1.25rem;
border-top: 1px solid var(--border);
}
.form label { .form label {
display: grid; display: grid;
gap: 0.3rem; gap: 0.3rem;
+47 -43
View File
@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from 'vue' import { computed, onMounted, ref } from 'vue'
import { ApiError } from '../lib/api' import { ApiError } from '../lib/api'
import { useAuthStore } from '../stores/auth' import { useAuthStore } from '../stores/auth'
import { MAX_LISTS, useListsStore } from '../stores/lists' import { MAX_LISTS, useListsStore } from '../stores/lists'
@@ -10,10 +10,15 @@ const lists = useListsStore()
const loadError = ref<string | null>(null) const loadError = ref<string | null>(null)
const title = ref('') const title = ref('')
const description = ref('')
const createError = ref<ApiError | null>(null) const createError = ref<ApiError | null>(null)
const submitting = ref(false) const submitting = ref(false)
const atLimit = computed(() => lists.lists.length >= MAX_LISTS)
const summary = computed(() => {
const n = lists.lists.length
return `You have ${n} ${n === 1 ? 'list' : 'lists'}.`
})
onMounted(load) onMounted(load)
async function load() { async function load() {
@@ -29,9 +34,8 @@ async function onCreate() {
submitting.value = true submitting.value = true
createError.value = null createError.value = null
try { try {
await lists.createList(title.value, description.value) await lists.createList(title.value)
title.value = '' title.value = ''
description.value = ''
} catch (e) { } catch (e) {
createError.value = e instanceof ApiError ? e : new ApiError('Could not create the list.', 0) createError.value = e instanceof ApiError ? e : new ApiError('Could not create the list.', 0)
} finally { } finally {
@@ -49,47 +53,47 @@ async function onCreate() {
verified yet. verified yet.
</div> </div>
<form class="form" @submit.prevent="onCreate">
<label>
<span>New list title</span>
<input v-model="title" type="text" maxlength="255" required :disabled="lists.lists.length >= MAX_LISTS" />
<small v-if="createError?.fieldError('title')" class="field-error">
{{ createError.fieldError('title') }}
</small>
</label>
<label>
<span>Description <span class="hint">(optional)</span></span>
<input v-model="description" type="text" maxlength="2000" :disabled="lists.lists.length >= MAX_LISTS" />
</label>
<p v-if="createError && Object.keys(createError.details).length === 0" class="form-error">
{{ createError.message }}
</p>
<button type="submit" :disabled="submitting || lists.lists.length >= MAX_LISTS">
{{ submitting ? 'Creating…' : 'Create list' }}
</button>
<p v-if="lists.lists.length >= MAX_LISTS" class="hint">
You have reached the maximum of {{ MAX_LISTS }} lists.
</p>
</form>
<p v-if="loadError" class="form-error">{{ loadError }}</p> <p v-if="loadError" class="form-error">{{ loadError }}</p>
<p v-else-if="lists.loading && !lists.loaded" class="muted">Loading</p> <p v-else-if="lists.loading && !lists.loaded" class="muted">Loading</p>
<p v-else-if="lists.lists.length === 0" class="muted">
No lists yet create your first one above.
</p>
<ul v-else class="lists"> <template v-else>
<li v-for="list in lists.lists" :key="list.id" class="lists__item"> <p class="muted">{{ summary }}</p>
<div class="lists__head">
<span class="lists__title">{{ list.title }}</span> <p v-if="lists.lists.length === 0" class="muted">
<span class="badge">{{ list.completed_count }} / {{ list.item_count }} done</span> No lists yet create your first one below.
</div> </p>
<p v-if="list.description" class="muted">{{ list.description }}</p>
</li> <ul v-else class="lists">
</ul> <li v-for="list in lists.lists" :key="list.id" class="lists__item">
<div class="lists__head">
<span class="lists__title">{{ list.title }}</span>
<span class="badge">{{ list.completed_count }} / {{ list.item_count }} done</span>
</div>
<p v-if="list.description" class="muted">{{ list.description }}</p>
</li>
</ul>
<form class="form form--new-list" @submit.prevent="onCreate">
<label>
<span>New list title</span>
<input v-model="title" type="text" maxlength="255" required :disabled="atLimit" />
<small v-if="createError?.fieldError('title')" class="field-error">
{{ createError.fieldError('title') }}
</small>
</label>
<p v-if="createError && Object.keys(createError.details).length === 0" class="form-error">
{{ createError.message }}
</p>
<button type="submit" :disabled="submitting || atLimit">
{{ submitting ? 'Creating…' : 'Create list' }}
</button>
<p v-if="atLimit" class="hint">
You have reached the maximum of {{ MAX_LISTS }} lists.
</p>
</form>
</template>
</section> </section>
</template> </template>