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
43 changes: 36 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" />
<title>TaskForge — open-source task tracker</title>
<script>
(() => {
const storageKey = "taskforge.theme";
const prefersDark = window.matchMedia(
"(prefers-color-scheme: dark)",
).matches;
let theme = prefersDark ? "dark" : "light";
try {
const savedTheme = localStorage.getItem(storageKey);
if (savedTheme === "dark" || savedTheme === "light") {
theme = savedTheme;
}
} catch {
// localStorage may be unavailable in privacy-restricted contexts.
}
document.documentElement.dataset.theme = theme;
})();
</script>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
Expand All @@ -12,14 +31,24 @@
<h1>TaskForge</h1>
<p class="tagline">A tiny task list that lives in your browser.</p>
</div>
<div class="auth-panel" aria-live="polite">
<img id="auth-avatar" class="auth-avatar" hidden />
<span id="auth-status" class="auth-status">
Tasks are stored on this device.
</span>
<button id="auth-action" class="auth-action" type="button">
Sign in with GitHub
<div class="header-actions">
<button
id="theme-toggle"
class="theme-toggle"
type="button"
aria-pressed="false"
>
Dark mode
</button>
<div class="auth-panel" aria-live="polite">
<img id="auth-avatar" class="auth-avatar" hidden />
<span id="auth-status" class="auth-status">
Tasks are stored on this device.
</span>
<button id="auth-action" class="auth-action" type="button">
Sign in with GitHub
</button>
</div>
</div>
</header>

Expand Down
45 changes: 45 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ 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");
const themePreference = window.matchMedia("(prefers-color-scheme: dark)");
const themeStorageKey = "taskforge.theme";

let tasks = [];
let user = null;
Expand Down Expand Up @@ -114,6 +117,47 @@ authAction.addEventListener("click", async () => {
}
});

themeToggle.addEventListener("click", () => {
const nextTheme = getTheme() === "dark" ? "light" : "dark";
applyTheme(nextTheme);
try {
localStorage.setItem(themeStorageKey, nextTheme);
} catch {
// Keep the toggle usable even when persistence is unavailable.
}
});

themePreference.addEventListener("change", (event) => {
if (hasStoredTheme()) return;
applyTheme(event.matches ? "dark" : "light");
});

function applyTheme(theme) {
document.documentElement.dataset.theme = theme;
renderThemeToggle();
}

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

function hasStoredTheme() {
try {
const savedTheme = localStorage.getItem(themeStorageKey);
return savedTheme === "dark" || savedTheme === "light";
} catch {
return false;
}
}

function renderThemeToggle() {
const isDark = getTheme() === "dark";
const nextTheme = isDark ? "light" : "dark";
themeToggle.textContent = isDark ? "Light mode" : "Dark mode";
themeToggle.setAttribute("aria-pressed", String(isDark));
themeToggle.setAttribute("aria-label", `Switch to ${nextTheme} theme`);
}

function renderAuth() {
authAction.disabled = false;
if (!user) {
Expand Down Expand Up @@ -146,4 +190,5 @@ function mergeTasks(localTasks, remoteTasks) {
return [...byId.values()].sort((a, b) => b.createdAt - a.createdAt);
}

renderThemeToggle();
init();
70 changes: 64 additions & 6 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
:root {
color-scheme: light;
--bg: #ffffff;
--surface: #f6f8fa;
--fg: #1f2328;
--muted: #6e7781;
--border: #d0d7de;
--accent: #0969da;
--accent-fg: #ffffff;
--button-bg: #f6f8fa;
--button-hover: #eef2f6;
--done: #8c959f;
--danger: #cf222e;
--danger-bg: rgba(207, 34, 46, 0.08);
--notice-bg: #fff8c5;
--notice-border: #d4a72c;
--notice-fg: #7d4e00;
--radius: 6px;
}

:root[data-theme="dark"] {
color-scheme: dark;
--bg: #0d1117;
--surface: #161b22;
--fg: #f0f6fc;
--muted: #8b949e;
--border: #30363d;
--accent: #58a6ff;
--accent-fg: #0d1117;
--button-bg: #21262d;
--button-hover: #30363d;
--done: #8b949e;
--danger: #ff7b72;
--danger-bg: rgba(248, 81, 73, 0.12);
--notice-bg: #2d2300;
--notice-border: #9e6a03;
--notice-fg: #f2cc60;
}

* {
box-sizing: border-box;
}
Expand Down Expand Up @@ -43,6 +71,13 @@ body {
font-size: 0.95rem;
}

.header-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 0.6rem;
}

.auth-panel {
display: flex;
align-items: center;
Expand Down Expand Up @@ -75,6 +110,22 @@ body {
cursor: pointer;
}

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

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

.auth-action:disabled {
cursor: wait;
opacity: 0.7;
Expand All @@ -89,9 +140,9 @@ body {
.auth-message {
margin: 0 0 1rem;
padding: 0.6rem 0.75rem;
color: #7d4e00;
background: #fff8c5;
border: 1px solid #d4a72c;
color: var(--notice-fg);
background: var(--notice-bg);
border: 1px solid var(--notice-border);
border-radius: var(--radius);
}

Expand All @@ -106,7 +157,7 @@ body {
padding: 0.5rem 0.75rem;
font: inherit;
color: inherit;
background: var(--bg);
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
}
Expand Down Expand Up @@ -145,6 +196,7 @@ body {
align-items: center;
gap: 0.75rem;
padding: 0.6rem 0.75rem;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
}
Expand All @@ -171,8 +223,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 Expand Up @@ -204,6 +256,12 @@ body {
width: 100%;
}

.header-actions {
align-items: flex-start;
flex-direction: column;
width: 100%;
}

.auth-status {
flex: 1;
max-width: none;
Expand Down