diff --git a/cmd/main.go b/cmd/main.go
index 87c69d2..4dab085 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -7,9 +7,12 @@ import (
func main() {
app := echo.New()
+ index := 0
- h := handler.Homehandler{}
+ h := handler.Homehandler{index}
app.GET("/", h.HandleUserShow)
+ app.POST("/carousel/next", handler.HtmxCarouselHandler{&index, 1}.HandlerCarouselUpdate)
+ app.POST("/carousel/previous", handler.HtmxCarouselHandler{&index, -1}.HandlerCarouselUpdate)
app.Static("/static", "assets")
app.Start(":3030")
diff --git a/internal/handler/handler.go b/internal/handler/handler.go
index 0829c58..80f2f78 100644
--- a/internal/handler/handler.go
+++ b/internal/handler/handler.go
@@ -6,13 +6,30 @@ import (
"github.com/lorenzhohermuth/portfolio/view/page"
)
-type Homehandler struct {}
+type Homehandler struct {
+ Index int
+}
func(h Homehandler) HandleUserShow(ctx echo.Context) error {
entrys := []component.CarouselEntry{
{"/static/test.jpg", "This is a Tree" , "I like Trees"},
- {"/static/flower.jpeg", "This is a Tree" , "I like Trees"},
- {"/static/paris.jpg", "This is a Tree" , "I like Trees"},
+ {"/static/flower.jpeg", "This is a Flower" , "I like Flowers"},
+ {"/static/paris.jpg", "This is the Eiffel Tower" , "I not like Franc"},
}
- return render(ctx, page.ShowHome(entrys))
+ return render(ctx, page.ShowHome(entrys, h.Index))
+}
+
+type HtmxCarouselHandler struct {
+ Index *int
+ Direction int
+}
+
+func(h HtmxCarouselHandler) HandlerCarouselUpdate(ctx echo.Context) error {
+ entrys := []component.CarouselEntry{
+ {"/static/test.jpg", "This is a Tree" , "I like Trees"},
+ {"/static/flower.jpeg", "This is a Flower" , "I like Flowers"},
+ {"/static/paris.jpg", "This is the Eiffel Tower" , "I not like Franc"},
+ }
+ *h.Index += h.Direction
+ return render(ctx, component.Carousel(entrys, int(*h.Index)))
}
diff --git a/view/component/carousel.templ b/view/component/carousel.templ
index 5f49d6c..4378774 100644
--- a/view/component/carousel.templ
+++ b/view/component/carousel.templ
@@ -6,33 +6,46 @@ type CarouselEntry struct {
Text string
}
-func add(a int, b int) int {
- return a + b
+func getEntry(arr []CarouselEntry, index int) CarouselEntry {
+ newIndex := index
+ for newIndex < 0 {
+ newIndex += len(arr)
+ }
+ newIndex = newIndex % len(arr)
+ return arr[newIndex]
}
templ Carousel(elm []CarouselEntry , index int) {
-
+
-
-

+
-
{elm[index].Title}
+
{getEntry(elm, index).Title}
-
-
+
+
-
{elm[index].Text}
+
{getEntry(elm, index).Text}
}
diff --git a/view/component/carousel_templ.go b/view/component/carousel_templ.go
index ca50599..840e10a 100644
--- a/view/component/carousel_templ.go
+++ b/view/component/carousel_templ.go
@@ -16,8 +16,13 @@ type CarouselEntry struct {
Text string
}
-func add(a int, b int) int {
- return a + b
+func getEntry(arr []CarouselEntry, index int) CarouselEntry {
+ newIndex := index
+ for newIndex < 0 {
+ newIndex += len(arr)
+ }
+ newIndex = newIndex % len(arr)
+ return arr[newIndex]
}
func Carousel(elm []CarouselEntry, index int) templ.Component {
@@ -33,14 +38,14 @@ func Carousel(elm []CarouselEntry, index int) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
)
)
)
Portfolio Lorenz Hohermuth
+
diff --git a/view/layout/base_templ.go b/view/layout/base_templ.go
index a18349f..42ea1a2 100644
--- a/view/layout/base_templ.go
+++ b/view/layout/base_templ.go
@@ -23,7 +23,7 @@ func Base() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Portfolio Lorenz Hohermuth")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Portfolio Lorenz Hohermuth")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/view/page/home.templ b/view/page/home.templ
index 960c3c3..88e948c 100644
--- a/view/page/home.templ
+++ b/view/page/home.templ
@@ -3,14 +3,14 @@ package page
import "github.com/lorenzhohermuth/portfolio/view/layout"
import "github.com/lorenzhohermuth/portfolio/view/component"
-templ ShowHome(arr []component.CarouselEntry) {
+templ ShowHome(arr []component.CarouselEntry, index int) {
@layout.Base(){
Intro
- @component.Carousel(arr, 1)
+ @component.Carousel(arr, index)
diff --git a/view/page/home_templ.go b/view/page/home_templ.go
index 8c728d0..9022065 100644
--- a/view/page/home_templ.go
+++ b/view/page/home_templ.go
@@ -13,7 +13,7 @@ import "bytes"
import "github.com/lorenzhohermuth/portfolio/view/layout"
import "github.com/lorenzhohermuth/portfolio/view/component"
-func ShowHome(arr []component.CarouselEntry) templ.Component {
+func ShowHome(arr []component.CarouselEntry, index int) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
@@ -36,7 +36,7 @@ func ShowHome(arr []component.CarouselEntry) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = component.Carousel(arr, 1).Render(ctx, templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = component.Carousel(arr, index).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}