Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ross96D committed Sep 28, 2024
1 parent 3dbecc4 commit 3c00837
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/client/views/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
listcomp "github.com/ross96D/updater/cmd/client/components/list"
"github.com/ross96D/updater/cmd/client/components/toast"
"github.com/ross96D/updater/cmd/client/models"
"github.com/ross96D/updater/cmd/client/pretty"
"github.com/ross96D/updater/cmd/client/state"
)

Expand Down Expand Up @@ -52,6 +53,7 @@ func (model *app) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return model, tea.Batch(state.GlobalStateSyncCmd, state.SaveCmd)

case state.FetchResultMsg:
pretty.Print("fetchResult", msg.ServerName, msg.Server.Version.String())
index := model.state.Find(
func(s *models.Server) bool {
return s.ServerName == msg.ServerName
Expand Down
30 changes: 26 additions & 4 deletions cmd/client/views/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ross96D/updater/cmd/client/components/list"
"github.com/ross96D/updater/cmd/client/components/toast"
"github.com/ross96D/updater/cmd/client/models"
"github.com/ross96D/updater/cmd/client/pretty"
"github.com/ross96D/updater/cmd/client/state"
)

Expand Down Expand Up @@ -104,17 +105,38 @@ func (hv HomeView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !ok {
return hv, nil
}
return hv, func() tea.Msg {
session, err := api.NewSession(*item.Value)
upgCmd := func() tea.Msg {
server := *item.Value
pretty.Print("getting session ")
session, err := api.NewSession(server)
if err != nil {
return state.ErrFetchFailMsg{ServerName: item.Value.ServerName, Err: err}
pretty.Print("error getting session", err)
return state.ErrFetchFailMsg{ServerName: server.ServerName, Err: err}
}
pretty.Print("getted session, upgrading")
resp, err := session.Upgrade()
if err != nil {
pretty.Print("err upgrading")
return err
}
return toast.AddToastMsg(toast.New(resp))
pretty.Print("uprgrade done")
updateServerCmd := func() tea.Msg {
pretty.Print("starting udpdate of server")
s, err := session.List()
if err != nil {
pretty.Print("error on udpdate of server", err)
return state.ErrFetchFailCmd(server.ServerName, err)
}
pretty.Print("udpdate of server done")
return state.FetchResultMsg{ServerName: server.ServerName, Server: s}
}
return tea.Batch(Repeat(toast.AddToastMsg(toast.New(resp))), updateServerCmd)
}
addToastCmd := func() tea.Msg {
return toast.AddToastMsg(toast.New(
fmt.Sprintf("upgrading server %s", item.Value.ServerName)))
}
return hv, tea.Sequence(addToastCmd, upgCmd)

case state.GlobalStateSyncMsg:
hv.init()
Expand Down

0 comments on commit 3c00837

Please sign in to comment.