fix: fixed the infinite call loop in WidgetGo.Serve .
This commit is contained in:
parent
8b76e52e6f
commit
2d5acbd112
4 changed files with 8 additions and 2 deletions
|
@ -19,6 +19,10 @@ func ExtractSessionData(c tg.Context) *SessionData {
|
|||
return c.SessionData().(*SessionData)
|
||||
}
|
||||
|
||||
var BackWidget = tg.RenderFunc(func(c tg.Context) tg.UI{
|
||||
return c.GoRet(tg.Back)
|
||||
})
|
||||
|
||||
var beh = tg.NewBehaviour().SetInit(tg.Func(func(c tg.Context) {
|
||||
// The session initialization.
|
||||
c.SetSessionData(&SessionData{})
|
||||
|
|
|
@ -24,6 +24,7 @@ var StartWidget = tg.RenderFunc(func(c tg.Context) tg.UI {
|
|||
|
||||
tg.Messagef("Choose your interest").Reply(
|
||||
tg.NewKeyboard().List(
|
||||
tg.Buttonf("Back").Go(BackWidget),
|
||||
tg.Buttonf("Inc/Dec").Go(IncDecWidget),
|
||||
tg.Buttonf("Mutate messages").Go(MutateMessagesWidget),
|
||||
tg.Buttonf("Send location").Go(LocationWidget),
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
//"path"
|
||||
//"log"
|
||||
)
|
||||
|
||||
|
||||
|
@ -316,7 +317,7 @@ func (c Context) Go(pth Widget) error {
|
|||
|
||||
var back bool
|
||||
if pth == Back {
|
||||
if len(c.session.pathHistory) < 2 {
|
||||
if len(c.session.pathHistory) <= 1 {
|
||||
return c.Go(nil)
|
||||
}
|
||||
pth = c.session.pathHistory[len(c.session.pathHistory)-2]
|
||||
|
|
2
go.go
2
go.go
|
@ -21,7 +21,7 @@ func (w WidgetGo) Act(c Context) {
|
|||
// Implementing the Server interface.
|
||||
func (widget WidgetGo) Serve(c Context) {
|
||||
c.input.Close()
|
||||
c.Go(widget)
|
||||
c.WithArg(widget.Path).Go(widget.Path)
|
||||
}
|
||||
|
||||
func (widget WidgetGo) Render(c Context) UI {
|
||||
|
|
Loading…
Reference in a new issue