Change AddToast to use EventEnv instead of Event

This commit is contained in:
David Vogel 2023-05-29 13:39:39 +02:00
parent f8e63c9772
commit 37d42e9a94
4 changed files with 11 additions and 11 deletions

View File

@ -52,7 +52,7 @@ func (c *Container) handleToastClose(event vugu.DOMEvent, toast vugu.Builder) {
c.CloseToast(toast)
}
func (c *Container) AddToast(event vugu.DOMEvent, component vugu.Builder) {
func (c *Container) AddToast(eventEnv vugu.EventEnv, component vugu.Builder) {
toast := ContainerToast{
body: component,
signalClasses: "d3c-color-accent",
@ -67,8 +67,8 @@ func (c *Container) AddToast(event vugu.DOMEvent, component vugu.Builder) {
if durationGetter, ok := component.(ToastDurationGetter); ok && durationGetter.ToastDuration() > 0 {
go func(component vugu.Builder) {
time.Sleep(durationGetter.ToastDuration())
event.EventEnv().Lock()
defer event.EventEnv().UnlockRender()
eventEnv.Lock()
defer eventEnv.UnlockRender()
c.CloseToast(component)
}(component)
}

View File

@ -25,7 +25,7 @@ func (c *PageOverlays) handleSimpleModalButton(event vugu.DOMEvent) {
}
func (c *PageOverlays) handleSimpleToastButton(event vugu.DOMEvent) {
c.AddToast(event, &overlay.ToastSimple{
c.AddToast(event.EventEnv(), &overlay.ToastSimple{
IconSlot: &icons.LInfoCircle{AttrMap: vugu.AttrMap{"style": "font-size: 2em;"}},
Message: "This is a simple toast!\nIt supports multiple lines and has an icon slot.\nThere also can be multiple of it at the same time, this one was opened at " + time.Now().Format(time.TimeOnly) + ".",
SignalColor: "d3c-color-attention",
@ -33,7 +33,7 @@ func (c *PageOverlays) handleSimpleToastButton(event vugu.DOMEvent) {
}
func (c *PageOverlays) handleWarningToastButton(event vugu.DOMEvent) {
c.AddToast(event, &overlay.ToastSimple{
c.AddToast(event.EventEnv(), &overlay.ToastSimple{
IconSlot: &icons.LWarning{AttrMap: vugu.AttrMap{"style": "font-size: 2em;", "class": "d3c-color-caution d3c-icon-use-color"}},
Message: "This is a warning, be careful!",
SignalColor: "d3c-color-caution",
@ -41,11 +41,11 @@ func (c *PageOverlays) handleWarningToastButton(event vugu.DOMEvent) {
}
func (c *PageOverlays) handleToastMessageButton(event vugu.DOMEvent) {
c.AddToast(event, &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeCritical, Message: "Uh oh!"})
c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeCritical, Message: "Uh oh!"})
}
func (c *PageOverlays) handleToastMessageTimeoutButton(event vugu.DOMEvent) {
c.AddToast(event, &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeSuccess, Message: "That worked!", Duration: 5 * time.Second})
c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeSuccess, Message: "That worked!", Duration: 5 * time.Second})
}
func (c *PageOverlays) handleWaitOverlayButton(event vugu.DOMEvent) {

View File

@ -44,14 +44,14 @@
</ul>
<view:Code>
<pre vg-content='"func (c *PageOverlays) handleButton(event vugu.DOMEvent) {\n" +
" c.AddToast(event, &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeCritical, Message: \"Uh oh!\"})\n" +
" c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeCritical, Message: \"Uh oh!\"})\n" +
"}"' style="margin: 0;"></pre>
</view:Code>
<input:Button @Click="c.handleToastMessageButton(event)">Open message toast</input:Button>
<p>To let the toast close itself after some time, you can use the <view:CodeInline>Duration</view:CodeInline> option:</p>
<view:Code>
<pre vg-content='"func (c *PageOverlays) handleButton(event vugu.DOMEvent) {\n" +
" c.AddToast(event, &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeSuccess, Message: \"That worked!\", Duration: 5 * time.Second})\n" +
" c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeSuccess, Message: \"That worked!\", Duration: 5 * time.Second})\n" +
"}"' style="margin: 0;"></pre>
</view:Code>
<input:Button @Click="c.handleToastMessageTimeoutButton(event)">Open self closing message toast</input:Button>

View File

@ -564,7 +564,7 @@ func (c *PageOverlays) Build(vgin *vugu.BuildIn) (vgout *vugu.BuildOut) {
vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "pre", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "style", Val: "margin: 0;"}}}
vgparent.AppendChild(vgn)
vgn.SetInnerHTML("func (c *PageOverlays) handleButton(event vugu.DOMEvent) {\n" +
" c.AddToast(event, &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeCritical, Message: \"Uh oh!\"})\n" +
" c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeCritical, Message: \"Uh oh!\"})\n" +
"}")
vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n\t\t"}
vgparent.AppendChild(vgn)
@ -663,7 +663,7 @@ func (c *PageOverlays) Build(vgin *vugu.BuildIn) (vgout *vugu.BuildOut) {
vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "pre", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "style", Val: "margin: 0;"}}}
vgparent.AppendChild(vgn)
vgn.SetInnerHTML("func (c *PageOverlays) handleButton(event vugu.DOMEvent) {\n" +
" c.AddToast(event, &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeSuccess, Message: \"That worked!\", Duration: 5 * time.Second})\n" +
" c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeSuccess, Message: \"That worked!\", Duration: 5 * time.Second})\n" +
"}")
vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n\t\t"}
vgparent.AppendChild(vgn)