Add theme toggle and admin nav link, update styles

Introduced a dark/light theme toggle with persistent user preference using localStorage. Updated base template to use Bootstrap's theme system, adjusted body background class, and added a conditional 'Food Items' nav link for admins. Simplified scan page header text.
This commit is contained in:
2025-06-29 09:11:20 +02:00
parent a39f54dbb0
commit cfff4b15d0
2 changed files with 27 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="UTF-8">
@@ -10,8 +10,7 @@
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<body class="bg-body-secondary">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
<div class="container-fluid">
<a class="navbar-brand" href="{{ url_for('index') }}">Iman was here</a>
@@ -24,6 +23,11 @@
<li class="nav-item">
<a class="nav-link" href="{{ url_for('scan') }}">Scan</a>
</li>
{% if current_user.is_admin %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('admin.food_items') }}">Food Items</a>
</li>
{% endif %}
</ul>
<ul class="navbar-nav ms-auto">
{% if current_user.is_authenticated %}
@@ -35,12 +39,10 @@
<li class="nav-item">
<a class="nav-link" href="{{ url_for('login') }}">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('dashboard') }}">Dashboard</a>
</li>
{% endif %}
</ul>
</div>
<button id="toggleTheme" class="btn btn-outline-light ms-3">Toggle Theme</button>
</div>
</nav>
@@ -55,9 +57,25 @@
{% endif %}
{% endwith %}
{% block content %}{% endblock %}
{% block content %}
{% endblock %}
</div>
<script>
const html = document.documentElement;
const savedTheme = localStorage.getItem("theme");
if (savedTheme) {
html.setAttribute("data-bs-theme", savedTheme);
}
document.getElementById("toggleTheme").addEventListener("click", () => {
const current = html.getAttribute("data-bs-theme");
const next = current === "dark" ? "light" : "dark";
html.setAttribute("data-bs-theme", next);
localStorage.setItem("theme", next);
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>

View File

@@ -3,8 +3,8 @@
{% block content %}
<div class="container py-5">
<div class="text-center mb-4">
<h1 class="fw-bold">📷 ZXing Barcode Scanner</h1>
<p class="text-muted">Use your camera to scan barcodes in real time.</p>
<h1 class="fw-bold">Barcode Scanner</h1>
<p class="text-muted">Use your camera to scan barcodes</p>
</div>
<div class="d-flex justify-content-center mb-4">