added switch for light and dark mode

This commit is contained in:
tp_dhu 2025-03-28 20:22:11 +00:00
parent 7083a55e03
commit ba3c93ba19
3 changed files with 24 additions and 1 deletions

View File

@ -46,6 +46,9 @@ POST /tag/create=TagController->create
; parsedown preview
POST /parsedown/preview=ParsedownPreview->view
; toggle-theme
POST /toggle-theme = ThemeController->toggle
; dashboard
GET /dashboard=DashboardController->index

View File

@ -0,0 +1,13 @@
<?php
class ThemeController
{
function toggle($f3)
{
$current = $f3->get('SESSION.theme') ?: 'light';
$new_theme = ($current === 'light') ? 'dark' : 'light';
$f3->set('SESSION.theme', $new_theme);
$f3->reroute($f3->get('HEADERS.Referer') ?: '/');
}
}

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html data-theme="{{ @SESSION.theme ?? 'light' }}" lang="en">
<head>
<meta charset="UTF-8">
@ -52,6 +52,13 @@
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<form id="theme-toggle-form" method="post" action="/toggle-theme" style="display:inline">
<button type="submit" id="theme-toggle-button" class="button is-small" aria-label="Toggle Theme">
<span class="icon">
<i class="fas fa-circle-half-stroke" id="theme-icon"></i>
</span>
</button>
</form>
<check if="{{ isset(@SESSION.user) }}">
<true>
<a class="button is-primary" href="/logout">Log Out</a>