2023-05-08 18:43:07 +00:00
|
|
|
//go:build wasm
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2023-05-12 20:07:04 +00:00
|
|
|
"git.d3nexus.de/Dadido3/D3vugu-components/components/navigation"
|
2023-05-18 21:17:17 +00:00
|
|
|
"git.d3nexus.de/Dadido3/D3vugu-components/components/overlay"
|
2023-05-08 18:43:07 +00:00
|
|
|
"github.com/vugu/vgrouter"
|
|
|
|
"github.com/vugu/vugu"
|
|
|
|
)
|
|
|
|
|
|
|
|
// urlPathPrefix contains the path prefix for the router.
|
|
|
|
//
|
|
|
|
// If the application's URL is `example.com/suburl/`, use `go build -ldflags="-X 'main.urlPathPrefix=/suburl'"`.
|
|
|
|
var urlPathPrefix = ""
|
|
|
|
|
|
|
|
// vuguSetup sets up overall wiring and routing.
|
|
|
|
func vuguSetup(buildEnv *vugu.BuildEnv, eventEnv vugu.EventEnv) vugu.Builder {
|
|
|
|
|
|
|
|
// Create new router instance.
|
|
|
|
router := vgrouter.New(eventEnv)
|
|
|
|
|
|
|
|
// Set prefix if available.
|
|
|
|
router.SetPathPrefix(urlPathPrefix)
|
|
|
|
|
|
|
|
// Create root object.
|
2023-05-18 21:17:17 +00:00
|
|
|
root := &Root{
|
|
|
|
OverlayContainer: &overlay.Container{},
|
|
|
|
}
|
2023-05-08 18:43:07 +00:00
|
|
|
|
2023-05-12 20:07:04 +00:00
|
|
|
var pageInfo navigation.PageInfo
|
|
|
|
|
2023-05-08 18:43:07 +00:00
|
|
|
buildEnv.SetWireFunc(func(b vugu.Builder) {
|
|
|
|
// Make our wire function populate anything that wants a "Navigator".
|
|
|
|
if c, ok := b.(vgrouter.NavigatorSetter); ok {
|
|
|
|
c.NavigatorSet(router)
|
|
|
|
}
|
2023-05-12 20:07:04 +00:00
|
|
|
if c, ok := b.(navigation.PageInfoSetter); ok {
|
|
|
|
c.PageInfoSet(&pageInfo)
|
|
|
|
}
|
2023-05-18 21:17:17 +00:00
|
|
|
if c, ok := b.(overlay.OverlayContainerSetter); ok {
|
|
|
|
c.OverlayContainerSet(root.OverlayContainer)
|
|
|
|
}
|
2023-05-08 18:43:07 +00:00
|
|
|
})
|
|
|
|
|
2023-05-12 20:07:04 +00:00
|
|
|
// Call wire function on root component.
|
2023-05-08 18:43:07 +00:00
|
|
|
buildEnv.WireComponent(root)
|
|
|
|
|
|
|
|
// Add routes.
|
2023-05-12 20:07:04 +00:00
|
|
|
router.MustAddRouteExact("/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
2023-05-15 06:58:12 +00:00
|
|
|
root.Body = &PageHome{}
|
2023-05-12 20:07:04 +00:00
|
|
|
}))
|
|
|
|
|
2023-05-25 13:59:13 +00:00
|
|
|
router.MustAddRouteExact("/input/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
|
|
|
root.Body = &PageInput{}
|
|
|
|
}))
|
|
|
|
|
2023-05-16 16:10:24 +00:00
|
|
|
router.MustAddRouteExact("/icons/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
2023-05-12 20:07:04 +00:00
|
|
|
root.Body = &PageIcons{}
|
|
|
|
}))
|
|
|
|
|
2023-05-16 16:10:24 +00:00
|
|
|
router.MustAddRouteExact("/layout/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
|
|
|
root.Body = &PageLayout{}
|
|
|
|
}))
|
|
|
|
|
2023-05-18 11:55:48 +00:00
|
|
|
router.MustAddRouteExact("/colors/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
|
|
|
root.Body = &PageColors{}
|
|
|
|
}))
|
|
|
|
|
2023-05-18 21:17:17 +00:00
|
|
|
router.MustAddRouteExact("/overlays/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
|
|
|
root.Body = &PageOverlays{}
|
|
|
|
}))
|
|
|
|
|
2023-05-16 16:10:24 +00:00
|
|
|
router.MustAddRouteExact("/user/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
|
|
|
root.Body = &PageUser{}
|
|
|
|
}))
|
|
|
|
|
|
|
|
router.MustAddRouteExact("/settings/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
|
|
|
root.Body = &PageSettings{}
|
|
|
|
}))
|
|
|
|
|
2023-05-12 20:07:04 +00:00
|
|
|
router.SetNotFound(vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
|
|
|
root.Body = nil
|
|
|
|
}))
|
|
|
|
|
|
|
|
// add another route at the end that always runs and handles the page info
|
|
|
|
router.MustAddRoute("/", vgrouter.RouteHandlerFunc(func(rm *vgrouter.RouteMatch) {
|
|
|
|
pageInfo = navigation.NewPageInfo(rm.Path, root.Body)
|
|
|
|
}))
|
2023-05-08 18:43:07 +00:00
|
|
|
|
|
|
|
// Tell the router to listen to the browser changing URLs.
|
|
|
|
err := router.ListenForPopState()
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grab the current browser URL and process it as a route.
|
|
|
|
err = router.Pull()
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return root
|
|
|
|
}
|