scrolling review
This commit is contained in:
parent
91e44b9c8d
commit
bcdee2bdb1
|
@ -9,6 +9,7 @@ import (
|
||||||
"ewintr.nl/emdb/cmd/api-service/moviestore"
|
"ewintr.nl/emdb/cmd/api-service/moviestore"
|
||||||
"github.com/charmbracelet/bubbles/textarea"
|
"github.com/charmbracelet/bubbles/textarea"
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
|
"github.com/charmbracelet/bubbles/viewport"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
@ -20,6 +21,7 @@ type tabReview struct {
|
||||||
height int
|
height int
|
||||||
mode string
|
mode string
|
||||||
selectedReview moviestore.Review
|
selectedReview moviestore.Review
|
||||||
|
reviewViewport viewport.Model
|
||||||
inputQuality textinput.Model
|
inputQuality textinput.Model
|
||||||
inputMentions textarea.Model
|
inputMentions textarea.Model
|
||||||
formFocus int
|
formFocus int
|
||||||
|
@ -27,6 +29,9 @@ type tabReview struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTabReview(emdb *client.EMDB, logger *Logger) (tea.Model, tea.Cmd) {
|
func NewTabReview(emdb *client.EMDB, logger *Logger) (tea.Model, tea.Cmd) {
|
||||||
|
reviewViewport := viewport.New(0, 0)
|
||||||
|
//reviewViewport.KeyMap = viewport.KeyMap{}
|
||||||
|
|
||||||
inputQuality := textinput.New()
|
inputQuality := textinput.New()
|
||||||
inputQuality.Prompt = ""
|
inputQuality.Prompt = ""
|
||||||
inputQuality.Width = 50
|
inputQuality.Width = 50
|
||||||
|
@ -39,6 +44,7 @@ func NewTabReview(emdb *client.EMDB, logger *Logger) (tea.Model, tea.Cmd) {
|
||||||
return &tabReview{
|
return &tabReview{
|
||||||
emdb: emdb,
|
emdb: emdb,
|
||||||
mode: "view",
|
mode: "view",
|
||||||
|
reviewViewport: reviewViewport,
|
||||||
inputQuality: inputQuality,
|
inputQuality: inputQuality,
|
||||||
inputMentions: inputMentions,
|
inputMentions: inputMentions,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
@ -50,6 +56,7 @@ func (m *tabReview) Init() tea.Cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *tabReview) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m *tabReview) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
var cmd tea.Cmd
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case TabSizeMsg:
|
case TabSizeMsg:
|
||||||
|
@ -58,6 +65,8 @@ func (m *tabReview) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
}
|
}
|
||||||
m.width = msg.Width
|
m.width = msg.Width
|
||||||
m.height = msg.Height
|
m.height = msg.Height
|
||||||
|
m.reviewViewport.Width = (m.width / 2) - 2
|
||||||
|
m.reviewViewport.Height = m.height - 2
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch m.mode {
|
switch m.mode {
|
||||||
case "edit":
|
case "edit":
|
||||||
|
@ -89,11 +98,19 @@ func (m *tabReview) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
m.logger.Log("fetching next unrated review")
|
m.logger.Log("fetching next unrated review")
|
||||||
cmds = append(cmds, m.inputQuality.Focus())
|
cmds = append(cmds, m.inputQuality.Focus())
|
||||||
cmds = append(cmds, FetchNextUnratedReview(m.emdb))
|
cmds = append(cmds, FetchNextUnratedReview(m.emdb))
|
||||||
|
default:
|
||||||
|
m.logger.Log(fmt.Sprintf("key: %s", msg.String()))
|
||||||
|
m.reviewViewport, cmd = m.reviewViewport.Update(msg)
|
||||||
|
cmds = append(cmds, cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case moviestore.Review:
|
case moviestore.Review:
|
||||||
m.logger.Log(fmt.Sprintf("got review %s", msg.ID))
|
m.logger.Log(fmt.Sprintf("got review %s", msg.ID))
|
||||||
m.selectedReview = msg
|
m.selectedReview = msg
|
||||||
|
review := strings.ReplaceAll(m.selectedReview.Review, "\n", "\n\n")
|
||||||
|
review = lipgloss.NewStyle().Width((m.width / 2) - 2).Render(review)
|
||||||
|
m.reviewViewport.SetContent(review)
|
||||||
|
m.reviewViewport.GotoTop()
|
||||||
m.UpdateForm()
|
m.UpdateForm()
|
||||||
case ReviewStored:
|
case ReviewStored:
|
||||||
m.logger.Log(fmt.Sprintf("stored review %s", msg))
|
m.logger.Log(fmt.Sprintf("stored review %s", msg))
|
||||||
|
@ -179,9 +196,7 @@ func (m *tabReview) ViewForm() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *tabReview) ViewReview() string {
|
func (m *tabReview) ViewReview() string {
|
||||||
review := strings.ReplaceAll(m.selectedReview.Review, "\n", "\n\n")
|
return m.reviewViewport.View()
|
||||||
|
|
||||||
return review
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *tabReview) StoreReview() tea.Cmd {
|
func (m *tabReview) StoreReview() tea.Cmd {
|
||||||
|
|
Loading…
Reference in New Issue