Redesign the UI on brain's look: sidebar with search, Overview, modules, grouped Settings
- Left sidebar as in brain: search at the top (press /), Overview, Inventory, the modules (Content with Inbox, Sources, Scheduled and Published; later phases greyed out), Settings at the bottom; a top bar with breadcrumbs, and a menu that slides in on narrow screens. - brain's colour tokens, type, radius and shadows, with a dark theme that follows the system setting. - Settings as grouped tabs: Profile; Social accounts (was Credentials, now keys and sign-in together per network); Core & Hermes; AI, which now holds the API keys too. Old addresses redirect. - /search matches every word across posts, fetched items, the inventory, products and settings pages. - Overview: a card per module, then the setup checklist, folded once done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/profile"
|
||||
)
|
||||
|
||||
// hit is one search result.
|
||||
type hit struct {
|
||||
Title, Detail, Link string
|
||||
Badge string // e.g. a relationship or a draft's status
|
||||
}
|
||||
|
||||
// hitGroup is a kind of result, in the order shown.
|
||||
type hitGroup struct {
|
||||
Name string
|
||||
Hits []hit
|
||||
}
|
||||
|
||||
const searchLimit = 25
|
||||
|
||||
// settingsPages are searched by name and by what they hold, so "anthropic
|
||||
// key" or "reddit" find the right tab.
|
||||
var settingsPages = []struct {
|
||||
hit
|
||||
Words string
|
||||
}{
|
||||
{hit{"Company profile", "Settings · your company, products, websites, voice and targets", "/settings/profile", ""},
|
||||
"profile company products websites voice tone audience keywords feeds subreddits accounts"},
|
||||
{hit{"Social accounts", "Settings · X, LinkedIn, Reddit and YouTube keys and sign-ins", "/settings/accounts", ""},
|
||||
"social accounts credentials keys x twitter linkedin reddit youtube sign in connect oauth bearer token"},
|
||||
{hit{"AI", "Settings · provider, model, API keys and the Hermes key", "/settings/ai", ""},
|
||||
"ai provider model anthropic claude openai ollama lm studio api key hermes effort"},
|
||||
{hit{"Core & Hermes", "Settings · the Federated Core, its services and the Hermes bridge", "/settings/core", ""},
|
||||
"core hermes federated mcp hub bridge espocrm nextcloud plausible gitea"},
|
||||
}
|
||||
|
||||
func (s *Server) searchPage(w http.ResponseWriter, r *http.Request) {
|
||||
q := strings.TrimSpace(r.URL.Query().Get("q"))
|
||||
var groups []hitGroup
|
||||
total := 0
|
||||
if q != "" {
|
||||
var err error
|
||||
groups, err = s.search(q)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
for _, g := range groups {
|
||||
total += len(g.Hits)
|
||||
}
|
||||
}
|
||||
s.render(w, r, "search", page{Title: "Search", Nav: "search", Query: q, Data: map[string]any{
|
||||
"Q": q,
|
||||
"Groups": groups,
|
||||
"Total": total,
|
||||
"Limit": searchLimit,
|
||||
}})
|
||||
}
|
||||
|
||||
// search looks for q in the inventory, fetched items, posts and settings.
|
||||
// Every word must appear (case-insensitively), in any order.
|
||||
func (s *Server) search(q string) ([]hitGroup, error) {
|
||||
words := strings.Fields(strings.ToLower(q))
|
||||
matches := func(texts ...string) bool {
|
||||
all := strings.ToLower(strings.Join(texts, "\n"))
|
||||
for _, w := range words {
|
||||
if !strings.Contains(all, w) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
entries, err := inventory.List(s.DB, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids := map[string]int64{} // inventory name (lower case) → ID, for links
|
||||
var inv []hit
|
||||
for _, e := range entries {
|
||||
ids[strings.ToLower(e.Name)] = e.ID
|
||||
if matches(e.Name, e.Description, e.TwitterHandle, e.TalkingPoints, strings.Join(e.Websites, " "),
|
||||
strings.Join(e.Hashtags, " "), strings.Join(e.Keywords, " "), strings.Join(e.Subreddits, " ")) {
|
||||
inv = append(inv, hit{Title: e.Name, Detail: e.Description,
|
||||
Link: "/inventory/" + strconv.FormatInt(e.ID, 10), Badge: e.Relationship})
|
||||
}
|
||||
}
|
||||
entryLink := func(name string) string {
|
||||
if strings.EqualFold(name, content.OwnName) {
|
||||
return "/content/own"
|
||||
}
|
||||
if id, ok := ids[strings.ToLower(name)]; ok {
|
||||
return "/content/" + strconv.FormatInt(id, 10)
|
||||
}
|
||||
return "/content"
|
||||
}
|
||||
|
||||
items, err := content.SearchItems(s.DB, words, searchLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var found []hit
|
||||
for _, it := range items {
|
||||
name := it.AppName
|
||||
if strings.EqualFold(name, content.OwnName) {
|
||||
name = "your own work"
|
||||
}
|
||||
title := it.Title
|
||||
if title == "" {
|
||||
title = it.Body
|
||||
}
|
||||
found = append(found, hit{Title: title, Detail: string(it.Source) + " · " + name + " · " + it.PublishedAt.Local().Format("2 Jan 2006"),
|
||||
Link: entryLink(it.AppName), Badge: ifElse(it.Dismissed, "dismissed", "")})
|
||||
}
|
||||
|
||||
drafts, err := content.SearchDrafts(s.DB, words, searchLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var posts []hit
|
||||
for _, d := range drafts {
|
||||
link := "/inbox"
|
||||
switch d.Status {
|
||||
case content.StatusScheduled:
|
||||
link = "/content/scheduled"
|
||||
case content.StatusPublished:
|
||||
link = "/content/published"
|
||||
}
|
||||
text := d.Content
|
||||
if d.Title != "" {
|
||||
text = d.Title
|
||||
}
|
||||
detail := d.Where()
|
||||
if d.InventoryName != "" {
|
||||
detail += " · " + d.InventoryName
|
||||
}
|
||||
posts = append(posts, hit{Title: text, Detail: detail, Link: link, Badge: d.Status})
|
||||
}
|
||||
|
||||
var settings []hit
|
||||
if p, err := profile.Load(s.DB); err == nil && p.IsSet() {
|
||||
for _, pr := range p.Products {
|
||||
if matches(pr.Name, pr.Description) {
|
||||
settings = append(settings, hit{Title: pr.Name, Detail: "Product, in the company profile", Link: "/settings/profile", Badge: "product"})
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, sp := range settingsPages {
|
||||
if matches(sp.Title, sp.Detail, sp.Words) {
|
||||
settings = append(settings, sp.hit)
|
||||
}
|
||||
}
|
||||
|
||||
var groups []hitGroup
|
||||
for _, g := range []hitGroup{{"Posts", posts}, {"Fetched items", found}, {"Inventory", inv}, {"Settings", settings}} {
|
||||
if len(g.Hits) > 0 {
|
||||
groups = append(groups, g)
|
||||
}
|
||||
}
|
||||
return groups, nil
|
||||
}
|
||||
Reference in New Issue
Block a user