Yokan / rebuild
Course 1 8624561

LibraryRoute.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/library/LibraryRoute.kt

implementation46 lines
1package eu.friedcutlet.yokan.ui.screens.library23import androidx.compose.runtime.Composable4import androidx.compose.runtime.getValue5import androidx.lifecycle.compose.collectAsStateWithLifecycle6import androidx.lifecycle.viewmodel.compose.viewModel7import eu.friedcutlet.yokan.app.YokanRuntime8import eu.friedcutlet.yokan.domain.ItemType9import eu.friedcutlet.yokan.ui.navigation.Navigator10import eu.friedcutlet.yokan.ui.navigation.Route1112/** The [itemType] library's ViewModel, shared through the root store by the screen and the root gestures. */13@Composable14internal fun rememberLibraryViewModel(itemType: ItemType, nav: Navigator): LibraryViewModel =15    viewModel(viewModelStoreOwner = nav.rootViewModelStoreOwner, key = "library-$itemType") {16        LibraryViewModel(17            itemType = itemType,18            repository = YokanRuntime.repository,19            settings = YokanRuntime.settings,20            libraryIndex = YokanRuntime.libraryIndex,21            libraryUpdates = YokanRuntime.libraryUpdates,22            localLibrary = YokanRuntime.localLibrary,23            chapterDownloads = YokanRuntime.chapterDownloads,24            libraryRequests = nav.libraryRequest,25            airings = YokanRuntime.services.libraryAirings,26            trackerProviders = YokanRuntime.services.trackers.map { LibraryTrackerChoice(it.syncId, it.name) },27        )28    }2930@Composable31internal fun LibraryRoute(32    itemType: ItemType,33    compact: Boolean,34    nav: Navigator,35) {36    val viewModel = rememberLibraryViewModel(itemType, nav)37    val state by viewModel.state.collectAsStateWithLifecycle()3839    LibraryScreen(40        state = state,41        compact = compact,42        onEvent = viewModel::onEvent,43        onOpenDetail = { manga -> nav.navigate(Route.Detail(manga.id)) },44        onContinue = { manga -> nav.navigate(Route.Reader(manga.id, viewModel.continueChapterId(manga))) },45    )46}47

Search chapters, reference and source filenames.