Pinned photo gallery support

This commit is contained in:
Noah Petherbridge 2024-07-07 14:00:58 -07:00
parent 0db69983fe
commit 22b8cf0594
6 changed files with 38 additions and 0 deletions

View File

@ -76,6 +76,7 @@ func Edit() http.HandlerFunc {
altText = strings.TrimSpace(r.FormValue("alt_text"))
isExplicit = r.FormValue("explicit") == "true"
isGallery = r.FormValue("gallery") == "true"
isPinned = r.FormValue("pinned") == "true"
visibility = models.PhotoVisibility(r.FormValue("visibility"))
// Profile pic fields
@ -101,6 +102,7 @@ func Edit() http.HandlerFunc {
models.NewFieldDiff("Caption", photo.Caption, caption),
models.NewFieldDiff("Explicit", photo.Explicit, isExplicit),
models.NewFieldDiff("Gallery", photo.Gallery, isGallery),
models.NewFieldDiff("Pinned", photo.Pinned, isPinned),
models.NewFieldDiff("Visibility", photo.Visibility, visibility),
}
@ -108,6 +110,7 @@ func Edit() http.HandlerFunc {
photo.AltText = altText
photo.Explicit = isExplicit
photo.Gallery = isGallery
photo.Pinned = isPinned
photo.Visibility = visibility
// Can not use a GIF as profile pic.

View File

@ -66,6 +66,7 @@ func Upload() http.HandlerFunc {
isExplicit = r.PostFormValue("explicit") == "true"
visibility = r.PostFormValue("visibility")
isGallery = r.PostFormValue("gallery") == "true"
isPinned = r.PostFormValue("pinned") == "true"
cropCoords = r.PostFormValue("crop")
confirm1 = r.PostFormValue("confirm1") == "true"
confirm2 = r.PostFormValue("confirm2") == "true"
@ -144,6 +145,7 @@ func Upload() http.HandlerFunc {
AltText: altText,
Visibility: models.PhotoVisibility(visibility),
Gallery: isGallery,
Pinned: isPinned,
Explicit: isExplicit,
}

View File

@ -16,6 +16,7 @@ func UserPhotos() http.HandlerFunc {
// Whitelist for ordering options.
var sortWhitelist = []string{
"pinned desc nulls last, updated_at desc",
"created_at desc",
"created_at asc",
}

View File

@ -24,6 +24,7 @@ type Photo struct {
Visibility PhotoVisibility `gorm:"index"`
Gallery bool `gorm:"index"` // photo appears in the public gallery (if public)
Explicit bool `gorm:"index"` // is an explicit photo
Pinned bool `gorm:"index"` // user pins it to the front of their gallery
CreatedAt time.Time `gorm:"index"`
UpdatedAt time.Time
}

View File

@ -19,6 +19,13 @@
<small class="has-text-grey">Uploaded {{.CreatedAt.Format "Jan _2 2006 15:04:05"}}</small>
</div>
<div class="mt-2">
{{if .Pinned}}
<span class="tag is-success is-light">
<span class="icon"><i class="fa fa-thumbtack"></i></span>
<span>Pinned</span>
</span>
{{end}}
{{if .Explicit}}
<span class="tag is-danger is-light">
<span class="icon"><i class="fa fa-fire"></i></span>
@ -420,6 +427,11 @@
<label class="label" for="sort">Sort by:</label>
<div class="select is-fullwidth">
<select id="sort" name="sort">
{{if not .IsSiteGallery}}
<option value="pinned desc nulls last, updated_at desc"{{if eq .Sort "pinned desc nulls last, updated_at desc"}} selected{{end}}>
Pinned, recently updated
</option>
{{end}}
<option value="created_at desc"{{if eq .Sort "created_at desc"}} selected{{end}}>Most recent</option>
<option value="created_at asc"{{if eq .Sort "created_at asc"}} selected{{end}}>Oldest first</option>
</select>

View File

@ -260,6 +260,25 @@
</p>
</div>
<div class="field mb-5">
<label class="label">
<i class="fa fa-thumbtack mr-1 has-text-success"></i>
Pinned Photo
<span class="tag is-success ml-2">New!</span>
</label>
<label class="checkbox">
<input type="checkbox"
name="pinned"
value="true"
{{if or (not .EditPhoto) (.EditPhoto.Pinned)}}checked{{end}}>
Keep this photo at the top of my gallery
</label>
<p class="help">
You may "pin" your favorite photos to keep them always at the front of
your photo gallery.
</p>
</div>
<div class="field mb-5">
<label class="label">Photo Visibility</label>
<div>