Repository navigation
Expand file tree
/
Copy pathApp.vue
More file actions
76 lines (67 loc) · 2.06 KB
/
Copy pathApp.vue
File metadata and controls
76 lines (67 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<script setup lang="ts">
import { computed, ref, watch } from "vue";
type Priority = "high" | "med" | "low";
type Filter = "all" | "active" | "done";
interface Task {
id: string;
title: string;
priority: Priority;
done: boolean;
}
const STORAGE_KEY = "ff-task-tracker-v1";
const load = (): Task[] => {
try {
return JSON.parse(localStorage.getItem(STORAGE_KEY) || "[]");
} catch {
return [];
}
};
const tasks = ref<Task[]>(load());
const title = ref("");
const priority = ref<Priority>("med");
const filter = ref<Filter>("all");
watch(tasks, (val) => localStorage.setItem(STORAGE_KEY, JSON.stringify(val)), { deep: true });
const remaining = computed(() => tasks.value.filter((t) => !t.done).length);
const visible = computed(() => {
if (filter.value === "active") return tasks.value.filter((t) => !t.done);
if (filter.value === "done") return tasks.value.filter((t) => t.done);
return tasks.value;
});
function addTask() {
const clean = title.value.trim();
if (!clean) return;
tasks.value.unshift({ id: crypto.randomUUID(), title: clean, priority: priority.value, done: false });
title.value = "";
}
const remove = (id: string) => {
tasks.value = tasks.value.filter((t) => t.id !== id);
};
</script>
<template>
<main>
<h1>Sprint Tasks ({{ remaining }} open)</h1>
<form @submit.prevent="addTask">
<input v-model="title" placeholder="Add task..." />
<select v-model="priority">
<option value="high">High</option>
<option value="med">Medium</option>
<option value="low">Low</option>
</select>
<button type="submit">Add</button>
</form>
<div>
<button v-for="f in (['all', 'active', 'done'] as const)" :key="f" :aria-pressed="filter === f" @click="filter = f">
{{ f }}
</button>
</div>
<ul>
<li v-for="t in visible" :key="t.id">
<label>
<input type="checkbox" v-model="t.done" />
<span>[{{ t.priority }}] {{ t.title }}</span>
</label>
<button @click="remove(t.id)">Delete</button>
</li>
</ul>
</main>
</template>