diff --git a/appview/db/strings.go b/appview/db/strings.go --- a/appview/db/strings.go +++ b/appview/db/strings.go @@ -131,7 +131,7 @@ ) 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 @@ -144,6 +144,11 @@ whereClause := "" if conditions != nil { whereClause = " where " + strings.Join(conditions, " and ") + } + + limitClause := "" + if limit != 0 { + limitClause = fmt.Sprintf(" limit %d ", limit) } query := fmt.Sprintf(`select @@ -154,8 +159,12 @@ description, 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 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1160,6 +1160,15 @@ func (p *Pages) StringsDashboard(w io.Writer, params StringsDashboardParams) error { 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 --- a/appview/pages/templates/strings/fragments/form.html +++ b/appview/pages/templates/strings/fragments/form.html @@ -31,8 +31,9 @@
diff --git a/appview/pages/templates/strings/string.html b/appview/pages/templates/strings/string.html --- 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 --- /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 --- a/appview/strings/strings.go +++ b/appview/strings/strings.go @@ -44,6 +44,9 @@ 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) { r.Get("/", s.dashboard) @@ -70,6 +73,22 @@ 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 @@ l = l.With("rkey", rkey) strings, err := db.GetStrings( s.Db, + 0, db.FilterEq("did", id.DID), db.FilterEq("rkey", rkey), ) @@ -154,6 +174,7 @@ l = l.With("did", id.DID, "handle", id.Handle) all, err := db.GetStrings( s.Db, + 0, db.FilterEq("did", id.DID), ) if err != nil { @@ -225,6 +246,7 @@ // 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 --- a/input.css +++ b/input.css @@ -103,7 +103,7 @@ display: none; } 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; } }