2024-09-11 17:31:40 +00:00
|
|
|
package partials
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2024-09-17 17:13:22 +00:00
|
|
|
"github.com/labstack/echo/v4"
|
2024-09-14 00:05:55 +00:00
|
|
|
"github.com/maddalax/htmgo/framework-ui/ui"
|
|
|
|
|
"github.com/maddalax/htmgo/framework/h"
|
2024-09-13 21:33:50 +00:00
|
|
|
"starter-template/news"
|
2024-09-11 17:31:40 +00:00
|
|
|
)
|
|
|
|
|
|
2024-09-17 17:13:22 +00:00
|
|
|
func NewsSheet(ctx echo.Context) *h.Partial {
|
2024-09-11 17:31:40 +00:00
|
|
|
open := h.GetQueryParam(ctx, "open") == "true"
|
|
|
|
|
return h.NewPartialWithHeaders(
|
|
|
|
|
&map[string]string{
|
|
|
|
|
"hx-trigger": "sheetOpened",
|
|
|
|
|
"hx-push-url": fmt.Sprintf("/news%s", h.Ternary(open, "?open=true", "")),
|
|
|
|
|
},
|
|
|
|
|
SheetWrapper(
|
|
|
|
|
h.IfElseLazy(open, SheetOpen, SheetClosed),
|
2024-09-19 23:11:12 +00:00
|
|
|
h.OobSwap(ctx, OpenSheetButton(open)),
|
|
|
|
|
h.OobSwap(ctx, NewsSheetOpenCount(ctx).Root),
|
2024-09-11 17:31:40 +00:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 17:13:22 +00:00
|
|
|
func NewsSheetOpenCount(ctx echo.Context) *h.Partial {
|
2024-09-11 17:31:40 +00:00
|
|
|
|
|
|
|
|
open := h.GetQueryParam(ctx, "open") == "true"
|
|
|
|
|
|
|
|
|
|
return h.NewPartial(h.Div(
|
|
|
|
|
h.Id("sheet-open-count"),
|
|
|
|
|
h.IfElse(open,
|
2024-09-13 17:30:25 +00:00
|
|
|
h.Text(fmt.Sprintf("you opened sheet %d times", 1)),
|
2024-09-11 17:31:40 +00:00
|
|
|
h.Text("sheet is not open")),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 01:24:44 +00:00
|
|
|
func SheetWrapper(children ...h.Ren) h.Ren {
|
2024-09-11 17:31:40 +00:00
|
|
|
return h.Div(h.Id("sheet-partial"), h.Fragment(children...))
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 01:24:44 +00:00
|
|
|
func SheetClosed() h.Ren {
|
2024-09-11 17:31:40 +00:00
|
|
|
return h.Div()
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 01:24:44 +00:00
|
|
|
func SheetOpen() h.Ren {
|
2024-09-11 17:31:40 +00:00
|
|
|
return h.Fragment(h.Div(
|
|
|
|
|
h.Class(`fixed top-0 right-0 h-full w-96 bg-gray-100 shadow-lg z-50`),
|
|
|
|
|
h.Div(
|
|
|
|
|
h.Class("p-4 overflow-y-auto h-full w-full flex flex-col gap-4"),
|
2024-09-13 15:47:18 +00:00
|
|
|
h.P(h.Text("News Sheet"),
|
2024-09-11 17:31:40 +00:00
|
|
|
h.Class("text-lg font-bold"),
|
|
|
|
|
),
|
2024-09-13 15:47:18 +00:00
|
|
|
h.P(h.Text("Here are the latest news stories."),
|
2024-09-11 17:31:40 +00:00
|
|
|
h.Class("text-sm mt-2"),
|
|
|
|
|
),
|
|
|
|
|
ui.Button(ui.ButtonProps{
|
|
|
|
|
Text: "Close NewsSheet",
|
|
|
|
|
Target: "#sheet-partial",
|
|
|
|
|
Get: h.GetPartialPathWithQs(NewsSheet, "open=false"),
|
|
|
|
|
}),
|
|
|
|
|
news.StoryList(),
|
|
|
|
|
)))
|
|
|
|
|
}
|