Modern Apps git

← Modern-Apps.git

web: MA search kinds as sibling routes with swipe

Commit
7f1e1b6d05d8d40695f0305ff7dcfb8378c6029b
Author
Vayun Mathur <[email protected]>
When
2026-12-06 04:24 UTC (8 hours ago)
Parents
18186c4
Route.SearchText / SearchImages / SearchNews (each carrying the
query) are sibling routes under the Browser tab, hosted by a nested
MainNavigation inside SearchResultsPage with a SwipeRouteHost tab
row. Swipe/tab replaces the sibling on the nested stack, Back
returns to browsing, and the browser chrome outside the host never
moves. The tab pseudo-URL stays the parent: nativeSearchUrl gains a
kind parameter and nativeSearchKind resolves it, so a search deep
link lands on the requested sibling (old URLs default to Text).
Each text-like kind keeps its own fetch slot in a remembered
per-query SearchKindStates holder, so switching routes loses no
response/page state and a reply only ever writes its own kind's
slot - the shared-slot tab race stays gone by construction; Images
keeps its own paginated fetch. SearchImages is screenshot-exempt
(live network fetch); Text and News gain previews. Metadata
regenerated.

Verified: :web:lint, :web:lintVitalRelease and :web:testDevUnitTest
pass; :web:metadata regenerated.

Diff

metadata_data/photos/web/large-tablet/1.png
diff --git a/metadata_data/photos/web/large-tablet/1.png b/metadata_data/photos/web/large-tablet/1.pngindex dc8660f6fa..c5885e430b 100644Binary files a/metadata_data/photos/web/large-tablet/1.png and b/metadata_data/photos/web/large-tablet/1.png differ
metadata_data/photos/web/phone/1.png
diff --git a/metadata_data/photos/web/phone/1.png b/metadata_data/photos/web/phone/1.pngindex 94adb79eca..f90e39de86 100644Binary files a/metadata_data/photos/web/phone/1.png and b/metadata_data/photos/web/phone/1.png differ
metadata_data/photos/web/phone/10.png
diff --git a/metadata_data/photos/web/phone/10.png b/metadata_data/photos/web/phone/10.pngnew file mode 100644index 0000000000..39c395e3c0Binary files /dev/null and b/metadata_data/photos/web/phone/10.png differ
metadata_data/photos/web/phone/11.png
diff --git a/metadata_data/photos/web/phone/11.png b/metadata_data/photos/web/phone/11.pngnew file mode 100644index 0000000000..2569c4a878Binary files /dev/null and b/metadata_data/photos/web/phone/11.png differ
metadata_data/photos/web/phone/12.png
diff --git a/metadata_data/photos/web/phone/12.png b/metadata_data/photos/web/phone/12.pngnew file mode 100644index 0000000000..2bbb752fd3Binary files /dev/null and b/metadata_data/photos/web/phone/12.png differ
metadata_data/photos/web/phone/13.png
diff --git a/metadata_data/photos/web/phone/13.png b/metadata_data/photos/web/phone/13.pngnew file mode 100644index 0000000000..b182ea2ddcBinary files /dev/null and b/metadata_data/photos/web/phone/13.png differ
metadata_data/photos/web/phone/14.png
diff --git a/metadata_data/photos/web/phone/14.png b/metadata_data/photos/web/phone/14.pngnew file mode 100644index 0000000000..44f7daf50eBinary files /dev/null and b/metadata_data/photos/web/phone/14.png differ
metadata_data/photos/web/phone/15.png
diff --git a/metadata_data/photos/web/phone/15.png b/metadata_data/photos/web/phone/15.pngnew file mode 100644index 0000000000..491ffc45a1Binary files /dev/null and b/metadata_data/photos/web/phone/15.png differ
metadata_data/photos/web/phone/16.png
diff --git a/metadata_data/photos/web/phone/16.png b/metadata_data/photos/web/phone/16.pngnew file mode 100644index 0000000000..840ef3c4e4Binary files /dev/null and b/metadata_data/photos/web/phone/16.png differ
metadata_data/photos/web/phone/17.png
diff --git a/metadata_data/photos/web/phone/17.png b/metadata_data/photos/web/phone/17.pngnew file mode 100644index 0000000000..96884ad5edBinary files /dev/null and b/metadata_data/photos/web/phone/17.png differ
metadata_data/photos/web/phone/18.png
diff --git a/metadata_data/photos/web/phone/18.png b/metadata_data/photos/web/phone/18.pngnew file mode 100644index 0000000000..0c7091d6fcBinary files /dev/null and b/metadata_data/photos/web/phone/18.png differ
metadata_data/photos/web/phone/2.png
diff --git a/metadata_data/photos/web/phone/2.png b/metadata_data/photos/web/phone/2.pngindex 610dbba461..74b36e3dff 100644Binary files a/metadata_data/photos/web/phone/2.png and b/metadata_data/photos/web/phone/2.png differ
metadata_data/photos/web/phone/3.png
diff --git a/metadata_data/photos/web/phone/3.png b/metadata_data/photos/web/phone/3.pngindex b182ea2ddc..a1886be514 100644Binary files a/metadata_data/photos/web/phone/3.png and b/metadata_data/photos/web/phone/3.png differ
metadata_data/photos/web/phone/4.png
diff --git a/metadata_data/photos/web/phone/4.png b/metadata_data/photos/web/phone/4.pngnew file mode 100644index 0000000000..7152cb91e5Binary files /dev/null and b/metadata_data/photos/web/phone/4.png differ
metadata_data/photos/web/phone/5.png
diff --git a/metadata_data/photos/web/phone/5.png b/metadata_data/photos/web/phone/5.pngnew file mode 100644index 0000000000..007b8e20caBinary files /dev/null and b/metadata_data/photos/web/phone/5.png differ
metadata_data/photos/web/phone/6.png
diff --git a/metadata_data/photos/web/phone/6.png b/metadata_data/photos/web/phone/6.pngnew file mode 100644index 0000000000..9906013681Binary files /dev/null and b/metadata_data/photos/web/phone/6.png differ
metadata_data/photos/web/phone/7.png
diff --git a/metadata_data/photos/web/phone/7.png b/metadata_data/photos/web/phone/7.pngnew file mode 100644index 0000000000..b67ec57baeBinary files /dev/null and b/metadata_data/photos/web/phone/7.png differ
metadata_data/photos/web/phone/8.png
diff --git a/metadata_data/photos/web/phone/8.png b/metadata_data/photos/web/phone/8.pngnew file mode 100644index 0000000000..c33140fbd0Binary files /dev/null and b/metadata_data/photos/web/phone/8.png differ
metadata_data/photos/web/phone/9.png
diff --git a/metadata_data/photos/web/phone/9.png b/metadata_data/photos/web/phone/9.pngnew file mode 100644index 0000000000..272a0b3754Binary files /dev/null and b/metadata_data/photos/web/phone/9.png differ
web/AGENTS.md
diff --git a/web/AGENTS.md b/web/AGENTS.mdindex b301e01480..0ecc271977 100644--- a/web/AGENTS.md+++ b/web/AGENTS.md@@ -87,6 +87,7 @@ _Install: ./install web (dev by default)._ - com/vayunmathur/web/ui/BookmarksPage.kt - com/vayunmathur/web/ui/HistoryPage.kt, HistoryContent.kt, DownloadsPage.kt, DownloadsContent.kt, InstalledSitesPage.kt, InstalledSitesContent.kt — page hosts + stateless screenshot slices - com/vayunmathur/web/ui/PermissionSheets.kt, SiteDataContent.kt — permission sheets + stateless site-data slice+- com/vayunmathur/web/ui/SearchResultsPage.kt — MA Search sibling routes (`Route.SearchText/SearchImages/SearchNews` over one query, nested nav host under the Browser tab; per-kind fetch slots in `SearchKindStates`) - com/vayunmathur/web/ui/SettingsPage.kt, SettingsContent.kt, ShieldsPanel.kt, ShieldsContent.kt — settings/shields hosts + stateless slices - com/vayunmathur/web/ui/WebDialogEntries.kt — `DialogPage()` entries for the seven dialog routes - com/vayunmathur/web/ui/components/SiteIcon.kt
web/src/main/java/com/vayunmathur/web/Route.kt
diff --git a/web/src/main/java/com/vayunmathur/web/Route.kt b/web/src/main/java/com/vayunmathur/web/Route.ktindex 427f78a6a4..e1d38e7d62 100644--- a/web/src/main/java/com/vayunmathur/web/Route.kt+++ b/web/src/main/java/com/vayunmathur/web/Route.kt@@ -3,6 +3,7 @@ package com.vayunmathur.web import com.vayunmathur.library.util.NavKey import kotlinx.serialization.Serializable +// SCREENSHOT COVERAGE EXCEPTION: SearchImages: image results own a live paginated network fetch; no stateless slice for Layoutlib /** Contract for route. */ @Serializable sealed interface Route : NavKey {@@ -20,6 +21,17 @@ sealed interface Route : NavKey {     @Serializable data object SiteData : Route     /** Installed sites (PWAs) route. */     @Serializable data object InstalledSites : Route+    /**+     * MA Search sibling routes for one [query]: Text, Images and News are+     * peers under the Browser tab (see `SearchResultsPage`'s nested nav+     * host). Swipe/tab switches replace the sibling on its stack, so each+     * kind keeps its own fetch state and Back returns to browsing.+     */+    @Serializable data class SearchText(val query: String) : Route+    /** Images sibling of [SearchText]; carries the same query. */+    @Serializable data class SearchImages(val query: String) : Route+    /** News sibling of [SearchText]; carries the same query. */+    @Serializable data class SearchNews(val query: String) : Route     /** Shields settings route. */     @Serializable data object Shields : Route     /** New bookmark folder dialog. */
web/src/main/java/com/vayunmathur/web/platform/SearchUrls.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/SearchUrls.kt b/web/src/main/java/com/vayunmathur/web/platform/SearchUrls.ktindex 7e963a7bb5..ec3805e368 100644--- a/web/src/main/java/com/vayunmathur/web/platform/SearchUrls.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/SearchUrls.kt@@ -13,8 +13,16 @@ import androidx.core.net.toUri  */  /** Builds the pseudo-URL stored in a tab for a native self-hosted search. */-fun nativeSearchUrl(query: String): String =-    "search://results?q=" + Uri.encode(query)+fun nativeSearchUrl(query: String, kind: com.vayunmathur.web.data.WebSearchKind = com.vayunmathur.web.data.WebSearchKind.TEXT): String =+    "search://results?q=" + Uri.encode(query) + "&kind=" + kind.param++/** The search kind a native search URL deep-links to (Text when absent/unknown). */+fun nativeSearchKind(url: String): com.vayunmathur.web.data.WebSearchKind {+    if (!isNativeSearchUrl(url)) return com.vayunmathur.web.data.WebSearchKind.TEXT+    val param = runCatching { url.toUri().getQueryParameter("kind") }.getOrNull()+    return com.vayunmathur.web.data.WebSearchKind.entries.firstOrNull { it.param == param }+        ?: com.vayunmathur.web.data.WebSearchKind.TEXT+}  /** Whether [url] is a native self-hosted search page rather than a WebView page. */ fun isNativeSearchUrl(url: String): Boolean = url.startsWith("search://")
web/src/main/java/com/vayunmathur/web/ui/BrowserOverlays.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/BrowserOverlays.kt b/web/src/main/java/com/vayunmathur/web/ui/BrowserOverlays.ktindex fd32fca865..563a4b46e1 100644--- a/web/src/main/java/com/vayunmathur/web/ui/BrowserOverlays.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/BrowserOverlays.kt@@ -234,6 +234,7 @@ internal fun BrowserContent(             key(activeTab.id, activeTab.url) {                 SearchResultsPage(                     query = nativeSearchQuery(activeTab.url),+                    initialKind = com.vayunmathur.web.platform.nativeSearchKind(activeTab.url),                     onOpenResult = { url -> onOpenUrl(activeTab, url) },                     modifier = Modifier.fillMaxSize(),                 )
web/src/main/java/com/vayunmathur/web/ui/SearchResultsPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/SearchResultsPage.kt b/web/src/main/java/com/vayunmathur/web/ui/SearchResultsPage.ktindex 8f89eb9087..d016b3cc61 100644--- a/web/src/main/java/com/vayunmathur/web/ui/SearchResultsPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/SearchResultsPage.kt@@ -21,19 +21,22 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp-import com.vayunmathur.library.ui.PagerTab-import com.vayunmathur.library.ui.TabStyle-import com.vayunmathur.library.ui.TabbedPagerScaffold-import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.DesktopMaxWidthContainer import com.vayunmathur.library.ui.EmptyState-import com.vayunmathur.library.ui.friendlyError import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.RouteTab+import com.vayunmathur.library.ui.SwipeRouteHost import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TopAppBar+import com.vayunmathur.library.ui.friendlyError import com.vayunmathur.library.ui.rememberMessenger+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.web.R+import com.vayunmathur.web.Route import com.vayunmathur.web.data.WebSearchKind import com.vayunmathur.web.data.WebSearchRepository import com.vayunmathur.web.data.WebSearchResponse@@ -46,20 +49,27 @@ import kotlinx.coroutines.launch  *  * Calls the JSON API and renders results with on-device Compose UI — no WebView,  * no engine HTML. Shown by [BrowserContent] when the active tab holds a- * `search://` pseudo-URL (see [nativeSearchUrl]).+ * `search://` pseudo-URL (see `nativeSearchUrl`).  *  * Query logging decision: the query itself is NOT written to history — only- * result taps the user opens are recorded (via [onOpenResult]). A search box- * is not a visit, and logging every keystroke-confirmed query would pollute- * history with non-pages.+ * result taps the user opens are recorded (via [onOpenResult]).  */ /**- * Text, images and news as three swipeable peer pages for one query. Each- * page owns its fetch state, so swiping (or tapping) never flashes another- * kind's results and the old shared-slot tab-switch race is gone by- * construction. Explicit page->kind order below (never- * `WebSearchKind.entries[page]`: a future enum reorder must not silently- * mismatch pages).+ * Text, images and news as three sibling **routes** ([Route.SearchText],+ * [Route.SearchImages], [Route.SearchNews]) for one query, hosted by a+ * nested [MainNavigation] under the Browser tab — the tab stays the+ * group's parent, so Back returns to browsing and the browser chrome+ * (which owns the bottom/top bars outside this host) never moves. A+ * swipe or tab tap replaces the sibling on the nested stack via+ * [SwipeRouteHost]; it never pushes, so the three kinds cannot pile up.+ *+ * Each kind owns its fetch state in a per-kind slot of the remembered+ * [SearchKindStates] holder, keyed by query and kind: switching routes+ * uncomposes a kind without losing its response, scroll is the route+ * entry's own, and the old shared-slot tab-switch race (a slow Text+ * reply overwriting News) is gone by construction — a reply only ever+ * writes its own kind's slot. Explicit route<->kind mapping below+ * (never enum order): a future enum reorder must not mismatch routes.  */ @OptIn(ExperimentalMaterial3Api::class) @Composable@@ -67,52 +77,85 @@ fun SearchResultsPage(     query: String,     onOpenResult: (String) -> Unit,     modifier: Modifier = Modifier,+    initialKind: WebSearchKind = WebSearchKind.TEXT, ) {-    TabbedPagerScaffold(+    val siblings: List<Route> = listOf(+        Route.SearchText(query),+        Route.SearchImages(query),+        Route.SearchNews(query),+    )+    val backStack = remember(query) {+        NavBackStack(arrayOf(searchRouteFor(query, initialKind)))+    }+    val states = remember(query) { SearchKindStates() }+    SwipeRouteHost(+        backStack = backStack,+        tabs = listOf(+            RouteTab(Route.SearchText(query), stringResource(R.string.search_tab_text)),+            RouteTab(Route.SearchImages(query), stringResource(R.string.search_tab_images)),+            RouteTab(Route.SearchNews(query), stringResource(R.string.search_tab_news)),+        ),         modifier = modifier,-        tabStyle = TabStyle.PrimaryTabRow,         topBar = { TopAppBar(title = { Text(query) }) },-        tabs = listOf(-            PagerTab(stringResource(R.string.search_tab_text)) {+    ) {+        MainNavigation(backStack = backStack) {+            entry<Route.SearchText>(metadata = SiblingPage()) {                 DesktopMaxWidthContainer {-                    SearchKindResults(query, WebSearchKind.TEXT, onOpenResult)+                    SearchKindResults(query, WebSearchKind.TEXT, states.text, onOpenResult)                 }-            },-            PagerTab(stringResource(R.string.search_tab_images)) {+            }+            entry<Route.SearchImages>(metadata = SiblingPage()) {                 DesktopMaxWidthContainer {                     // SearchImageResults owns its own paginated fetch (the grid needs                     // append semantics the shared response does not have).                     SearchImageResults(query = query, onOpenResult = onOpenResult)                 }-            },-            PagerTab(stringResource(R.string.search_tab_news)) {+            }+            entry<Route.SearchNews>(metadata = SiblingPage()) {                 DesktopMaxWidthContainer {-                    SearchKindResults(query, WebSearchKind.NEWS, onOpenResult)+                    SearchKindResults(query, WebSearchKind.NEWS, states.news, onOpenResult)                 }-            },-        ),-    )+            }+        }+    }+}++/** The sibling route for [kind] over [query] — the deep-link resolution for search. */+internal fun searchRouteFor(query: String, kind: WebSearchKind): Route = when (kind) {+    WebSearchKind.TEXT -> Route.SearchText(query)+    WebSearchKind.IMAGES -> Route.SearchImages(query)+    WebSearchKind.NEWS -> Route.SearchNews(query)+}++/** Per-kind fetch slots for one query, surviving sibling route switches. */+internal class SearchKindStates {+    val text = SearchKindState()+    val news = SearchKindState()+}++internal class SearchKindState {+    var response: WebSearchResponse? by mutableStateOf(null)+    var loading: Boolean by mutableStateOf(true)+    var failure: String? by mutableStateOf(null)+    var page: Int by mutableIntStateOf(1) } -/** One text-like result kind (TEXT or NEWS) with its own fetch state. */+/** One text-like result kind (TEXT or NEWS) with its own fetch state in [state]. */ @Composable private fun SearchKindResults(     query: String,     kind: WebSearchKind,+    state: SearchKindState,     onOpenResult: (String) -> Unit, ) {     val context = LocalContext.current     val searchFailedText = stringResource(R.string.search_failed)     val messenger = rememberMessenger()     val scope = rememberCoroutineScope()-    var response by remember(query, kind) { mutableStateOf<WebSearchResponse?>(null) }-    var loading by remember(query, kind) { mutableStateOf(true) }-    var failure by remember(query, kind) { mutableStateOf<String?>(null) }-    var page by remember(query, kind) { mutableIntStateOf(1) }      fun load(requestedPage: Int) {-        loading = true-        failure = null+        state.loading = true+        state.failure = null         scope.launch {             runCatching {                 WebSearchRepository.search(@@ -122,36 +165,34 @@ private fun SearchKindResults(                     page = requestedPage,                 )             }.onSuccess {-                response = if (requestedPage > 1 && response?.query == it.query) {-                    appendPage(response, it)+                state.response = if (requestedPage > 1 && state.response?.query == it.query) {+                    appendPage(state.response, it)                 } else {                     it                 }-                page = requestedPage-                loading = false+                state.page = requestedPage+                state.loading = false             }.onFailure { e ->-                failure = context.friendlyError(e)-                loading = false+                state.failure = context.friendlyError(e)+                state.loading = false                 messenger.show(searchFailedText)             }         }     } -    LaunchedEffect(query, kind) { load(1) }+    LaunchedEffect(query, kind) { if (state.response == null && state.failure == null) load(1) }      Box(Modifier.fillMaxSize()) {         when {-            loading && response == null -> Box(Modifier.fillMaxSize())+            state.loading && state.response == null -> Box(Modifier.fillMaxSize()) -            failure != null && response == null -> SearchErrorState(-                message = failure.orEmpty(),+            state.failure != null && state.response == null -> SearchErrorState(+                message = state.failure.orEmpty(),                 onRetry = { load(1) },             )              else -> {-                val resp = response-                // Degraded server reply: lists are empty and an-                // upstream error is set.+                val resp = state.response                 if (resp?.error != null && resp.text.isNullOrEmpty() &&                     resp.images.isNullOrEmpty() && resp.news.isNullOrEmpty()                 ) {@@ -162,9 +203,9 @@ private fun SearchKindResults(                 } else when (kind) {                     WebSearchKind.TEXT -> SearchTextResults(                         items = resp?.text.orEmpty(),-                        loadingMore = loading,+                        loadingMore = state.loading,                         onOpenResult = onOpenResult,-                        onLoadMore = { load(page + 1) },+                        onLoadMore = { load(state.page + 1) },                     )                     WebSearchKind.NEWS -> SearchNewsResults(                         items = resp?.news.orEmpty(),@@ -212,7 +253,6 @@ private fun appendPage(     return previous.copy(         text = (previous.text.orEmpty() + next.text.orEmpty()).ifEmpty { null },         news = (previous.news.orEmpty() + next.news.orEmpty()).ifEmpty { null },-        // Images paginate inside SearchImageResults, which owns its own accumulation.         error = next.error,     ) }
web/src/screenshotTest/kotlin/com/vayunmathur/web/ui/MetadataPreviews.kt
diff --git a/web/src/screenshotTest/kotlin/com/vayunmathur/web/ui/MetadataPreviews.kt b/web/src/screenshotTest/kotlin/com/vayunmathur/web/ui/MetadataPreviews.ktindex eae4d57765..af215b61be 100644--- a/web/src/screenshotTest/kotlin/com/vayunmathur/web/ui/MetadataPreviews.kt+++ b/web/src/screenshotTest/kotlin/com/vayunmathur/web/ui/MetadataPreviews.kt@@ -381,4 +381,44 @@ class MetadataPreviews {             )         }     }++    @PreviewTest+    @Preview(name = "18-search-text", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview18SearchText() {+        DynamicTheme(darkTheme = true) {+            SearchTextResults(+                items = listOf(+                    com.vayunmathur.web.data.WebSearchTextItem(+                        title = "Kotlin coroutines guide",+                        url = "https://example.com/coroutines",+                        snippet = "Structured concurrency in practice.",+                    ),+                ),+                loadingMore = false,+                onOpenResult = {},+                onLoadMore = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "19-search-news", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview19SearchNews() {+        DynamicTheme(darkTheme = true) {+            SearchNewsResults(+                items = listOf(+                    com.vayunmathur.web.data.WebSearchNewsItem(+                        title = "Big Story",+                        url = "https://news.example/1",+                        snippet = "A snippet.",+                        date = 1700000000,+                        source = "Wire",+                    ),+                ),+                onOpenResult = {},+            )+        }+    } }