diff --git a/internal/server/ui/router.go b/internal/server/ui/router.go index 5475ab0..39e91bf 100644 --- a/internal/server/ui/router.go +++ b/internal/server/ui/router.go @@ -4,11 +4,11 @@ import ( "encoding/json" "errors" "fmt" + "html/template" "net/http" "net/url" "strconv" "strings" - "text/template" "ruben/inventory2/internal/domains/accounts" etsy_platform "ruben/inventory2/internal/domains/platforms/etsy" @@ -81,6 +81,11 @@ func Routes( return a * b }, + // html + "rawHTML": func(s string) template.HTML { + return template.HTML(s) + }, + // json "prettyPrintJSON": func(j json.RawMessage) string { b, err := json.MarshalIndent(j, " ", "") @@ -90,6 +95,18 @@ func Routes( return string(b) }, "marshalJSON": json.Marshal, + + // slices + "newSlice": func(args ...any) []any { + return args + }, + "newHTMLSlice": func(args ...string) []template.HTML { + ss := make([]template.HTML, len(args)) + for i, s := range args { + ss[i] = template.HTML(s) + } + return ss + }, } }, }), diff --git a/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/add-listing-button.html.tmpl b/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/add-listing-button.html.tmpl index 027babb..395273b 100644 --- a/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/add-listing-button.html.tmpl +++ b/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/add-listing-button.html.tmpl @@ -1,7 +1,7 @@ {{- $acctID := .PathParams.acctID }} -{{- component "button" +{{- $button := component "button" "HXPost" (printf "/api/accounts/%d/inventory/sync-groups/draft/listings" $acctID) "HXTarget" "#accounts-acct-id-inventory-sync-groups-draft-table" "HXSwap" "none" @@ -14,3 +14,24 @@ send rowUpdated to the first
in #accounts-acct-id-inventory-sync-groups-draft-table ` }} +{{/* $button */}} + +{{- + component "tutorial-tooltip" + "AnchorTag" "div" + "AnchorID" "sync-groups-draft-table-add-listing-button" + "AnchorClickedEventName" "anchorClicked" + "AnchorContent" $button + + "AnchorClass" "" + "AnchorStyle" "display: inline;" + + "PopoverID" "add-listing-popover" + "PopoverContentIDPrefix" "add-listing-popover-content" + "PopoverContents" ( + newHTMLSlice + "Click to add a listing" + "You need at least two to create a sync group!" + "Keep adding listing until done!" + ) +}} diff --git a/templates/components/tutorial-tooltip.html.tmpl b/templates/components/tutorial-tooltip.html.tmpl new file mode 100644 index 0000000..7e0b8fe --- /dev/null +++ b/templates/components/tutorial-tooltip.html.tmpl @@ -0,0 +1,103 @@ +{{/* anchor props */}} +{{/* required: .AnchorTag, .AnchorID, .AnchorClickedEventName, .AnchorContent */}} +{{/* optional: .AnchorClass, .AnchorStyle */}} +{{/* popover props */}} +{{/* required: .PopoverID, PopoverContentIDPrefix, .PopoverContents: [](string|HTML) */}} +{{/* optional: .PopoverStyle */}} + +{{- $dot := . }} +{{- $anchorTag := or .AnchorTag "div" }} +{{printf "<%s" $anchorTag | rawHTML}} + {{if .AnchorID}}id="{{.AnchorID}}"{{end}} + {{if .AnchorClass}}class="{{.AnchorClass}}"{{end}} + style="anchor-name: --{{.AnchorID}}; {{.AnchorStyle}}" + _=" + on click + set popover to the #{{.PopoverID}} + send {{.AnchorClickedEventName}} to #{{.PopoverID}} + " +{{ rawHTML ">" }} + {{ .AnchorContent }} +{{printf "%s>" $anchorTag | rawHTML}} + diff --git a/templates/pages/accounts/{acctID.int64}/index.html.tmpl b/templates/pages/accounts/{acctID.int64}/index.html.tmpl index 1d559cc..c3217d5 100644 --- a/templates/pages/accounts/{acctID.int64}/index.html.tmpl +++ b/templates/pages/accounts/{acctID.int64}/index.html.tmpl @@ -60,19 +60,38 @@ >