summaryrefslogtreecommitdiff
path: root/internal/client/ui/core/core.go
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2025-01-04 16:59:44 +0200
committerKyren223 <Kyren223@proton.me>2025-01-04 16:59:44 +0200
commitfeb8562dd0b6a0ec35781e80756dc3761e6b1ade (patch)
tree997d5f5ef0f051f06f00148b30cd00a4e9a93f7a /internal/client/ui/core/core.go
parent1b15db0fe9263d52ec0063f0dce2cfdd197c00fd (diff)
Implmented Ui for network joining
Diffstat (limited to 'internal/client/ui/core/core.go')
-rw-r--r--internal/client/ui/core/core.go40
1 files changed, 32 insertions, 8 deletions
diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go
index 46eaca5..3048375 100644
--- a/internal/client/ui/core/core.go
+++ b/internal/client/ui/core/core.go
@@ -18,6 +18,7 @@ import (
"github.com/kyren223/eko/internal/client/ui/core/frequencycreation"
"github.com/kyren223/eko/internal/client/ui/core/frequencylist"
"github.com/kyren223/eko/internal/client/ui/core/networkcreation"
+ "github.com/kyren223/eko/internal/client/ui/core/networkjoin"
"github.com/kyren223/eko/internal/client/ui/core/networklist"
"github.com/kyren223/eko/internal/client/ui/core/state"
"github.com/kyren223/eko/internal/client/ui/loadscreen"
@@ -53,6 +54,7 @@ type Model struct {
connected bool
networkCreationPopup *networkcreation.Model
+ networkJoinPopup *networkjoin.Model
frequencyCreationPopup *frequencycreation.Model
networkList networklist.Model
frequencyList frequencylist.Model
@@ -70,6 +72,7 @@ func New(privKey ed25519.PrivateKey, name string) Model {
timeout: initialTimeout,
connected: false,
networkCreationPopup: nil,
+ networkJoinPopup: nil,
frequencyCreationPopup: nil,
networkList: networklist.New(),
frequencyList: frequencylist.New(),
@@ -106,6 +109,8 @@ func (m Model) View() string {
popup = m.networkCreationPopup.View()
} else if m.frequencyCreationPopup != nil {
popup = m.frequencyCreationPopup.View()
+ } else if m.networkJoinPopup != nil {
+ popup = m.networkJoinPopup.View()
}
if popup != "" {
x := (ui.Width - lipgloss.Width(popup)) / 2
@@ -238,12 +243,11 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd {
}
case tea.KeyMsg:
- key := msg.Type
- switch key {
- case tea.KeyCtrlN:
+ switch msg.String() {
+ case "n":
switch m.focus {
case FocusNetworkList:
- if m.networkCreationPopup == nil {
+ if m.networkCreationPopup == nil && m.networkJoinPopup == nil {
popup := networkcreation.New()
m.networkCreationPopup = &popup
}
@@ -256,14 +260,22 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd {
}
}
- case tea.KeyEscape:
+ case "i":
+ if m.focus == FocusNetworkList && m.networkJoinPopup == nil && m.networkCreationPopup == nil {
+ popup := networkjoin.New()
+ m.networkJoinPopup = &popup
+ }
+
+ case "esc":
if m.networkCreationPopup != nil {
m.networkCreationPopup = nil
} else if m.frequencyCreationPopup != nil {
m.frequencyCreationPopup = nil
+ } else if m.networkJoinPopup != nil {
+ m.networkJoinPopup = nil
}
- case tea.KeyEnter:
+ case "enter":
if m.networkCreationPopup != nil {
cmd := m.networkCreationPopup.Select()
if cmd != nil {
@@ -276,6 +288,12 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd {
m.frequencyCreationPopup = nil
}
return cmd
+ } else if m.networkJoinPopup != nil {
+ cmd := m.networkJoinPopup.Select()
+ if cmd != nil {
+ m.networkJoinPopup = nil
+ }
+ return cmd
}
default:
@@ -287,6 +305,10 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd {
popup, cmd := m.frequencyCreationPopup.Update(msg)
m.frequencyCreationPopup = &popup
return cmd
+ } else if m.networkJoinPopup != nil {
+ popup, cmd := m.networkJoinPopup.Update(msg)
+ m.networkJoinPopup = &popup
+ return cmd
}
if m.focus != FocusChat || !m.chat.Locked() {
@@ -303,8 +325,10 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd {
}
}
- inPopup := m.networkCreationPopup != nil || m.frequencyCreationPopup != nil
- if inPopup {
+ isPopup := m.networkCreationPopup != nil ||
+ m.frequencyCreationPopup != nil ||
+ m.networkJoinPopup != nil
+ if isPopup {
return nil
}