Promena teme klikom na tačkice u topbaru

This commit is contained in:
2026-06-01 01:45:24 +02:00
parent 8a9579e201
commit 91889b7711
3 changed files with 31 additions and 2 deletions
+1
View File
@@ -56,6 +56,7 @@ func main() {
r.Get("/dashboard", h.Dashboard) r.Get("/dashboard", h.Dashboard)
r.Get("/podesavanja", h.Podesavanja) r.Get("/podesavanja", h.Podesavanja)
r.Post("/podesavanja/sacuvaj", h.SacuvajPodesavanja) r.Post("/podesavanja/sacuvaj", h.SacuvajPodesavanja)
r.Get("/tema/{tema}", h.PromeniTemu)
log.Printf("NTech pokrenut na portu %s", port) log.Printf("NTech pokrenut na portu %s", port)
err = http.ListenAndServe(":"+port, r) err = http.ListenAndServe(":"+port, r)
+28
View File
@@ -6,6 +6,8 @@ import (
"ntech/internal/db/sqlite" "ntech/internal/db/sqlite"
"ntech/internal/model" "ntech/internal/model"
"github.com/go-chi/chi/v5"
) )
// PodaciPodesavanja su podaci za stranicu podešavanja // PodaciPodesavanja su podaci za stranicu podešavanja
@@ -89,3 +91,29 @@ func (h *Handler) SacuvajPodesavanja(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/podesavanja?sacuvano=1", http.StatusSeeOther) http.Redirect(w, r, "/podesavanja?sacuvano=1", http.StatusSeeOther)
} }
// PromeniTemu menja aktivnu temu i vraća na prethodnu stranicu
func (h *Handler) PromeniTemu(w http.ResponseWriter, r *http.Request) {
tema := chi.URLParam(r, "tema")
// proveravamo da li je validna tema
validne := map[string]bool{
"tamna": true, "svetla": true, "zelena": true, "ljubicasta": true,
}
if !validne[tema] {
http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
return
}
if err := sqlite.SacuvajPodesavanje(r.Context(), h.DB, "tema", tema); err != nil {
http.Error(w, "Greška pri promeni teme", http.StatusInternalServerError)
return
}
// vraćamo se na stranicu sa koje je kliknut dugmić
referer := r.Header.Get("Referer")
if referer == "" {
referer = "/dashboard"
}
http.Redirect(w, r, referer, http.StatusSeeOther)
}
+2 -2
View File
@@ -6,8 +6,8 @@
<div style="display:flex;align-items:center;gap:8px;"> <div style="display:flex;align-items:center;gap:8px;">
<a href="/tema/tamna" style="width:20px;height:20px;border-radius:50%;background:#1a1d2e;border:2px solid {{if eq .Tema "tamna"}}#fff{{else}}transparent{{end}};display:inline-block;" title="Tamna"></a> <a href="/tema/tamna" style="width:20px;height:20px;border-radius:50%;background:#1a1d2e;border:2px solid {{if eq .Tema "tamna"}}#fff{{else}}transparent{{end}};display:inline-block;" title="Tamna"></a>
<a href="/tema/svetla" style="width:20px;height:20px;border-radius:50%;background:#f8fafc;border:2px solid {{if eq .Tema "svetla"}}#1a1d2e{{else}}#cbd5e1{{end}};display:inline-block;" title="Svetla"></a> <a href="/tema/svetla" style="width:20px;height:20px;border-radius:50%;background:#f8fafc;border:2px solid {{if eq .Tema "svetla"}}#1a1d2e{{else}}#cbd5e1{{end}};display:inline-block;" title="Svetla"></a>
<a href="/tema/zelena" style="width:20px;height:20px;border-radius:50%;background:#0f2818;border:2px solid {{if eq .Tema "zelena"}}#fff{{else}}transparent{{end}};display:inline-block;" title="Zelena"></a> <a href="/tema/zelena" style="width:20px;height:20px;border-radius:50%;background:#338150;border:2px solid {{if eq .Tema "zelena"}}#fff{{else}}transparent{{end}};display:inline-block;" title="Zelena"></a>
<a href="/tema/ljubicasta" style="width:20px;height:20px;border-radius:50%;background:#1e1535;border:2px solid {{if eq .Tema "ljubicasta"}}#fff{{else}}transparent{{end}};display:inline-block;" title="Ljubičasta"></a> <a href="/tema/ljubicasta" style="width:20px;height:20px;border-radius:50%;background:#543b94;border:2px solid {{if eq .Tema "ljubicasta"}}#fff{{else}}transparent{{end}};display:inline-block;" title="Ljubičasta"></a>
</div> </div>
<!-- korisnik --> <!-- korisnik -->