Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #75 from qor5/fix-lazy-portal-doc
Browse files Browse the repository at this point in the history
fixed the lazy portal doc
  • Loading branch information
iBakuman authored Oct 20, 2023
2 parents 064a895 + c07c148 commit 5d0ba28
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/search_indexes.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/vuetify-components/lazy-portals.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
<div id='docMainBox' class='px-16 pb-12 pt-4 overflow-auto'>
<h1 class='mb-8'>Lazy Portals</h1>

<div class='border-t'><p>Use <code>web.Portal().EventFunc(&#34;menuItems&#34;).Name(&#34;menuContent&#34;)</code> to put a portal place holder inside a part of html, and it will load specified event func&#39;s response body inside the place holder after the main page is rendered in a separate AJAX request. Later in an event func, you could also use <code>r.ReloadPortals = []string{&#34;menuContent&#34;}</code> to reload the portal.</p>
<div class='border-t'><p>Use <code>web.Portal().Loader(web.POST().EventFunc(&#34;menuItems&#34;)).Name(&#34;menuContent&#34;)</code> to put a portal place holder inside a part of html, and it will load specified event func&#39;s response body inside the place holder after the main page is rendered in a separate AJAX request. Later in an event func, you could also use <code>r.ReloadPortals = []string{&#34;menuContent&#34;}</code> to reload the portal.</p>

<highlightjs :language='"go"' :code='"\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t. \"github.com/qor5/ui/vuetify\"\n\t\"github.com/qor5/web\"\n\th \"github.com/theplant/htmlgo\"\n)\n\ntype mystate struct {\n\tCompany string\n\tError string\n}\n\nvar listItems = []string{\"Apple\", \"Microsoft\", \"Google\"}\n\nfunc LazyPortalsAndReload(ctx *web.EventContext) (pr web.PageResponse, err error) {\n\n\tpr.Body = VApp(\n\t\tVMain(\n\t\t\tVContainer(\n\t\t\t\tVDialog(\n\t\t\t\t\tweb.Slot(\n\t\t\t\t\t\tVBtn(\"Select\").Color(\"primary\").Attr(\"v-on\", \"on\"),\n\t\t\t\t\t).Name(\"activator\").Scope(\"{ on }\"),\n\t\t\t\t\tweb.Portal().Loader(web.POST().EventFunc(\"menuItems\")).Name(\"menuContent\"),\n\t\t\t\t),\n\n\t\t\t\th.Div(\n\t\t\t\t\th.H1(\"Portal A\"),\n\t\t\t\t\tweb.Portal().Loader(web.POST().EventFunc(\"portal1\")).Name(\"portalA\"),\n\t\t\t\t).Style(\"border: 2px solid blue;\"),\n\n\t\t\t\th.Div(\n\t\t\t\t\th.H1(\"Portal B\"),\n\t\t\t\t\tweb.Portal().Loader(web.POST().EventFunc(\"portal1\")).Name(\"portalB\"),\n\t\t\t\t).Style(\"border: 2px solid red;\"),\n\n\t\t\t\tVBtn(\"Reload Portal A and B\").OnClick(\"reloadAB\").Color(\"orange\").Dark(true),\n\n\t\t\t\th.Div(\n\t\t\t\t\th.H1(\"Portal C\"),\n\t\t\t\t\tweb.Portal().Name(\"portalC\"),\n\t\t\t\t).Style(\"border: 2px solid blue;\"),\n\n\t\t\t\th.Div(\n\t\t\t\t\th.H1(\"Portal D\"),\n\t\t\t\t\tweb.Portal().Name(\"portalD\"),\n\t\t\t\t).Style(\"border: 2px solid red;\"),\n\n\t\t\t\tVBtn(\"Update Portal C and D\").OnClick(\"updateCD\").Color(\"primary\").Dark(true),\n\t\t\t),\n\t\t),\n\t)\n\treturn\n}\n\nfunc menuItems(ctx *web.EventContext) (r web.EventResponse, err error) {\n\n\tvar items []h.HTMLComponent\n\tfor _, item := range listItems {\n\t\titems = append(items, VListItem(\n\t\t\tVListItemTitle(h.Text(item)),\n\t\t))\n\t}\n\n\titems = append(items, VDivider())\n\n\titems = append(items,\n\t\tVDialog(\n\t\t\tweb.Slot(\n\t\t\t\tVListItemAction(\n\t\t\t\t\tVBtn(\"Create New\").Text(true).Attr(\"v-on\", \"on\"),\n\t\t\t\t),\n\t\t\t).Name(\"activator\").Scope(\"{ on }\"),\n\t\t\tweb.Portal().Loader(web.POST().EventFunc(\"addItemForm\")).Name(\"addItemForm\").Visible(\"true\"),\n\t\t).Width(\"500\"),\n\t)\n\n\tr.Body = VList(items...)\n\treturn\n}\n\nfunc addItemForm(ctx *web.EventContext) (r web.EventResponse, err error) {\n\tvar s = \u0026mystate{}\n\tctx.MustUnmarshalForm(s)\n\n\ttextField := VTextField().FieldName(\"Company\")\n\n\tif len(s.Error) \u003e 0 {\n\t\ttextField.Error(true).ErrorMessages(s.Error)\n\t}\n\n\tr.Body = VCard(\n\t\tVCardText(\n\t\t\ttextField,\n\t\t),\n\t\tVCardActions(\n\t\t\tVBtn(\"Create\").Color(\"primary\").OnClick(\"addItem\"),\n\t\t),\n\t)\n\treturn\n}\n\nfunc addItem(ctx *web.EventContext) (r web.EventResponse, err error) {\n\tvar s = \u0026mystate{}\n\tctx.MustUnmarshalForm(s)\n\n\tif len(s.Company) \u003c 5 {\n\t\ts.Error = \"too short\"\n\t\tr.ReloadPortals = []string{\"addItemForm\"}\n\t\treturn\n\t}\n\n\tlistItems = append(listItems, s.Company)\n\ts.Company = \"\"\n\ts.Error = \"\"\n\tr.ReloadPortals = []string{\"menuContent\"}\n\treturn\n}\n\nfunc portal1(ctx *web.EventContext) (r web.EventResponse, err error) {\n\tr.Body = h.Text(fmt.Sprint(time.Now().UnixNano()))\n\treturn\n}\n\nfunc reloadAB(ctx *web.EventContext) (r web.EventResponse, err error) {\n\tr.ReloadPortals = []string{\"portalA\", \"portalB\"}\n\treturn\n}\n\nfunc updateCD(ctx *web.EventContext) (r web.EventResponse, err error) {\n\tr.UpdatePortals = append(r.UpdatePortals,\n\t\t\u0026web.PortalUpdate{\n\t\t\tName: \"portalC\",\n\t\t\tBody: h.Text(fmt.Sprint(time.Now().UnixNano())),\n\t\t},\n\t\t\u0026web.PortalUpdate{\n\t\t\tName: \"portalD\",\n\t\t\tBody: h.Text(fmt.Sprint(time.Now().UnixNano())),\n\t\t},\n\t)\n\treturn\n}\n\nvar LazyPortalsAndReloadPB = web.Page(LazyPortalsAndReload).\n\tEventFunc(\"addItem\", addItem).\n\tEventFunc(\"menuItems\", menuItems).\n\tEventFunc(\"addItemForm\", addItemForm).\n\tEventFunc(\"portal1\", portal1).\n\tEventFunc(\"reloadAB\", reloadAB).\n\tEventFunc(\"updateCD\", updateCD)\n\nconst LazyPortalsAndReloadPath = \"/samples/lazy-portals-and-reload\"\n"'></highlightjs>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var LazyPortalsAndReload = Doc(
Markdown(`
Use ~web.Portal().EventFunc("menuItems").Name("menuContent")~ to put a portal place holder inside a part of html, and it will load specified event func's response body inside the place holder after the main page is rendered in a separate AJAX request. Later in an event func, you could also use ~r.ReloadPortals = []string{"menuContent"}~ to reload the portal.
Use ~web.Portal().Loader(web.POST().EventFunc("menuItems")).Name("menuContent")~ to put a portal place holder inside a part of html, and it will load specified event func's response body inside the place holder after the main page is rendered in a separate AJAX request. Later in an event func, you could also use ~r.ReloadPortals = []string{"menuContent"}~ to reload the portal.
`),
ch.Code(generated.LazyPortalsAndReloadSample).Language("go"),
utils.Demo("Lazy Portals", e17_hello_lazy_portals_and_reload.LazyPortalsAndReloadPath, "e17_hello_lazy_portals_and_reload/page.go"),
Expand Down

0 comments on commit 5d0ba28

Please sign in to comment.