Files
swanadiva 8357d9d76e fix: UI overhaul — align all HTMX views with Lumina Design System (46 fixes)
- All 7 pages rewritten: Dashboard, Terminal, Snippets, Keychain, SFTP, Settings, Brief
- Apply consistent Lumina glassmorphic theme (rounded-2xl, shadows, borders, tracking)
- Fix SVG icons not rendering — return template.HTML instead of string
- Fix Alpine x-data scoping: terminal tabs, SFTP modals, snippet tag buttons
- Fix dashboard search sending literal ?q=...
- Rebuild CSS with all new Tailwind classes (62KB)
- Add .air.toml with hot-reload config, docs/PERBAIKANUI.md checklist
- Remove unused backup partials
2026-07-07 14:55:42 +07:00

87 lines
1.7 KiB
Go

package store
import (
"time"
"git.tukangketik.id/swanadiva/hostkeeper/v2/internal/model"
)
type SnippetStore struct {
snippets []model.Snippet
}
func NewSnippetStore() *SnippetStore {
s := &SnippetStore{}
mu.RLock()
readFile("snippets.json", &s.snippets)
mu.RUnlock()
if s.snippets == nil {
s.snippets = []model.Snippet{}
}
return s
}
func (s *SnippetStore) All() []model.Snippet {
mu.RLock()
defer mu.RUnlock()
return s.snippets
}
func (s *SnippetStore) Search(q, collection, tag string) []model.Snippet {
mu.RLock()
defer mu.RUnlock()
var res []model.Snippet
for _, sn := range s.snippets {
if q != "" && !contains(sn.Name, q) && !contains(sn.Content, q) && !contains(sn.Language, q) {
continue
}
if collection != "" && sn.Collection != collection {
continue
}
if tag != "" {
found := false
for _, t := range sn.Tags {
if t == tag {
found = true
break
}
}
if !found {
continue
}
}
res = append(res, sn)
}
return res
}
func (s *SnippetStore) Add(name, content, language string, tags []string, description, collection string) model.Snippet {
mu.Lock()
defer mu.Unlock()
sn := model.Snippet{
ID: randID(),
Name: name,
Content: content,
Language: language,
Description: description,
Collection: collection,
Icon: "FileText",
Tags: tags,
CreatedAt: time.Now().Format("Jan 2, 2006"),
}
s.snippets = append(s.snippets, sn)
writeFile("snippets.json", &s.snippets)
return sn
}
func (s *SnippetStore) Delete(id string) {
mu.Lock()
defer mu.Unlock()
for i, sn := range s.snippets {
if sn.ID == id {
s.snippets = append(s.snippets[:i], s.snippets[i+1:]...)
writeFile("snippets.json", &s.snippets)
return
}
}
}