Skip to content

replacer support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions examples/mountpoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"fmt"
"github.com/metatexx/go-app-pkgs/mountpoint"
"log"
"net/http"
"strconv"

"github.com/metatexx/go-app-pkgs/mountpoint"

"github.com/maxence-charriere/go-app/v9/pkg/app"
)

Expand All @@ -25,13 +26,20 @@ type isolate struct {
app.Compo
Tabs1 []app.UI
Tabs2 []app.UI
Tabs3 []func() app.UI
Active int
mp *mountpoint.UI
maxTab app.UI
}

func (c *isolate) OnInit() {
c.Tabs1 = []app.UI{&tab{Text: "Content A"}, &tab{Text: "Content B"}, &tab{Text: "Content C"}}
c.Tabs2 = []app.UI{&tab{Text: "Content A"}, &tab{Text: "Content B"}, &tab{Text: "Content C"}}
c.Tabs3 = []func() app.UI{
func() app.UI { return &tab{Text: "Content A"} },
func() app.UI { return &tab{Text: "Content B"} },
func() app.UI { return &tab{Text: "Content C"} },
}
c.mp = mountpoint.New(c.Tabs1[0])
}

Expand All @@ -43,6 +51,16 @@ func (c *isolate) OnNav(ctx app.Context) {
}
c.Active = idx
c.mp.Switch(c.Tabs1[c.Active])

c.maxSwitch(ctx)
}

func (c *isolate) maxSwitch(ctx app.Context) {
idx, _ := strconv.Atoi(ctx.Page().URL().Fragment)
if idx >= 3 {
idx = 0
}
c.maxTab = c.Tabs3[idx]()
}

func (c *isolate) Render() app.UI {
Expand All @@ -60,12 +78,14 @@ func (c *isolate) Render() app.UI {
app.Div().Style("padding", "5px").Body(c.Tabs2[c.Active]),
app.Div().Style("margin-top", "10px").Text("Using mountpoint"),
app.Div().Style("padding", "5px").Body(c.mp.UI()),
app.Div().Style("margin-top", "10px").Text("Using Max's implementation"),
app.Div().Style("padding", "5px").Body(c.maxTab),
),
)
}

func main() {
app.Route("/", &isolate{})
app.Route("/", app.NewZeroComponentFactory(&isolate{}))
app.RunWhenOnBrowser()
http.Handle("/", &app.Handler{
Name: "Isolate",
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module github.com/metatexx/go-app-pkgs

go 1.17
go 1.21

toolchain go1.21.6

require (
github.com/magefile/mage v1.15.0
github.com/maxence-charriere/go-app/v9 v9.8.0
github.com/maxence-charriere/go-app/v9 v9.8.1-0.20240215070438-5041bacc4ce0
github.com/metatexx/go-app-pkgs/mountpoint v1.0.1
)

Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXq
github.com/maxence-charriere/go-app/v9 v9.1.2/go.mod h1:zo0n1kh4OMKn7P+MrTUUi7QwUMU2HOfHsZ293TITtxI=
github.com/maxence-charriere/go-app/v9 v9.8.0 h1:rDfLNvxIKXyjpRS76P45kn9Xj8IumwfoqpsEJYxfd+E=
github.com/maxence-charriere/go-app/v9 v9.8.0/go.mod h1:gzgFoeaDuoNHw9MbJraTCKIoKtZ/SoIfOIHHn2FOffc=
github.com/maxence-charriere/go-app/v9 v9.8.1-0.20240207075255-ff07574184f1 h1:Htz6jehcAkURpLUH1dCF2RQQSRmzJFo2E3fDx4/V/E4=
github.com/maxence-charriere/go-app/v9 v9.8.1-0.20240207075255-ff07574184f1/go.mod h1:DILieaERyrL22gcv8vF8z9IJdCw1qKdjTkF1yzxhOu0=
github.com/maxence-charriere/go-app/v9 v9.8.1-0.20240215070438-5041bacc4ce0 h1:WkmR8kleyg9MUKfpqc38uuZXdcjWQ/3tMfjWRtGCgHs=
github.com/maxence-charriere/go-app/v9 v9.8.1-0.20240215070438-5041bacc4ce0/go.mod h1:DILieaERyrL22gcv8vF8z9IJdCw1qKdjTkF1yzxhOu0=
github.com/metatexx/go-app-pkgs/mountpoint v1.0.1 h1:0dx4iIhx6ggoVTjxO/aps9vi0JzbZw3fvHPQQOKTOW8=
github.com/metatexx/go-app-pkgs/mountpoint v1.0.1/go.mod h1:YvAetNc8lyGYmiXb/3gQzAhPCLeZsB+V89bKE6qwCZ0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down