List existing tags on edit post page

This commit is contained in:
Brian Picciano 2022-05-21 11:20:45 -06:00
parent 3059909deb
commit e269b111a1
2 changed files with 28 additions and 11 deletions

View File

@ -205,7 +205,21 @@ func (a *api) renderEditPostHandler() http.Handler {
} }
} }
executeTemplate(rw, r, tpl, storedPost) tags, err := a.params.PostStore.GetTags()
if err != nil {
apiutil.InternalServerError(rw, r, fmt.Errorf("fetching tags: %w", err))
return
}
tplPayload := struct {
Post post.StoredPost
Tags []string
}{
Post: storedPost,
Tags: tags,
}
executeTemplate(rw, r, tpl, tplPayload)
}) })
} }

View File

@ -8,17 +8,17 @@
<div class="columns six"> <div class="columns six">
<label for="idInput">Unique ID</label> <label for="idInput">Unique ID</label>
{{ if eq .Payload.ID "" }} {{ if eq .Payload.Post.ID "" }}
<input <input
id="idInput" id="idInput"
name="id" name="id"
class="u-full-width" class="u-full-width"
type="text" type="text"
placeholder="e.g. how-to-fly-a-kite" placeholder="e.g. how-to-fly-a-kite"
value="{{ .Payload.ID }}" /> value="{{ .Payload.Post.ID }}" />
{{ else }} {{ else }}
<a href="{{ PostURL .Payload.ID }}" target="_blank">{{ .Payload.ID }}</a> <a href="{{ PostURL .Payload.Post.ID }}" target="_blank">{{ .Payload.Post.ID }}</a>
<input name="id" type="hidden" value="{{ .Payload.ID }}" /> <input name="id" type="hidden" value="{{ .Payload.Post.ID }}" />
{{ end }} {{ end }}
</div> </div>
@ -29,7 +29,10 @@
name="tags" name="tags"
class="u-full-width" class="u-full-width"
type="text" type="text"
value="{{ range $i, $tag := .Payload.Tags }}{{ if ne $i 0 }} {{ end }}{{ $tag }}{{ end }}" /> value="{{ range $i, $tag := .Payload.Post.Tags }}{{ if ne $i 0 }} {{ end }}{{ $tag }}{{ end }}" />
<p class="light">
Existing tags: {{ range $i, $tag := .Payload.Tags }}{{ if ne $i 0 }} {{ end }}{{ $tag }}{{ end }}
</p>
</div> </div>
<div class="columns three"> <div class="columns three">
@ -39,7 +42,7 @@
name="series" name="series"
class="u-full-width" class="u-full-width"
type="text" type="text"
value="{{ .Payload.Series }}" /> value="{{ .Payload.Post.Series }}" />
</div> </div>
</div> </div>
@ -53,7 +56,7 @@
name="title" name="title"
class="u-full-width" class="u-full-width"
type="text" type="text"
value="{{ .Payload.Title }}" /> value="{{ .Payload.Post.Title }}" />
</div> </div>
<div class="columns six"> <div class="columns six">
@ -63,7 +66,7 @@
name="description" name="description"
class="u-full-width" class="u-full-width"
type="text" type="text"
value="{{ .Payload.Description }}" /> value="{{ .Payload.Post.Description }}" />
</div> </div>
</div> </div>
@ -76,7 +79,7 @@
placeholder="Blog body" placeholder="Blog body"
style="height: 50vh;" style="height: 50vh;"
> >
{{- .Payload.Body -}} {{- .Payload.Post.Body -}}
</textarea> </textarea>
</div> </div>
</div> </div>
@ -84,7 +87,7 @@
<input <input
type="submit" type="submit"
value="Preview" value="Preview"
formaction="{{ BlogURL "posts/" }}{{ .Payload.ID }}?method=preview" formaction="{{ BlogURL "posts/" }}{{ .Payload.Post.ID }}?method=preview"
formtarget="_blank" formtarget="_blank"
/> />