From 0b2380b8e22a0c76101b23f7ea8c1ed603c8cbcc Mon Sep 17 00:00:00 2001 From: Arkadii Ivanov Date: Fri, 6 Dec 2024 13:06:35 +0000 Subject: [PATCH] Pass articleId instead of authorId to DefaultArticleAuthorComponent --- .../multipane/DefaultMultiPaneComponent.kt | 16 ++++++++-------- .../author/DefaultArticleAuthorComponent.kt | 4 ++-- .../shared/multipane/database/ArticleDatabase.kt | 2 -- .../multipane/database/DefaultArticleDatabase.kt | 4 ---- .../multipane/list/ArticleListComponent.kt | 1 - .../list/DefaultArticleListComponent.kt | 5 ++--- .../list/PreviewArticleListComponent.kt | 2 +- 7 files changed, 13 insertions(+), 21 deletions(-) diff --git a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/DefaultMultiPaneComponent.kt b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/DefaultMultiPaneComponent.kt index 8d45cae7..2b18a046 100644 --- a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/DefaultMultiPaneComponent.kt +++ b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/DefaultMultiPaneComponent.kt @@ -57,11 +57,11 @@ internal class DefaultMultiPaneComponent( database = database, isToolbarVisible = navState.map { it.mode.isSingle }, selectedArticleId = navState.map { it.takeUnless { it.mode.isSingle }?.details?.articleId }, - onArticleSelected = { articleId, authorId -> + onArticleSelected = { articleId -> navigation.navigate { state -> state.copy( - details = Details(articleId = articleId, authorId = authorId), - extra = if (state.mode == TRIPLE) Extra(authorId = authorId) else null, + details = Details(articleId = articleId), + extra = if (state.mode == TRIPLE) Extra(articleId = articleId) else null, ) } }, @@ -73,7 +73,7 @@ internal class DefaultMultiPaneComponent( database = database, articleId = config.articleId, isToolbarVisible = navState.map { it.mode.isSingle }, - onAuthorRequested = { navigation.activateExtra(extra = Extra(authorId = config.authorId)) }, + onAuthorRequested = { navigation.activateExtra(extra = Extra(articleId = config.articleId)) }, onFinished = navigation::pop, ) @@ -81,7 +81,7 @@ internal class DefaultMultiPaneComponent( DefaultArticleAuthorComponent( componentContext = componentContext, database = database, - authorId = config.authorId, + articleId = config.articleId, isToolbarVisible = navState.map { it.mode.isSingle }, isCloseButtonVisible = navState.map { it.mode.isDual }, onFinished = navigation::pop, @@ -90,7 +90,7 @@ internal class DefaultMultiPaneComponent( override fun setMode(mode: ChildPanelsMode) { navigation.navigate { state -> state.copy( - extra = state.takeIf { mode == TRIPLE }?.details?.authorId?.let { Extra(authorId = it) } ?: state.extra, + extra = state.takeIf { mode == TRIPLE }?.details?.articleId?.let { Extra(articleId = it) } ?: state.extra, mode = mode, ) } @@ -101,8 +101,8 @@ internal class DefaultMultiPaneComponent( } @Serializable - private data class Details(val articleId: Long, val authorId: Long) + private data class Details(val articleId: Long) @Serializable - private data class Extra(val authorId: Long) + private data class Extra(val articleId: Long) } diff --git a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/author/DefaultArticleAuthorComponent.kt b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/author/DefaultArticleAuthorComponent.kt index 2259da72..f76413a5 100644 --- a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/author/DefaultArticleAuthorComponent.kt +++ b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/author/DefaultArticleAuthorComponent.kt @@ -15,7 +15,7 @@ import com.badoo.reaktive.observable.Observable internal class DefaultArticleAuthorComponent( componentContext: ComponentContext, database: ArticleDatabase, - authorId: Long, + articleId: Long, isToolbarVisible: Observable, isCloseButtonVisible: Observable, private val onFinished: () -> Unit, @@ -26,7 +26,7 @@ internal class DefaultArticleAuthorComponent( Model( isToolbarVisible = false, isCloseButtonVisible = false, - author = database.getAuthor(id = authorId).toAuthor(), + author = database.getArticle(id = articleId).author.toAuthor(), ) ) diff --git a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/database/ArticleDatabase.kt b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/database/ArticleDatabase.kt index 9fccc6bc..cb95dbbe 100644 --- a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/database/ArticleDatabase.kt +++ b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/database/ArticleDatabase.kt @@ -5,6 +5,4 @@ internal interface ArticleDatabase { fun getArticles(): List fun getArticle(id: Long): ArticleEntity - - fun getAuthor(id: Long): AuthorEntity } diff --git a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/database/DefaultArticleDatabase.kt b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/database/DefaultArticleDatabase.kt index b895fb04..7f74a7dc 100644 --- a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/database/DefaultArticleDatabase.kt +++ b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/database/DefaultArticleDatabase.kt @@ -28,14 +28,10 @@ internal class DefaultArticleDatabase : ArticleDatabase { ) } - private val authorMap = authors.associateBy(AuthorEntity::id) private val articleMap = articles.associateBy(ArticleEntity::id) override fun getArticles(): List = articles override fun getArticle(id: Long): ArticleEntity = articleMap.getValue(id) - - override fun getAuthor(id: Long): AuthorEntity = - authorMap.getValue(id) } diff --git a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/ArticleListComponent.kt b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/ArticleListComponent.kt index b2821e6f..0c41261f 100644 --- a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/ArticleListComponent.kt +++ b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/ArticleListComponent.kt @@ -16,7 +16,6 @@ interface ArticleListComponent { data class Article( val id: Long, - val authorId: Long, val title: String ) } diff --git a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/DefaultArticleListComponent.kt b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/DefaultArticleListComponent.kt index 86d6b74b..e8c36f93 100644 --- a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/DefaultArticleListComponent.kt +++ b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/DefaultArticleListComponent.kt @@ -17,7 +17,7 @@ internal class DefaultArticleListComponent( database: ArticleDatabase, isToolbarVisible: Observable, selectedArticleId: Observable, - private val onArticleSelected: (articleId: Long, authorId: Long) -> Unit, + private val onArticleSelected: (articleId: Long) -> Unit, ) : ArticleListComponent, ComponentContext by componentContext, DisposableScope by componentContext.disposableScope() { private val _models = @@ -44,11 +44,10 @@ internal class DefaultArticleListComponent( private fun ArticleEntity.toArticle(): Article = Article( id = id, - authorId = author.id, title = title ) override fun onArticleClicked(article: Article) { - onArticleSelected(article.id, article.authorId) + onArticleSelected(article.id) } } diff --git a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/PreviewArticleListComponent.kt b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/PreviewArticleListComponent.kt index a554ed7d..d1fc19d3 100644 --- a/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/PreviewArticleListComponent.kt +++ b/sample/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/multipane/list/PreviewArticleListComponent.kt @@ -13,7 +13,7 @@ class PreviewArticleListComponent( MutableValue( Model( articles = List(10) { index -> - Article(id = index.toLong(), authorId = index.toLong(), title = "Article $index") + Article(id = index.toLong(), title = "Article $index") }, isToolbarVisible = isToolbarVisible, selectedArticleId = null,