Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit 8442bf4

Browse files
committed
Default category setting
1 parent 8a1b7cd commit 8442bf4

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

backend/main.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ type Task struct {
3434
}
3535

3636
type Category struct {
37-
ID int `json:"id"`
38-
Name string `json:"name"`
37+
ID int `json:"id"`
38+
Name string `json:"name"`
39+
IsDefault bool `json:"is_default"`
3940
}
4041

4142
type CreateTaskRequest struct {
@@ -115,7 +116,8 @@ func initDB() {
115116
schema := `
116117
CREATE TABLE IF NOT EXISTS categories (
117118
id INTEGER PRIMARY KEY AUTOINCREMENT,
118-
name TEXT NOT NULL UNIQUE
119+
name TEXT NOT NULL UNIQUE,
120+
is_default BOOLEAN NOT NULL DEFAULT 0
119121
);
120122
121123
CREATE TABLE IF NOT EXISTS tasks (
@@ -146,8 +148,14 @@ func initDB() {
146148
// Column already exists, ignore error
147149
}
148150

151+
// Add is_default column if it doesn't exist (migration for existing databases)
152+
_, err = db.Exec("ALTER TABLE categories ADD COLUMN is_default BOOLEAN NOT NULL DEFAULT 0")
153+
if err != nil {
154+
// Column already exists, ignore error
155+
}
156+
149157
// Insert default category if not exists
150-
_, err = db.Exec("INSERT OR IGNORE INTO categories (id, name) VALUES (1, 'General')")
158+
_, err = db.Exec("INSERT OR IGNORE INTO categories (id, name, is_default) VALUES (1, 'General', 1)")
151159
if err != nil {
152160
log.Fatal(err)
153161
}
@@ -159,7 +167,7 @@ func getVersion(w http.ResponseWriter, r *http.Request) {
159167
}
160168

161169
func getCategories(w http.ResponseWriter, r *http.Request) {
162-
rows, err := db.Query("SELECT id, name FROM categories ORDER BY name")
170+
rows, err := db.Query("SELECT id, name, is_default FROM categories ORDER BY name")
163171
if err != nil {
164172
http.Error(w, err.Error(), http.StatusInternalServerError)
165173
return
@@ -169,7 +177,7 @@ func getCategories(w http.ResponseWriter, r *http.Request) {
169177
categories := []Category{}
170178
for rows.Next() {
171179
var c Category
172-
if err := rows.Scan(&c.ID, &c.Name); err != nil {
180+
if err := rows.Scan(&c.ID, &c.Name, &c.IsDefault); err != nil {
173181
http.Error(w, err.Error(), http.StatusInternalServerError)
174182
return
175183
}

frontend/src/App.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
categories = await res.json();
3838
await loadTaskCounts();
3939
if (categories.length > 0 && !selectedCategory) {
40-
selectedCategory = categories[0];
40+
// Select default category or fall back to first
41+
selectedCategory = categories.find(c => c.is_default) || categories[0];
4142
await loadTasks();
4243
}
4344
}

0 commit comments

Comments
 (0)