Pass messages from backend to frontend
This commit is contained in:
parent
b6db773ee3
commit
8476d3ae6c
|
@ -46,8 +46,10 @@ func GetReleases(dbConn *sql.DB, mu *sync.Mutex, proj Project) (Project, error)
|
|||
return proj, err
|
||||
}
|
||||
|
||||
// TODO: figure out a clean way to remove this so the home page loads
|
||||
// immediately.
|
||||
if len(ret) == 0 {
|
||||
return fetchReleases(dbConn, mu, proj)
|
||||
return proj, nil
|
||||
}
|
||||
|
||||
for _, row := range ret {
|
||||
|
|
|
@ -21,11 +21,12 @@
|
|||
<header class="wrapper">
|
||||
<h1>Willow <span><a href="/logout">Log out</a></span></h1>
|
||||
<p><a href="/new">Track a new project</a></p>
|
||||
<p class="message-{{ .MessageType }}">{{ .Message }}</p>
|
||||
</header>
|
||||
<div class="two_column">
|
||||
<div class="projects">
|
||||
<!-- Range through projects that aren't yet up-to-date -->
|
||||
{{- range . -}}
|
||||
{{- range .Projects -}}
|
||||
{{- if ne .Running (index .Releases 0).Tag -}}
|
||||
<h2>Outdated projects</h2>
|
||||
{{- break -}}
|
||||
|
@ -43,13 +44,13 @@
|
|||
{{- end -}}
|
||||
|
||||
<!-- Range through projects that _are_ up-to-date -->
|
||||
{{- range . -}}
|
||||
{{- range .Projects -}}
|
||||
{{- if eq .Running (index .Releases 0).Tag -}}
|
||||
<h2>Up-to-date projects</h2>
|
||||
{{- break -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- range . -}}
|
||||
{{- range .Projects -}}
|
||||
{{- if eq .Running (index .Releases 0).Tag -}}
|
||||
<div class="project card">
|
||||
<h3><a href="{{ .URL }}">{{ .Name }}</a> <span class="delete"><a href="/new?action=delete&url={{ .URL }}">Delete?</a></span></h3>
|
||||
|
@ -60,7 +61,7 @@
|
|||
</div>
|
||||
<div class="release_notes">
|
||||
<h2>Release notes</h2>
|
||||
{{- range . -}}
|
||||
{{- range .Projects -}}
|
||||
<div id="{{ (index .Releases 0).ID }}" class="release_note card">
|
||||
<h3>{{ .Name }}: release notes for <a href="{{ (index .Releases 0).URL }}">{{ (index .Releases 0).Tag }}</a> <span class="close"><a href="#">✖</a></span></h3>
|
||||
{{- if eq .Forge "github" "gitea" "forgejo" -}}
|
||||
|
|
13
ws/ws.go
13
ws/ws.go
|
@ -29,6 +29,12 @@ type Handler struct {
|
|||
Mu *sync.Mutex
|
||||
}
|
||||
|
||||
type page struct {
|
||||
Projects []project.Project
|
||||
Message string
|
||||
MessageType string
|
||||
}
|
||||
|
||||
//go:embed static
|
||||
var fs embed.FS
|
||||
|
||||
|
@ -51,7 +57,12 @@ func (h Handler) RootHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
tmpl := template.Must(template.ParseFS(fs, "static/home.html"))
|
||||
if err := tmpl.Execute(w, data); err != nil {
|
||||
p := page{
|
||||
Projects: data,
|
||||
Message: "Hello world",
|
||||
MessageType: "info",
|
||||
}
|
||||
if err := tmpl.Execute(w, p); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue