From 195a2912b7c67393b806dedb058590d8bc201186 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Tue, 26 Nov 2024 12:11:02 +0200 Subject: Added is private input to network creation --- internal/client/api/api.go | 1 + .../ui/core/networkcreation/networkcreation.go | 25 +++++++++++++++++++--- internal/data/models.go | 2 +- internal/data/networks.sql.go | 7 +++--- 4 files changed, 28 insertions(+), 7 deletions(-) (limited to 'internal') diff --git a/internal/client/api/api.go b/internal/client/api/api.go index 7fcde8b..d91de46 100644 --- a/internal/client/api/api.go +++ b/internal/client/api/api.go @@ -91,3 +91,4 @@ func GetUserById(id snowflake.ID) tea.Cmd { return fmt.Errorf("received invalid response from server: %v", response.Type()) } } + diff --git a/internal/client/ui/core/networkcreation/networkcreation.go b/internal/client/ui/core/networkcreation/networkcreation.go index 0c35dde..f0aad5e 100644 --- a/internal/client/ui/core/networkcreation/networkcreation.go +++ b/internal/client/ui/core/networkcreation/networkcreation.go @@ -38,9 +38,9 @@ var ( return lipgloss.JoinVertical(lipgloss.Left, s, underline) } - iconHeader = headerStyle.Bold(true).Render(" Icon: ") + iconHeader = headerStyle.Bold(true).Render("Icon: ") bgColorHeader = headerStyle.Bold(true).Render("BG # ") - fgColorHeader = headerStyle.Bold(true).Render("FG # ") + fgColorHeader = headerStyle.Bold(true).Render(" FG # ") blurredCreate = lipgloss.NewStyle(). Background(colors.Gray).Padding(0, 1).Render("Create Network") @@ -58,6 +58,7 @@ const ( FgColorField BgColorField IconField + PrivateField CreateField FieldCount ) @@ -69,6 +70,7 @@ type Model struct { icon textinput.Model bgColor textinput.Model fgColor textinput.Model + private bool create string selected int @@ -193,10 +195,20 @@ func (m Model) View() string { icon := lipgloss.JoinHorizontal(lipgloss.Top, fgColorText, bgColorText, iconText) + privateStyle := lipgloss.NewStyle().PaddingLeft(1) + if m.selected == PrivateField { + privateStyle = privateStyle.Foreground(colors.Focus) + } + private := "[ ] Private" + if m.private { + private = "[x] Private" + } + private = privateStyle.Render(private) + create := lipgloss.NewStyle().Width(m.nameWidth).Align(lipgloss.Center).Render(m.create) // create := m.create - content := flex.NewVertical(iconPreview, name, icon, create).WithGap(1).View() + content := flex.NewVertical(iconPreview, name, icon, private, create).WithGap(1).View() return style.Render(content) } @@ -293,6 +305,8 @@ func (m *Model) updateFocus() tea.Cmd { return m.bgColor.Focus() case FgColorField: return m.fgColor.Focus() + case PrivateField: + return nil case CreateField: m.create = focusedCreate return nil @@ -303,6 +317,11 @@ func (m *Model) updateFocus() tea.Cmd { } func (m *Model) Select() tea.Cmd { + if m.selected == PrivateField { + m.private = !m.private + return nil + } + if m.selected != CreateField { return nil } diff --git a/internal/data/models.go b/internal/data/models.go index fab7489..4bfb7a5 100644 --- a/internal/data/models.go +++ b/internal/data/models.go @@ -32,7 +32,7 @@ type Network struct { OwnerID snowflake.ID Name string Icon string - BgHexColor *string + BgHexColor string FgHexColor string IsPublic bool } diff --git a/internal/data/networks.sql.go b/internal/data/networks.sql.go index 4b9e390..d690b7b 100644 --- a/internal/data/networks.sql.go +++ b/internal/data/networks.sql.go @@ -16,7 +16,8 @@ INSERT INTO networks ( id, owner_id, name, is_public, icon, bg_hex_color, fg_hex_color ) VALUES ( - ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, + ?, ?, ? ) RETURNING id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public ` @@ -27,7 +28,7 @@ type CreateNetworkParams struct { Name string IsPublic bool Icon string - BgHexColor *string + BgHexColor string FgHexColor string } @@ -229,7 +230,7 @@ RETURNING id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public type SetNetworkIconParams struct { Icon string - BgHexColor *string + BgHexColor string FgHexColor string ID snowflake.ID } -- cgit v1.3.1