From 40de2893e6c0a01d173efbeacab89f0b89e1ac24 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Tue, 27 Feb 2024 14:54:48 -0700 Subject: [PATCH] create a produceToolState Composable for the ToolsRepository --- .../org/cru/godtools/db/repository/ToolsRepository.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/db/src/main/kotlin/org/cru/godtools/db/repository/ToolsRepository.kt b/library/db/src/main/kotlin/org/cru/godtools/db/repository/ToolsRepository.kt index be8046e9a9..4bd1fc9e00 100644 --- a/library/db/src/main/kotlin/org/cru/godtools/db/repository/ToolsRepository.kt +++ b/library/db/src/main/kotlin/org/cru/godtools/db/repository/ToolsRepository.kt @@ -1,7 +1,11 @@ package org.cru.godtools.db.repository +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.remember import java.util.Locale import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import org.cru.godtools.model.Tool @@ -42,3 +46,7 @@ interface ToolsRepository { suspend fun deleteIfNotFavorite(code: String) // endregion Sync Methods } + +@Composable +fun ToolsRepository.produceToolState(toolCode: String?) = + remember(toolCode) { toolCode?.let { findToolFlow(it) } ?: flowOf(null) }.collectAsState(null)