|
@ -275,6 +275,16 @@ func filterDatasheetNames(m model) []string { |
|
|
return m.datasheetNames |
|
|
return m.datasheetNames |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// setViewport sets the viewport content.
|
|
|
|
|
|
func (m *model) setViewport() { |
|
|
|
|
|
if len(m.filteredDatasheets) == 0 { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
lastDatasheet := m.filteredDatasheets[len(m.filteredDatasheets)-1] |
|
|
|
|
|
viewportText := m.datasheetFromName(lastDatasheet) |
|
|
|
|
|
m.datasheetViewport.SetContent(viewportText) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Update updates the program state.
|
|
|
// Update updates the program state.
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
|
|
var ( |
|
|
var ( |
|
@ -291,19 +301,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
|
|
m.loadDatasheetSpinner, cmd = m.loadDatasheetSpinner.Update(msg) |
|
|
m.loadDatasheetSpinner, cmd = m.loadDatasheetSpinner.Update(msg) |
|
|
cmds = append(cmds, cmd) |
|
|
cmds = append(cmds, cmd) |
|
|
|
|
|
|
|
|
|
|
|
// TODO: implement cursor for scrolling up/down filtered
|
|
|
|
|
|
// results so we can view the PDF contents as desired
|
|
|
|
|
|
// it's currently just the last one (closest to input)
|
|
|
if m.input.Focused() && m.datasheetsLoaded { |
|
|
if m.input.Focused() && m.datasheetsLoaded { |
|
|
if m.filterMode == filenameFilterMode { |
|
|
if m.filterMode == filenameFilterMode { |
|
|
m.filteredDatasheets = filterDatasheetNames(m) |
|
|
m.filteredDatasheets = filterDatasheetNames(m) |
|
|
} else { |
|
|
} else { |
|
|
m.filteredDatasheets = filterDatasheetContents(m) |
|
|
m.filteredDatasheets = filterDatasheetContents(m) |
|
|
} |
|
|
} |
|
|
|
|
|
m.setViewport() |
|
|
// TODO: implement cursor for scrolling up/down filtered
|
|
|
|
|
|
// results so we can view the PDF contents as desired
|
|
|
|
|
|
// it's currently just the last one (closest to input)
|
|
|
|
|
|
lastDatasheet := m.filteredDatasheets[len(m.filteredDatasheets)-1] |
|
|
|
|
|
viewportText := m.datasheetFromName(lastDatasheet) |
|
|
|
|
|
m.datasheetViewport.SetContent(viewportText) |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
switch msg := msg.(type) { |
|
|
switch msg := msg.(type) { |
|
@ -311,10 +318,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
|
|
m.datasheets = msg.datasheets |
|
|
m.datasheets = msg.datasheets |
|
|
m.datasheetNames = msg.datasheetNames |
|
|
m.datasheetNames = msg.datasheetNames |
|
|
m.filteredDatasheets = msg.datasheetNames |
|
|
m.filteredDatasheets = msg.datasheetNames |
|
|
|
|
|
m.setViewport() |
|
|
selectedDatasheet := msg.datasheets[len(msg.datasheets)-1] |
|
|
|
|
|
m.datasheetViewport.SetContent(selectedDatasheet.contents) |
|
|
|
|
|
|
|
|
|
|
|
m.datasheetsLoaded = true |
|
|
m.datasheetsLoaded = true |
|
|
case peerDiscoveredMsg: |
|
|
case peerDiscoveredMsg: |
|
|
m.peers = msg.discovered |
|
|
m.peers = msg.discovered |
|
@ -328,6 +332,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
|
|
return m, tea.Quit |
|
|
return m, tea.Quit |
|
|
case "tab": |
|
|
case "tab": |
|
|
m.toggleFilterMode() |
|
|
m.toggleFilterMode() |
|
|
|
|
|
case "enter": |
|
|
|
|
|
// TODO: fire content search query
|
|
|
case "o": |
|
|
case "o": |
|
|
selectedDatasheet := m.datasheets[len(m.datasheets)-1] |
|
|
selectedDatasheet := m.datasheets[len(m.datasheets)-1] |
|
|
// TODO: handle error
|
|
|
// TODO: handle error
|
|
|