wip: content query foundations

This commit is contained in:
decentral1se 2023-05-14 19:40:28 +02:00
parent 238adeb4dd
commit 5a2e20f0df
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410

View File

@ -81,6 +81,9 @@ type model struct {
datasheetsLoaded bool // Whether or not the datasheets are loaded or not datasheetsLoaded bool // Whether or not the datasheets are loaded or not
datasheetViewport viewport.Model // Viewport for the PDF content datasheetViewport viewport.Model // Viewport for the PDF content
datasheetViewportStyle lipgloss.Style // Style to show while showing datasheet viewport datasheetViewportStyle lipgloss.Style // Style to show while showing datasheet viewport
indexSpinner spinner.Model // Spinner to show that content indexes are being loaded
querySpinner spinner.Model // Spinner to show that content is being queried
} }
// datasheetFromName retrieves a datasheet via a name. // datasheetFromName retrieves a datasheet via a name.
@ -209,6 +212,18 @@ func (m model) Init() tea.Cmd {
) )
} }
// filterDatasheetContents filters datasheet by content from user input.
func filterDatasheetContents(m model) []string {
// TODO: implement indexing work beforehand
// wait for datasheetsLoaded to go true
// then iterate m.datasheets and index them
//
// for this function, catch 3 chars or more in the textinput
// start the query, fire the spinner and block any other queries
// coming in. return the list hits that come back from the query
return []string{}
}
// filterDatasheetNames filters datasheet names based on user input. // filterDatasheetNames filters datasheet names based on user input.
func filterDatasheetNames(m model) []string { func filterDatasheetNames(m model) []string {
search := m.input.Value() search := m.input.Value()
@ -246,7 +261,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
if m.input.Focused() && m.datasheetsLoaded { if m.input.Focused() && m.datasheetsLoaded {
if m.filterMode == filenameFilterMode {
m.filteredDatasheets = filterDatasheetNames(m) m.filteredDatasheets = filterDatasheetNames(m)
} else {
m.filteredDatasheets = filterDatasheetContents(m)
}
// TODO: implement cursor for scrolling up/down filtered // TODO: implement cursor for scrolling up/down filtered
// results so we can view the PDF contents as desired // results so we can view the PDF contents as desired