From aa900f3d30cb8d535bbed3a94948facc150ee711 Mon Sep 17 00:00:00 2001 From: "Elie G." Date: Sun, 7 Jun 2026 02:47:10 +0300 Subject: [PATCH] feat(search): open zayit:// deep links pasted into the search bar --- .../core/presentation/tabs/TabsContent.kt | 3 +++ .../features/search/SearchHomeViewModel.kt | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/core/presentation/tabs/TabsContent.kt b/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/core/presentation/tabs/TabsContent.kt index 51b5ecb4b..f8a751330 100644 --- a/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/core/presentation/tabs/TabsContent.kt +++ b/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/core/presentation/tabs/TabsContent.kt @@ -170,6 +170,9 @@ fun TabsContent() { ), ) } + is SearchHomeNavigationEvent.NavigateToDeepLink -> { + tabsViewModel.replaceCurrentTabDestination(event.destination) + } } } } diff --git a/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/features/search/SearchHomeViewModel.kt b/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/features/search/SearchHomeViewModel.kt index 69162c3e1..4faa90dfe 100644 --- a/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/features/search/SearchHomeViewModel.kt +++ b/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/features/search/SearchHomeViewModel.kt @@ -5,7 +5,9 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.russhwolf.settings.Settings import com.russhwolf.settings.get +import io.github.kdroidfilter.seforim.tabs.TabsDestination import io.github.kdroidfilter.seforimapp.core.coroutines.runSuspendCatching +import io.github.kdroidfilter.seforimapp.core.deeplink.parseZayitDeepLink import io.github.kdroidfilter.seforimapp.core.settings.AppSettings import io.github.kdroidfilter.seforimapp.framework.search.LuceneLookupSearchService import io.github.kdroidfilter.seforimapp.framework.session.SearchPersistedState @@ -60,6 +62,14 @@ sealed class SearchHomeNavigationEvent { val tabId: String, val lineId: Long?, ) : SearchHomeNavigationEvent() + + /** + * Navigate to a destination resolved from a zayit:// deep link pasted into the search bar. + * @param destination The parsed destination (book/line or search) + */ + data class NavigateToDeepLink( + val destination: TabsDestination, + ) : SearchHomeNavigationEvent() } @Immutable @@ -495,6 +505,20 @@ class SearchHomeViewModel( query: String, currentTabId: String, ) { + // A zayit:// link pasted into the search bar opens the target instead of running a search. + parseZayitDeepLink(query.trim())?.let { destination -> + val resolvable = + when (destination) { + is TabsDestination.BookContent -> + runSuspendCatching { repository.getBookCore(destination.bookId) }.getOrNull() != null + else -> true + } + if (resolvable) { + _navigationEvents.send(SearchHomeNavigationEvent.NavigateToDeepLink(destination)) + return + } + } + // Apply selected scope only (view filters) and persist dataset scope for fetch val selected = _uiState.value val datasetScope: String