kitgit

tirbofish/kitgit · commit

7b3a10061fad22b3233815f639275ef1ca77197a

feat: add light/dark/system theme preference

Verified

Thribhu K <4tkbytes@pm.me> · 2026-07-28 15:12

view full diff

diff --git a/migrations/012_user_theme.sql b/migrations/012_user_theme.sql
new file mode 100644
index 0000000..7b57126
--- /dev/null
+++ b/migrations/012_user_theme.sql
@@ -0,0 +1,10 @@
+-- Per-user appearance preference: light | dark | system
+
+ALTER TABLE users
+    ADD COLUMN IF NOT EXISTS theme TEXT NOT NULL DEFAULT 'system';
+
+ALTER TABLE users
+    DROP CONSTRAINT IF EXISTS users_theme_check;
+
+ALTER TABLE users
+    ADD CONSTRAINT users_theme_check CHECK (theme IN ('light', 'dark', 'system'));
diff --git a/src/db/models.rs b/src/db/models.rs
index 874e00c..f98c3f6 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -17,10 +17,21 @@ pub struct User {
     pub is_suspended: bool,
     pub show_email: bool,
     pub vigilant_mode: bool,
+    /// `light`, `dark`, or `system` (follows prefers-color-scheme).
+    pub theme: String,
     pub created_at: DateTime<Utc>,
     pub updated_at: DateTime<Utc>,
 }
 
+impl User {
+    pub fn theme_pref(&self) -> &str {
+        match self.theme.as_str() {
+            "light" | "dark" => self.theme.as_str(),
+            _ => "system",
+        }
+    }
+}
+
 #[derive(Debug, Clone, FromRow)]
 pub struct UserMfa {
     pub user_id: Uuid,
diff --git a/src/db/queries.rs b/src/db/queries.rs
index a236a11..4f67ddd 100644
--- a/src/db/queries.rs
+++ b/src/db/queries.rs
@@ -2003,6 +2003,19 @@ pub async fn update_privacy(
     .await?)
 }
 

Large diffs are not rendered by default. Showing the first 50 of 317 lines. Show full diff