summaryrefslogtreecommitdiff
path: root/internal/client
diff options
context:
space:
mode:
Diffstat (limited to 'internal/client')
-rw-r--r--internal/client/ui/core/core.go18
-rw-r--r--internal/client/ui/core/state/state.go7
2 files changed, 18 insertions, 7 deletions
diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go
index 737029f..98158b3 100644
--- a/internal/client/ui/core/core.go
+++ b/internal/client/ui/core/core.go
@@ -3,6 +3,8 @@ package core
import (
"crypto/ed25519"
"fmt"
+ "log"
+ "slices"
"time"
"github.com/charmbracelet/bubbles/spinner"
@@ -138,8 +140,20 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd {
return tea.Batch(gateway.Connect(m.privKey, connectionTimeout), m.loading.Init())
case *packet.NetworksInfo:
- for _, network := range msg.Networks {
- state.State.Networks[network.ID] = network
+ if msg.Set {
+ state.State.Networks = msg.Networks
+ } else {
+ // state.State.Networks = append(state.State.Networks, msg.Networks...)
+ networks := state.State.Networks
+ networks = append(networks, msg.Networks...)
+ networks = slices.DeleteFunc(networks, func(network packet.FullNetwork) bool {
+ return slices.Contains(msg.RemoveNetworks, network.ID)
+ })
+ slices.SortFunc(networks, func(a, b packet.FullNetwork) int {
+ return a.Position - b.Position
+ })
+ log.Println(networks)
+ state.State.Networks = networks
}
case ui.QuitMsg:
diff --git a/internal/client/ui/core/state/state.go b/internal/client/ui/core/state/state.go
index eeba245..e40cdc9 100644
--- a/internal/client/ui/core/state/state.go
+++ b/internal/client/ui/core/state/state.go
@@ -2,13 +2,10 @@ package state
import (
"github.com/kyren223/eko/internal/packet"
- "github.com/kyren223/eko/pkg/snowflake"
)
type state struct {
- Networks map[snowflake.ID]packet.FullNetwork
+ Networks []packet.FullNetwork
}
-var State state = state{
- Networks: make(map[snowflake.ID]packet.FullNetwork),
-}
+var State state = state{}