Started working on netwrok creation popup

This commit is contained in:
2024-11-24 00:16:23 +02:00
parent c17319d6fd
commit 54564f397d
6 changed files with 120 additions and 13 deletions

View File

@@ -18,7 +18,7 @@ import (
"github.com/kyren223/eko/internal/client/config"
"github.com/kyren223/eko/internal/client/ui"
authfield "github.com/kyren223/eko/internal/client/ui/auth/field"
authfield "github.com/kyren223/eko/internal/client/ui/field"
"github.com/kyren223/eko/internal/client/ui/choicepopup"
"github.com/kyren223/eko/internal/client/ui/core"
"github.com/kyren223/eko/pkg/assert"
@@ -471,7 +471,6 @@ func (m *Model) Signup() tea.Cmd {
return nil
}
return ui.Transition(core.New(privKey, username))
}
@@ -577,4 +576,3 @@ func expandPath(path string) string {
}
return path
}

View File

@@ -8,10 +8,12 @@ import (
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/timer"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/kyren223/eko/internal/client/gateway"
"github.com/kyren223/eko/internal/client/ui"
"github.com/kyren223/eko/internal/client/ui/core/networkcreation"
"github.com/kyren223/eko/internal/client/ui/core/networks"
"github.com/kyren223/eko/internal/client/ui/loadscreen"
"github.com/kyren223/eko/internal/client/ui/networks"
"github.com/kyren223/eko/pkg/snowflake"
)
@@ -27,25 +29,26 @@ type Model struct {
name string
privKey ed25519.PrivateKey
networks networks.Model
loading loadscreen.Model
timeout time.Duration
timer timer.Model
timeout time.Duration
connected bool
id snowflake.ID
networks networks.Model
networkCreationPopup *networkcreation.Model
}
func New(privKey ed25519.PrivateKey, name string) Model {
return Model{
name: name,
privKey: privKey,
loading: loadscreen.New(connectingToServer),
timeout: initialTimeout,
timer: newTimer(initialTimeout),
connected: false,
networks: networks.New(),
loading: loadscreen.New(connectingToServer),
timer: newTimer(initialTimeout),
timeout: initialTimeout,
connected: false,
}
}
@@ -58,7 +61,22 @@ func (m Model) View() string {
return m.loading.View()
}
return m.networks.View()
result := m.networks.View()
result = lipgloss.Place(
ui.Width, ui.Height,
lipgloss.Left, lipgloss.Top,
result,
)
if m.networkCreationPopup != nil {
popup := m.networkCreationPopup.View()
x := (ui.Width - lipgloss.Width(popup)) / 2
y := (ui.Height - lipgloss.Height(popup)) / 2
result = ui.PlaceOverlay(x, y, popup, result)
}
return result
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -101,7 +119,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
switch msg.(type) {
switch msg := msg.(type) {
case gateway.ConnectionLost:
m.connected = false
m.timeout = initialTimeout
@@ -109,6 +127,16 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case ui.QuitMsg:
gateway.Disconnect()
case tea.KeyMsg:
key := msg.Type
switch key {
case tea.KeyCtrlN:
if m.networkCreationPopup == nil {
popup := networkcreation.New()
m.networkCreationPopup = &popup
}
}
}
return m, nil

View File

@@ -0,0 +1,81 @@
package networkcreation
import (
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/kyren223/eko/internal/client/ui/field"
)
var (
style = lipgloss.NewStyle().Border(lipgloss.ThickBorder())
focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#5874FF"))
fieldBlurredStyle = lipgloss.NewStyle().
PaddingLeft(1).
Border(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.Color("#007E8A"))
fieldFocusedStyle = fieldBlurredStyle.BorderForeground(focusedStyle.GetForeground()).Border(lipgloss.ThickBorder())
headerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#54D7A9"))
iconStyle = lipgloss.NewStyle().Border(lipgloss.ThickBorder(), false, false, true, false)
)
type Model struct {
Width int
Height int
name field.Model
icon textinput.Model
color textinput.Model
Style lipgloss.Style
}
func New() Model {
name := field.New(30)
name.Header = "Network Name"
name.HeaderStyle = headerStyle
name.FocusedStyle = fieldFocusedStyle
name.BlurredStyle = fieldBlurredStyle
name.Focus()
icon := textinput.New()
icon.Prompt = ""
icon.Placeholder = "ic"
color := textinput.New()
color.Prompt = ""
color.Placeholder = "000000"
return Model{
Width: 50,
Height: 10,
name: name,
icon: icon,
color: color,
Style: style,
}
}
func (m Model) Init() tea.Cmd {
return nil
}
func (m Model) View() string {
name := m.name.View()
iconText := lipgloss.JoinHorizontal(lipgloss.Top, "icon: ", iconStyle.Render(m.icon.View()))
iconColor := lipgloss.JoinHorizontal(lipgloss.Top, "# ", iconStyle.Render(m.color.View()))
icon := lipgloss.JoinHorizontal(lipgloss.Top, iconText, " ", iconColor)
content := lipgloss.JoinVertical(lipgloss.Left, name, "\n", icon)
popup := lipgloss.NewStyle().Width(m.Width).Height(m.Height).Render(content)
return m.Style.Render(popup)
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}

View File

@@ -48,7 +48,7 @@ func SendMessage(ctx context.Context, request *packet.SendMessage) packet.Payloa
func GetMessages(ctx context.Context, request *packet.GetMessagesRange) packet.Payload {
queries := data.New(db)
messages, err := queries.ListMessages(ctx)
messages, err := queries.GetFrequencyMessages(ctx, request.FrequencyID)
if err != nil {
log.Println("database error when retrieving messages:", err)
return &packet.ErrorMessage{Error: "internal server error"}