Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TaskForge — open-source task tracker</title>
<script>
(() => {
const storedTheme = window.localStorage.getItem("taskforge.theme");
const systemDark = window.matchMedia?.(
"(prefers-color-scheme: dark)",
).matches;
const theme = storedTheme || (systemDark ? "dark" : "light");
document.documentElement.dataset.theme = theme;
})();
</script>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
Expand All @@ -13,6 +23,14 @@ <h1>TaskForge</h1>
<p class="tagline">A tiny task list that lives in your browser.</p>
</div>
<div class="auth-panel" aria-live="polite">
<button
id="theme-toggle"
class="theme-toggle"
type="button"
aria-label="Switch to dark theme"
>
Dark
</button>
<img id="auth-avatar" class="auth-avatar" hidden />
<span id="auth-status" class="auth-status">
Tasks are stored on this device.
Expand Down
3 changes: 3 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "./auth.js";
import { load, loadLocal, save } from "./storage.js";
import { createTask, toggleTask, removeTask } from "./tasks.js";
import { initTheme } from "./theme.js";

const form = document.getElementById("task-form");
const input = document.getElementById("task-input");
Expand All @@ -15,11 +16,13 @@ const authStatus = document.getElementById("auth-status");
const authAction = document.getElementById("auth-action");
const authAvatar = document.getElementById("auth-avatar");
const authMessage = document.getElementById("auth-message");
const themeToggle = document.getElementById("theme-toggle");

let tasks = [];
let user = null;

async function init() {
initTheme(themeToggle);
const localTasks = loadLocal();
let completedSignIn = false;
try {
Expand Down
38 changes: 38 additions & 0 deletions src/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const THEME_KEY = "taskforge.theme";
const DARK_QUERY = "(prefers-color-scheme: dark)";

export function initTheme(toggleButton) {
const mediaQuery = window.matchMedia?.(DARK_QUERY);

applyTheme(getPreferredTheme(mediaQuery), toggleButton);

toggleButton?.addEventListener("click", () => {
const nextTheme = currentTheme() === "dark" ? "light" : "dark";
window.localStorage.setItem(THEME_KEY, nextTheme);
applyTheme(nextTheme, toggleButton);
});

mediaQuery?.addEventListener("change", (event) => {
if (window.localStorage.getItem(THEME_KEY)) return;
applyTheme(event.matches ? "dark" : "light", toggleButton);
});
}

function getPreferredTheme(mediaQuery) {
const storedTheme = window.localStorage.getItem(THEME_KEY);
if (storedTheme === "dark" || storedTheme === "light") return storedTheme;
return mediaQuery?.matches ? "dark" : "light";
}

function currentTheme() {
return document.documentElement.dataset.theme === "dark" ? "dark" : "light";
}

function applyTheme(theme, toggleButton) {
document.documentElement.dataset.theme = theme;
if (!toggleButton) return;

const nextTheme = theme === "dark" ? "light" : "dark";
toggleButton.textContent = nextTheme === "dark" ? "Dark" : "Light";
toggleButton.setAttribute("aria-label", `Switch to ${nextTheme} theme`);
}
47 changes: 42 additions & 5 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,29 @@
--accent: #0969da;
--accent-fg: #ffffff;
--done: #8c959f;
--message-bg: #fff8c5;
--message-border: #d4a72c;
--message-fg: #7d4e00;
--danger: #cf222e;
--danger-bg: rgba(207, 34, 46, 0.08);
--radius: 6px;
color-scheme: light;
}

:root[data-theme="dark"] {
--bg: #0d1117;
--fg: #e6edf3;
--muted: #8b949e;
--border: #30363d;
--accent: #2f81f7;
--accent-fg: #ffffff;
--done: #6e7681;
--message-bg: #332701;
--message-border: #9e6a03;
--message-fg: #f0c36a;
--danger: #ff7b72;
--danger-bg: rgba(248, 81, 73, 0.14);
color-scheme: dark;
}

* {
Expand Down Expand Up @@ -80,6 +102,21 @@ body {
opacity: 0.7;
}

.theme-toggle {
flex: 0 0 auto;
padding: 0.45rem 0.75rem;
font: inherit;
color: var(--fg);
background: var(--bg);
border: 1px solid var(--border);
border-radius: var(--radius);
cursor: pointer;
}

.theme-toggle:hover {
border-color: var(--accent);
}

.app-main {
max-width: 36rem;
margin: 0 auto;
Expand All @@ -89,9 +126,9 @@ body {
.auth-message {
margin: 0 0 1rem;
padding: 0.6rem 0.75rem;
color: #7d4e00;
background: #fff8c5;
border: 1px solid #d4a72c;
color: var(--message-fg);
background: var(--message-bg);
border: 1px solid var(--message-border);
border-radius: var(--radius);
}

Expand Down Expand Up @@ -171,8 +208,8 @@ body {
}

.task-delete:hover {
color: #cf222e;
background: rgba(207, 34, 46, 0.08);
color: var(--danger);
background: var(--danger-bg);
}

.empty-state {
Expand Down