feat(browser): Implement lazy loading and E2E tests for browser

This commit is contained in:
gmp
2026-06-01 20:37:59 -04:00
parent 3a2e21e4b3
commit 94db42d2ad
4 changed files with 588 additions and 20 deletions
+8 -20
View File
@@ -44,6 +44,7 @@ type ResultEvent struct {
// Logic runs the logic goroutine and provides channels for communication.
type Logic struct {
state *State
browserManager *browser.BrowserManager // Add this field
configChan chan ConfigUpdate
frameChan chan []ui.Element
inputChan chan []ui.InputEvent
@@ -71,9 +72,11 @@ func NewLogic() *Logic {
// Set browser initial path to mock root
state.Browser.CurrentPath = "/"
bm, _ := browser.NewBrowserManager(&state.Browser, wp, mockFS)
return &Logic{
state: state,
browserManager: bm, // Add to struct
configChan: make(chan ConfigUpdate),
frameChan: make(chan []ui.Element),
inputChan: make(chan []ui.InputEvent),
@@ -168,40 +171,25 @@ func (l *Logic) Run() {
// handleWorkerResult processes results from the worker pool.
func (l *Logic) handleWorkerResult(res pool.Result) {
switch res.TaskType {
case pool.TypeBuildIndex:
l.applyBuildIndexResult(res)
case pool.TypeLoadPages:
l.applyLoadPagesResult(res)
case pool.TypeReadDir:
l.applyReadDirResult(res)
if res.IsBrowserResult() {
l.browserManager.HandleResult(res)
}
l.frameChan <- l.state.layout()
}
// applyBuildIndexResult applies a completed BuildIndexTask result to browser state.
func (l *Logic) applyBuildIndexResult(res pool.Result) {
if !res.Success {
return
}
// Convert mock DirEntry results to browser entries
if entries, ok := res.Data.([]mock.DirEntry); ok {
l.state.Browser.TotalEntries = len(entries)
// Build the in-memory index with position maps
l.state.Browser.SortIndex = buildBrowserIndex(entries)
// Load initial visible pages from the index into the Pages map
browser.LoadInitialPages(&l.state.Browser)
}
// Delegated to browserManager
}
// applyLoadPagesResult applies a completed LoadPagesTask result to browser state.
func (l *Logic) applyLoadPagesResult(res pool.Result) {
_ = res // TODO: implement page loading from worker results
// Delegated to browserManager
}
// applyReadDirResult applies a completed ReadDirTask result to browser state.
func (l *Logic) applyReadDirResult(res pool.Result) {
_ = res // TODO: implement directory read result handling
// Delegated to browserManager
}
// State returns the current state.