Remove duplicate browser state and fix sort mode toggle
- Remove currentBrowserState global and SetBrowserState from browser package - Browser now receives sortHandler as a parameter instead of using global state - Fix sort mode toggle: reload pages after clearing cache (was showing 'Loading...') - Add String() methods to all UI element types for debugging - Add e2e tests for sort mode functionality (5 tests) The editor now owns all state; the browser is a pure function receiving state and handlers through parameters.
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
)
|
||||
|
||||
// BrowserLayout computes the element tree for the browser (file listing) page.
|
||||
// Pure function: (screen dimensions, browser state) → []ui.Element
|
||||
func BrowserLayout(screenW, screenH ui.Dp, state *BrowserState) []ui.Element {
|
||||
// Pure function: (screen dimensions, browser state, sort handler) → []ui.Element
|
||||
func BrowserLayout(screenW, screenH ui.Dp, state *BrowserState, sortHandler func(any)) []ui.Element {
|
||||
margin := ui.Dp(10)
|
||||
contentWidth := screenW - margin*2
|
||||
|
||||
@@ -23,7 +23,7 @@ func BrowserLayout(screenW, screenH ui.Dp, state *BrowserState) []ui.Element {
|
||||
[]ui.Element{
|
||||
ui.NewLabel(state.CurrentPath, 14, ui.Region{X: 0, Y: 0, W: contentWidth, H: headerHeight}, ui.AlignStart, "", nil),
|
||||
ui.NewLabel(sortLabel, 12, ui.Region{X: 0, Y: 0, W: contentWidth, H: headerHeight}, ui.AlignEnd, "sort",
|
||||
[]ui.Interaction{{Gesture: ui.Tap, Handler: ToggleSortOrder}}),
|
||||
[]ui.Interaction{{Gesture: ui.Tap, Handler: sortHandler}}),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -94,23 +94,7 @@ func sortModeLabel(mode SortMode) string {
|
||||
}
|
||||
}
|
||||
|
||||
// ToggleSortOrder cycles the browser sort mode through four modes.
|
||||
func ToggleSortOrder(data any) {
|
||||
if currentBrowserState == nil {
|
||||
return
|
||||
}
|
||||
currentBrowserState.SortMode = (currentBrowserState.SortMode + 1) % 4
|
||||
currentBrowserState.ScrollIndex = 0 // reset scroll on sort change
|
||||
}
|
||||
|
||||
// currentBrowserState is set by the editor before calling BrowserLayout.
|
||||
// Used by handlers that need access to the browser state.
|
||||
var currentBrowserState *BrowserState
|
||||
|
||||
// SetBrowserState sets the global browser state reference for handlers.
|
||||
func SetBrowserState(s *BrowserState) {
|
||||
currentBrowserState = s
|
||||
}
|
||||
|
||||
// ComputeVisibleEntriesForTest is exported for testing purposes.
|
||||
// It builds the list of ui.ListItem entries that should be rendered.
|
||||
|
||||
Reference in New Issue
Block a user