Skip to content

Commit

Permalink
refactor: clean up unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Apr 3, 2022
1 parent 8b5b0ae commit 4273034
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 44 deletions.
27 changes: 0 additions & 27 deletions cmd/project-management/flags.go

This file was deleted.

4 changes: 0 additions & 4 deletions frontend/messages.go

This file was deleted.

4 changes: 4 additions & 0 deletions frontend/constants/const.go → tui/constants/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"github.com/charmbracelet/lipgloss"
)

// DocStyle styling for viewports
var DocStyle = lipgloss.NewStyle().Margin(1, 2)

// HelpStyle styling for help context menu
var HelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render

type keymap struct {
Expand All @@ -16,6 +19,7 @@ type keymap struct {
Back key.Binding
}

// Keymap reusable key mappings shared across models
var Keymap = keymap{
Create: key.NewBinding(
key.WithKeys("c"),
Expand Down
File renamed without changes.
8 changes: 7 additions & 1 deletion frontend/entryui/entry_view.go → tui/entryui/entry_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package entryui

import (
"github.com/bashbunni/project-management/entry"
"github.com/bashbunni/project-management/frontend/constants"
"github.com/bashbunni/project-management/tui/constants"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
Expand All @@ -15,8 +15,10 @@ var (
cmds []tea.Cmd
)

// BackMsg change state back to project view
type BackMsg bool

// Model entryui model
type Model struct {
viewport viewport.Model
er *entry.GormRepository
Expand All @@ -26,10 +28,12 @@ type Model struct {
error string
}

// Init run any intial IO on program start
func (m Model) Init() tea.Cmd {
return nil
}

// New initialize the entryui model for your program
func New(er *entry.GormRepository, activeProjectID uint, p *tea.Program) *Model {
m := Model{er: er, activeProjectID: activeProjectID}
vp := viewport.New(8, 8)
Expand All @@ -53,6 +57,7 @@ func New(er *entry.GormRepository, activeProjectID uint, p *tea.Program) *Model
return &m
}

// Update handle IO and commands
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
Expand Down Expand Up @@ -84,6 +89,7 @@ func (m Model) helpView() string {
return constants.HelpStyle("\n ↑/↓: navigate • esc: back • c: create entry • d: delete entry • q: quit\n")
}

// View return the text UI to be output to the terminal
func (m Model) View() string {
return constants.DocStyle.Render(m.viewport.View() + m.helpView())
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"log"

"github.com/bashbunni/project-management/entry"
"github.com/bashbunni/project-management/frontend/constants"
"github.com/bashbunni/project-management/project"
"github.com/bashbunni/project-management/tui/constants"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
Expand All @@ -14,17 +14,20 @@ import (

// TODO: add multi-page navigation

// SelectMsg the message to change the view to the selected entry
type SelectMsg struct {
ActiveProjectID uint
}

// Model the entryui model definition
type Model struct {
mode string
list list.Model
input textinput.Model
pr *project.GormRepository
}

// New initialize the projectui model for your program
func New(pr *project.GormRepository, er *entry.GormRepository) tea.Model {
input := textinput.New()
input.Prompt = "$ "
Expand Down Expand Up @@ -52,13 +55,14 @@ func newProjectList(pr *project.GormRepository) []list.Item {
log.Fatal(err)
}
return projectsToItems(projects)

}

// Init run any intial IO on program start
func (m Model) Init() tea.Cmd {
return nil
}

// Update handle IO and commands
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
var cmds []tea.Cmd
Expand Down Expand Up @@ -123,6 +127,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}

// View return the text UI to be output to the terminal
func (m Model) View() string {
if m.input.Focused() {
return constants.DocStyle.Render(m.list.View() + "\n" + m.input.View())
Expand All @@ -131,7 +136,7 @@ func (m Model) View() string {
}

// TODO: use generics
// convert []model.Project to []list.Item
// projectsToItems convert []model.Project to []list.Item
func projectsToItems(projects []project.Project) []list.Item {
items := make([]list.Item, len(projects))
for i, proj := range projects {
Expand Down
22 changes: 13 additions & 9 deletions frontend/tui.go → tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"os"

"github.com/bashbunni/project-management/entry"
"github.com/bashbunni/project-management/frontend/entryui"
"github.com/bashbunni/project-management/frontend/projectui"
"github.com/bashbunni/project-management/project"
"github.com/bashbunni/project-management/tui/entryui"
"github.com/bashbunni/project-management/tui/projectui"
tea "github.com/charmbracelet/bubbletea"
)

Expand All @@ -22,8 +22,8 @@ const (
entryView
)

// implements tea.Model (Init, Update, View)
type mainModel struct {
// MainModel the main model of the program; holds other models and bubbles
type MainModel struct {
state sessionState
project tea.Model
entry tea.Model
Expand Down Expand Up @@ -52,20 +52,23 @@ func StartTea(pr project.GormRepository, er entry.GormRepository) {
}
}

func New(pr *project.GormRepository, er *entry.GormRepository) mainModel {
return mainModel{
// New initialize the main model for your program
func New(pr *project.GormRepository, er *entry.GormRepository) MainModel {
return MainModel{
state: projectView,
project: projectui.New(pr, er),
pr: pr,
er: er,
}
}

func (m mainModel) Init() tea.Cmd {
// Init run any intial IO on program start
func (m MainModel) Init() tea.Cmd {
return nil
}

func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Update handle IO and commands
func (m MainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
var cmds []tea.Cmd
switch msg := msg.(type) {
Expand Down Expand Up @@ -99,7 +102,8 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}

func (m mainModel) View() string {
// View return the text UI to be output to the terminal
func (m MainModel) View() string {
switch m.state {
case entryView:
return m.entry.View()
Expand Down

0 comments on commit 4273034

Please sign in to comment.