From fb801bbcaa42120ecbd381e4e01a9352a9b46ace Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Wed, 13 Aug 2025 12:30:30 +0100 Subject: [PATCH] appview/strings: add timeline page Change-Id: wvywrqlppxqoxopyqmukwtwmnxsulznr Signed-off-by: oppiliappan --- appview/db/strings.go | 13 +++- appview/pages/pages.go | 9 +++ .../templates/strings/fragments/form.html | 3 +- appview/pages/templates/strings/string.html | 2 +- appview/pages/templates/strings/timeline.html | 65 +++++++++++++++++++ appview/strings/strings.go | 22 +++++++ input.css | 2 +- 7 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 appview/pages/templates/strings/timeline.html diff --git a/appview/db/strings.go b/appview/db/strings.go index 9d0c7137..18304219 100644 --- a/appview/db/strings.go +++ b/appview/db/strings.go @@ -131,7 +131,7 @@ func AddString(e Execer, s String) error { return err } -func GetStrings(e Execer, filters ...filter) ([]String, error) { +func GetStrings(e Execer, limit int, filters ...filter) ([]String, error) { var all []String var conditions []string @@ -146,6 +146,11 @@ func GetStrings(e Execer, filters ...filter) ([]String, error) { whereClause = " where " + strings.Join(conditions, " and ") } + limitClause := "" + if limit != 0 { + limitClause = fmt.Sprintf(" limit %d ", limit) + } + query := fmt.Sprintf(`select did, rkey, @@ -154,8 +159,12 @@ func GetStrings(e Execer, filters ...filter) ([]String, error) { content, created, edited - from strings %s`, + from strings + %s + order by created desc + %s`, whereClause, + limitClause, ) rows, err := e.Query(query, args...) diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 6697ffa3..dc42a234 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1160,6 +1160,15 @@ func (p *Pages) StringsDashboard(w io.Writer, params StringsDashboardParams) err return p.execute("strings/dashboard", w, params) } +type StringTimelineParams struct { + LoggedInUser *oauth.User + Strings []db.String +} + +func (p *Pages) StringsTimeline(w io.Writer, params StringTimelineParams) error { + return p.execute("strings/timeline", w, params) +} + type SingleStringParams struct { LoggedInUser *oauth.User ShowRendered bool diff --git a/appview/pages/templates/strings/fragments/form.html b/appview/pages/templates/strings/fragments/form.html index 2badb23e..8c2dd61d 100644 --- a/appview/pages/templates/strings/fragments/form.html +++ b/appview/pages/templates/strings/fragments/form.html @@ -31,8 +31,9 @@ name="content" id="content-textarea" wrap="off" - class="w-full dark:bg-gray-700 dark:text-white dark:border-gray-600 dark:placeholder-gray-400" + class="w-full dark:bg-gray-700 dark:text-white dark:border-gray-600 dark:placeholder-gray-400 font-mono" rows="20" + spellcheck="false" placeholder="Paste your string here!" required>{{ .String.Contents }}
diff --git a/appview/pages/templates/strings/string.html b/appview/pages/templates/strings/string.html index b275df8b..80a646e5 100644 --- a/appview/pages/templates/strings/string.html +++ b/appview/pages/templates/strings/string.html @@ -77,7 +77,7 @@ {{ end }}
-
+
{{ if .ShowRendered }}
{{ .RenderedContents }}
{{ else }} diff --git a/appview/pages/templates/strings/timeline.html b/appview/pages/templates/strings/timeline.html new file mode 100644 index 00000000..1796cad6 --- /dev/null +++ b/appview/pages/templates/strings/timeline.html @@ -0,0 +1,65 @@ +{{ define "title" }} all strings {{ end }} + +{{ define "topbar" }} + {{ template "layouts/topbar" $ }} +{{ end }} + +{{ define "content" }} + {{ block "timeline" $ }}{{ end }} +{{ end }} + +{{ define "timeline" }} +
+
+

All strings

+
+ +
+ {{ range $i, $s := .Strings }} +
+ {{ if ne $i 0 }} +
+ {{ end }} +
+ {{ template "stringCard" $s }} +
+
+ {{ end }} +
+
+{{ end }} + +{{ define "stringCard" }} +
+ + {{ with .Description }} +
+ {{ . }} +
+ {{ end }} + + {{ template "stringCardInfo" . }} +
+{{ end }} + +{{ define "stringCardInfo" }} + {{ $stat := .Stats }} + {{ $resolved := resolve .Did.String }} +
+ + {{ template "user/fragments/picHandle" $resolved }} + + + {{ $stat.LineCount }} line{{if ne $stat.LineCount 1}}s{{end}} + + {{ with .Edited }} + edited {{ template "repo/fragments/shortTimeAgo" . }} + {{ else }} + {{ template "repo/fragments/shortTimeAgo" .Created }} + {{ end }} +
+{{ end }} + + diff --git a/appview/strings/strings.go b/appview/strings/strings.go index e211d64f..a51f3489 100644 --- a/appview/strings/strings.go +++ b/appview/strings/strings.go @@ -43,6 +43,9 @@ type Strings struct { func (s *Strings) Router(mw *middleware.Middleware) http.Handler { r := chi.NewRouter() + r. + Get("/", s.timeline) + r. With(mw.ResolveIdent()). Route("/{user}", func(r chi.Router) { @@ -70,6 +73,22 @@ func (s *Strings) Router(mw *middleware.Middleware) http.Handler { return r } +func (s *Strings) timeline(w http.ResponseWriter, r *http.Request) { + l := s.Logger.With("handler", "timeline") + + strings, err := db.GetStrings(s.Db, 50) + if err != nil { + l.Error("failed to fetch string", "err", err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + s.Pages.StringsTimeline(w, pages.StringTimelineParams{ + LoggedInUser: s.OAuth.GetUser(r), + Strings: strings, + }) +} + func (s *Strings) contents(w http.ResponseWriter, r *http.Request) { l := s.Logger.With("handler", "contents") @@ -91,6 +110,7 @@ func (s *Strings) contents(w http.ResponseWriter, r *http.Request) { strings, err := db.GetStrings( s.Db, + 0, db.FilterEq("did", id.DID), db.FilterEq("rkey", rkey), ) @@ -154,6 +174,7 @@ func (s *Strings) dashboard(w http.ResponseWriter, r *http.Request) { all, err := db.GetStrings( s.Db, + 0, db.FilterEq("did", id.DID), ) if err != nil { @@ -225,6 +246,7 @@ func (s *Strings) edit(w http.ResponseWriter, r *http.Request) { // get the string currently being edited all, err := db.GetStrings( s.Db, + 0, db.FilterEq("did", id.DID), db.FilterEq("rkey", rkey), ) diff --git a/input.css b/input.css index b47edc90..009a7aa1 100644 --- a/input.css +++ b/input.css @@ -104,7 +104,7 @@ } code { - @apply font-mono rounded bg-gray-100 dark:bg-gray-700; + @apply font-mono rounded bg-gray-100 dark:bg-gray-700 text-black dark:text-white; } } -- 2.43.0