Files
simple-aircraft-manager-rails/app/javascript/controllers/theme_controller.js
T
rickyandClaude Opus 5.5 bff6a05173 Remove orphaned code and unused Solid Cable; simplify compliance status
- Delete methods nothing calls: BackupRun.last_good, EntrySignature#short_id,
  Sso#issuer_origin, InspectionType#effect_label and #latest_record_for,
  ApplicationHelper#airworthiness_dot, Airworthiness::Status#can_fly? and
  FlightStats#shortest_flight (tests now check red? / longest_flight)
- Routes: sessions and passwords limited to the actions that exist
- Theme toggle: drop the unused button target
- Action Cable was never used (no broadcasts or streams): async adapter in
  production, solid_cable gem, cable database and app/channels removed
- Empty system test setup removed with capybara and selenium-webdriver
- Compliance: one due_result helper for overdue / due soon; inspections use
  next_due for the date, as ADs do
- applicable_to moved into SharedRecordHistory (was identical in ADs and
  inspection types)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 21:04:41 -05:00

49 lines
1.7 KiB
JavaScript

import { Controller } from "@hotwired/stimulus"
const CHOICES = ["system", "light", "dark"]
const LABELS = { system: "System", light: "Light", dark: "Dark" }
// Light / dark / follow-the-OS theme toggle. The choice is kept in
// localStorage; the layout's inline script applies it before first paint.
export default class extends Controller {
connect() {
this.media = window.matchMedia("(prefers-color-scheme: dark)")
this.onSystemChange = () => { if (this.choice === "system") this.apply() }
this.media.addEventListener("change", this.onSystemChange)
this.apply()
}
disconnect() {
this.media.removeEventListener("change", this.onSystemChange)
}
cycle() {
this.choice = CHOICES[(CHOICES.indexOf(this.choice) + 1) % CHOICES.length]
this.apply()
}
get choice() {
try { return localStorage.getItem("theme") || "system" } catch { return "system" }
}
set choice(value) {
try { localStorage.setItem("theme", value) } catch {}
}
apply() {
const choice = this.choice
const dark = choice === "dark" || (choice === "system" && this.media.matches)
const theme = dark ? "dark" : "light"
const changed = document.documentElement.dataset.theme !== theme
document.documentElement.dataset.theme = theme
this.element.querySelectorAll("[data-theme-icon]").forEach((icon) => {
icon.classList.toggle("hidden", icon.dataset.themeIcon !== choice)
})
const label = `Theme: ${LABELS[choice]}${choice === "system" ? ` (${theme})` : ""}`
this.element.title = label
this.element.setAttribute("aria-label", label)
if (changed) window.dispatchEvent(new CustomEvent("theme:change", { detail: { theme } }))
}
}