diff --git a/cmd/terminal-client/tui/basemodel.go b/cmd/terminal-client/tui/basemodel.go index 20ca649..26791ae 100644 --- a/cmd/terminal-client/tui/basemodel.go +++ b/cmd/terminal-client/tui/basemodel.go @@ -57,7 +57,10 @@ func (m baseModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, cmd) tmdbTab, cmd = NewTabTMDB(m.emdb, m.tmdb, m.logger) cmds = append(cmds, cmd) + reviewTab, cmd := NewTabReview(m.emdb, m.logger) + cmds = append(cmds, cmd) m.tabs.AddTab("emdb", "Watched movies", emdbTab) + m.tabs.AddTab("review", "Review", reviewTab) m.tabs.AddTab("tmdb", "TMDB", tmdbTab) m.initialized = true } diff --git a/cmd/terminal-client/tui/tabemdb.go b/cmd/terminal-client/tui/tabemdb.go index 32b8571..da0b95d 100644 --- a/cmd/terminal-client/tui/tabemdb.go +++ b/cmd/terminal-client/tui/tabemdb.go @@ -49,9 +49,7 @@ func NewTabEMDB(emdb *client.EMDB, logger *Logger) (tea.Model, tea.Cmd) { "Rating", "Comment", } - //if l == "Comment" { - // formInputs[i] = textarea.New() - //} + inputWatchedOn := textinput.New() inputWatchedOn.Prompt = "" inputWatchedOn.Width = 50 diff --git a/cmd/terminal-client/tui/tabreview.go b/cmd/terminal-client/tui/tabreview.go new file mode 100644 index 0000000..8913531 --- /dev/null +++ b/cmd/terminal-client/tui/tabreview.go @@ -0,0 +1,57 @@ +package tui + +import ( + "ewintr.nl/emdb/client" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" +) + +type tabReview struct { + initialized bool + emdb *client.EMDB + width int + height int + logger *Logger +} + +func NewTabReview(emdb *client.EMDB, logger *Logger) (tea.Model, tea.Cmd) { + return &tabReview{ + emdb: emdb, + logger: logger, + }, nil +} + +func (m *tabReview) Init() tea.Cmd { + return nil +} + +func (m *tabReview) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + var cmds []tea.Cmd + switch msg := msg.(type) { + case TabSizeMsg: + if !m.initialized { + m.initialized = true + } + m.width = msg.Width + m.height = msg.Height + case tea.KeyMsg: + switch msg.String() { + case "q", "esc", "ctrl+c": + return m, tea.Quit + case "right", "tab": + cmds = append(cmds, SelectNextTab()) + case "left", "shift+tab": + cmds = append(cmds, SelectPrevTab()) + } + } + + return m, tea.Batch(cmds...) +} + +func (m *tabReview) View() string { + return lipgloss.NewStyle(). + Width(m.width - 2). + Height(m.height - 2). + Padding(1). + Render("Review") +}