Skip to content

Commit

Permalink
combined history templates
Browse files Browse the repository at this point in the history
  • Loading branch information
damongolding committed Jan 21, 2025
1 parent 6a8baeb commit 3613045
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
32 changes: 0 additions & 32 deletions internal/templates/components/image/history.templ

This file was deleted.

7 changes: 5 additions & 2 deletions internal/templates/components/image/image.templ
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package components

import "github.com/damongolding/immich-kiosk/internal/common"
import (
"github.com/damongolding/immich-kiosk/internal/common"
"github.com/damongolding/immich-kiosk/internal/templates/partials"
)

// Image is the main entry point for rendering images.
// It determines whether to use a single or split view layout based on the number of images,
Expand All @@ -14,7 +17,7 @@ templ Image(viewData common.ViewData) {
} else {
@layoutSplitView(viewData)
}
@renderHistory(viewData)
@partials.RenderHistory(viewData)
if viewData.ShowMoreInfo {
@renderMoreInfo(viewData)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/templates/components/video/video.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package components
import (
"fmt"
"github.com/damongolding/immich-kiosk/internal/common"
"github.com/damongolding/immich-kiosk/internal/templates/partials"
)

templ Video(viewData common.ViewData) {
Expand All @@ -16,5 +17,5 @@ templ Video(viewData common.ViewData) {
></video>
</div>
</div>
@renderHistory(viewData)
@partials.RenderHistory(viewData)
}
31 changes: 31 additions & 0 deletions internal/templates/partials/history.templ
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
package partials

import (
"github.com/damongolding/immich-kiosk/internal/common"
"html/template"
"strings"
)

// historyForm renders a form for kiosk history
templ History() {
<form id="kiosk-history" hx-swap-oob="true">
<input class="kiosk-history--entry" type="hidden" value=""/>
</form>
}

func newHistoryEntry(images []common.ViewImageData) string {
if len(images) == 0 {
return ""
}
newImages := make([]string, len(images))
for i, entry := range images {
sanitisedID := template.HTMLEscapeString(entry.ImmichImage.ID)
newImages[i] = sanitisedID
}
return strings.Join(newImages, ",")
}

// renderHistory renders a form containing the viewing history of images.
//
// Parameters:
// - viewData: ViewData containing the history and current images.
templ RenderHistory(viewData common.ViewData) {
<form id="kiosk-history" hx-swap-oob="true">
for _, historyEntry := range viewData.History {
<input type="hidden" class="kiosk-history--entry" name="history" value={ historyEntry }/>
}
<input type="hidden" class="kiosk-history--entry" name="history" value={ newHistoryEntry(viewData.Images) }/>
</form>
}

0 comments on commit 3613045

Please sign in to comment.