diff --git a/experimental/market/src/commonMain/kotlin/org/mobilenativefoundation/market/combineReducers.kt b/experimental/market/src/commonMain/kotlin/org/mobilenativefoundation/market/combineReducers.kt new file mode 100644 index 000000000..d2b2a9fe3 --- /dev/null +++ b/experimental/market/src/commonMain/kotlin/org/mobilenativefoundation/market/combineReducers.kt @@ -0,0 +1,11 @@ +package org.mobilenativefoundation.market + + +inline fun combineReducers(vararg reducers: Market.Reducer): Market.Reducer { + return Market.Reducer { state, action -> + reducers.fold(state) { currentState, reducer -> + reducer.reduce(currentState, action) + } + } +} + diff --git a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/di/CoreComponent.kt b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/di/CoreComponent.kt index d522fdcea..ede407803 100644 --- a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/di/CoreComponent.kt +++ b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/di/CoreComponent.kt @@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import me.tatarka.inject.annotations.Component import me.tatarka.inject.annotations.Provides +import org.mobilenativefoundation.market.combineReducers import org.mobilenativefoundation.market.impl.MarketActionFactory import org.mobilenativefoundation.market.impl.RealMarketSupplier import org.mobilenativefoundation.market.impl.RealScheduledMarketSupplier @@ -16,9 +17,8 @@ import org.mobilenativefoundation.sample.octonaut.android.app.circuit.OctonautPr import org.mobilenativefoundation.sample.octonaut.android.app.circuit.OctonautScreenFactory import org.mobilenativefoundation.sample.octonaut.android.app.circuit.OctonautUiFactory import org.mobilenativefoundation.sample.octonaut.android.app.circuit.ScreenFactory -import org.mobilenativefoundation.sample.octonaut.android.app.market.MutableOctonautMarket -import org.mobilenativefoundation.sample.octonaut.android.app.market.RealMutableOctonautMarket -import org.mobilenativefoundation.sample.octonaut.android.app.market.RealOctonautMarketDispatcher +import org.mobilenativefoundation.sample.octonaut.android.app.market.* +import org.mobilenativefoundation.sample.octonaut.android.app.market.reducers.* import org.mobilenativefoundation.sample.octonaut.xplat.common.market.* import org.mobilenativefoundation.sample.octonaut.xplat.domain.feed.api.FeedStore import org.mobilenativefoundation.sample.octonaut.xplat.domain.feed.api.FeedSupplier @@ -86,10 +86,21 @@ abstract class CoreComponent : NetworkingComponent { @Provides fun provideMarket(mutableMarket: MutableOctonautMarket): OctonautMarket = mutableMarket + @Provides + fun provideRootReducer(): RootReducer { + return combineReducers( + currentUserReducer, + notificationsReducer, + feedReducer, + usersReducer, + repositoriesReducer + ) + } + @UserScope @Provides - fun provideMarketDispatcher(mutableMarket: MutableOctonautMarket): OctonautMarketDispatcher { - return RealOctonautMarketDispatcher(mutableMarket) + fun provideMarketDispatcher(mutableMarket: MutableOctonautMarket, rootReducer: RootReducer): OctonautMarketDispatcher { + return RealOctonautMarketDispatcher(mutableMarket, rootReducer) } @UserScope @@ -172,9 +183,10 @@ abstract class CoreComponent : NetworkingComponent { marketDispatcher: OctonautMarketDispatcher, ): RepositorySupplier { - val marketActionFactory = MarketActionFactory { storeOutput -> - OctonautMarketAction.AddRepository(storeOutput) - } + val marketActionFactory = + MarketActionFactory { storeOutput -> + OctonautMarketAction.AddRepository(storeOutput) + } return RealMarketSupplier( coroutineDispatcher, diff --git a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/RealOctonautMarketDispatcher.kt b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/RealOctonautMarketDispatcher.kt index 165c3420f..a7520c5d2 100644 --- a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/RealOctonautMarketDispatcher.kt +++ b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/RealOctonautMarketDispatcher.kt @@ -3,245 +3,19 @@ package org.mobilenativefoundation.sample.octonaut.android.app.market import me.tatarka.inject.annotations.Inject import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketDispatcher -import org.mobilenativefoundation.sample.octonaut.xplat.domain.feed.api.* -import org.mobilenativefoundation.sample.octonaut.xplat.domain.notifications.api.Notification -import org.mobilenativefoundation.sample.octonaut.xplat.domain.notifications.api.NotificationsState -import org.mobilenativefoundation.sample.octonaut.xplat.domain.repository.api.RepositoriesState -import org.mobilenativefoundation.sample.octonaut.xplat.domain.repository.api.Repository -import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.User -import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.UsersState @Inject class RealOctonautMarketDispatcher( - private val mutableMarket: MutableOctonautMarket + private val mutableMarket: MutableOctonautMarket, + private val rootReducer: RootReducer ) : OctonautMarketDispatcher { override fun dispatch(action: OctonautMarketAction) { - val prevState = mutableMarket.state.value - val nextState = when (action) { - is OctonautMarketAction.UpdateCurrentUser -> { - prevState.copy( - currentUser = action.user?.let { - User( - id = it.id, - email = it.email, - name = it.name ?: "", - login = it.login, - avatarUrl = it.avatarUrl.toString(), - repositories = it.repositories.nodes?.mapNotNull { repo -> repo?.id } ?: emptyList(), - starredRepositories = it.starredRepositories.nodes?.mapNotNull { repo -> repo?.id } - ?: emptyList(), - organizations = it.organizations.nodes?.mapNotNull { org -> org?.id } ?: emptyList(), - pinnedItems = it.pinnedItems.let { pinnedItems -> List(pinnedItems.totalCount) { "" } }, - socialAccounts = it.socialAccounts.nodes?.mapNotNull { socialAccount -> - socialAccount?.let { - User.SocialAccount( - socialAccount.displayName, - socialAccount.provider.name - ) - } - } ?: emptyList() - ) - } - ) - } - - is OctonautMarketAction.UpdateNotifications -> { - - val notifications = action.notifications.notifications.map { - Notification( - it.id, - it.unread, - it.updatedAt, - it.lastReadAt, - it.url, - it.subscriptionUrl - ) - } - - val byId = notifications.associateBy { it.id } - val allIds = notifications.map { it.id } - - val notificationsState = NotificationsState( - byId = byId, - allIds = allIds - ) - - prevState.copy( - notifications = notificationsState - ) - } - - is OctonautMarketAction.UpdateFeed -> { - - val id = action.feed.id - - val entries = action.feed.entry.map { - Entry( - it.id, - it.published, - it.updated, - it.link.href, - it.title, - it.author.uri, - it.thumbnail.url - ) - } - - val entriesState = EntriesState( - byId = entries.associateBy { it.id }, - allIds = entries.map { it.id } - ) - - val links = action.feed.link.map { - Link( - it.type, - it.rel, - it.href - ) - } - - val linksState = LinksState( - byHref = links.associateBy { it.href }, - allHrefs = links.map { it.href } - ) - - val thumbnails = action.feed.entry.map { - Thumbnail( - it.thumbnail.height, - it.thumbnail.width, - it.thumbnail.url - ) - } - - val thumbnailsState = ThumbnailsState( - byUrl = thumbnails.associateBy { it.url }, - allUrls = thumbnails.map { it.url } - ) - - val feedState = FeedState( - id = id, - entries = entriesState, - links = linksState, - thumbnails = thumbnailsState - ) - - prevState.copy( - feed = feedState - ) - } - - is OctonautMarketAction.AddUser -> { - val user = User( - id = action.user.id, - email = action.user.email, - name = action.user.name ?: "", - login = action.user.login, - avatarUrl = action.user.avatarUrl.toString(), - repositories = action.user.repositories.nodes?.mapNotNull { repo -> repo?.id } ?: emptyList(), - starredRepositories = action.user.starredRepositories.nodes?.mapNotNull { repo -> repo?.id } - ?: emptyList(), - organizations = action.user.organizations.nodes?.mapNotNull { org -> org?.id } ?: emptyList(), - pinnedItems = action.user.pinnedItems.let { pinnedItems -> List(pinnedItems.totalCount) { "" } }, - socialAccounts = action.user.socialAccounts.nodes?.mapNotNull { socialAccount -> - socialAccount?.let { - User.SocialAccount( - socialAccount.displayName, - socialAccount.provider.name - ) - } - } ?: emptyList() - ) - - val allIds = if (user.id !in prevState.users.byId) { - val copy = prevState.users.allIds.toMutableList() - copy.add(action.user.id) - copy - } else { - prevState.users.allIds - } - - val byId = prevState.users.byId.toMutableMap() - byId[user.id] = user - - val loginToId = allIds.mapNotNull { id -> byId[id] }.associate { it.login to it.id } - - val usersState = UsersState( - byId = byId, - allIds = allIds, - loginToId = loginToId - ) - - prevState.copy( - users = usersState - ) - } - - is OctonautMarketAction.AddNotifications -> { - - - val notifications = action.notifications.notifications.map { - Notification( - it.id, - it.unread, - it.updatedAt, - it.lastReadAt, - it.url, - it.subscriptionUrl - ) - } - - val byId = prevState.notifications.byId.toMutableMap() - val allIds = prevState.notifications.allIds.toMutableList() - - notifications.forEach { - if (it.id !in byId) { - allIds.add(it.id) - } - - byId[it.id] = it - } - - val notificationsState = NotificationsState( - byId = byId, - allIds = allIds - ) - - prevState.copy( - notifications = notificationsState - ) - - } - - is OctonautMarketAction.AddRepository -> { - val repository = Repository( - action.repository.id, - action.repository.name - ) - - val allIds = if (repository.id !in prevState.repositories.byId) { - val copy = prevState.repositories.allIds.toMutableList() - copy.add(repository.id) - copy - } else { - prevState.repositories.allIds - } + val nextState = rootReducer.reduce(mutableMarket.state.value, action) + mutableMarket.updateState(nextState) + } +} - val byId = prevState.repositories.byId.toMutableMap() - byId[repository.id] = repository - val repositoriesState = RepositoriesState( - byId = byId, - allIds = allIds, - ) - prevState.copy( - repositories = repositoriesState - ) - } - } - println("UPDATING STATE: $prevState to $nextState") - mutableMarket.updateState(nextState) - } -} \ No newline at end of file diff --git a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/RootReducer.kt b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/RootReducer.kt new file mode 100644 index 000000000..0750a0d31 --- /dev/null +++ b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/RootReducer.kt @@ -0,0 +1,7 @@ +package org.mobilenativefoundation.sample.octonaut.android.app.market + +import org.mobilenativefoundation.market.Market +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketState + +typealias RootReducer = Market.Reducer \ No newline at end of file diff --git a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/CurrentUserReducer.kt b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/CurrentUserReducer.kt new file mode 100644 index 000000000..5a30f0423 --- /dev/null +++ b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/CurrentUserReducer.kt @@ -0,0 +1,39 @@ +package org.mobilenativefoundation.sample.octonaut.android.app.market.reducers + +import org.mobilenativefoundation.market.Market +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketState +import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.User + +val currentUserReducer: Market.Reducer = + Market.Reducer { state, action -> + + if (action is OctonautMarketAction.UpdateCurrentUser) { + state.copy(currentUser = state.currentUser.copy( + user = action.user?.let { + User( + id = it.id, + email = it.email, + name = it.name ?: "", + login = it.login, + avatarUrl = it.avatarUrl.toString(), + repositories = it.repositories.nodes?.mapNotNull { repo -> repo?.id } ?: emptyList(), + starredRepositories = it.starredRepositories.nodes?.mapNotNull { repo -> repo?.id } + ?: emptyList(), + organizations = it.organizations.nodes?.mapNotNull { org -> org?.id } ?: emptyList(), + pinnedItems = it.pinnedItems.let { pinnedItems -> List(pinnedItems.totalCount) { "" } }, + socialAccounts = it.socialAccounts.nodes?.mapNotNull { socialAccount -> + socialAccount?.let { + User.SocialAccount( + socialAccount.displayName, + socialAccount.provider.name + ) + } + } ?: emptyList() + ) + } + )) + } else { + state + } + } \ No newline at end of file diff --git a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/FeedReducer.kt b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/FeedReducer.kt new file mode 100644 index 000000000..f45a9da34 --- /dev/null +++ b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/FeedReducer.kt @@ -0,0 +1,69 @@ +package org.mobilenativefoundation.sample.octonaut.android.app.market.reducers + +import org.mobilenativefoundation.market.Market +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketState +import org.mobilenativefoundation.sample.octonaut.xplat.domain.feed.api.* + +val feedReducer: Market.Reducer = Market.Reducer { state, action -> + + if (action is OctonautMarketAction.UpdateFeed) { + val id = action.feed.id + + val entries = action.feed.entry.map { + Entry( + it.id, + it.published, + it.updated, + it.link.href, + it.title, + it.author.uri, + it.thumbnail.url + ) + } + + val entriesState = EntriesState( + byId = entries.associateBy { it.id }, + allIds = entries.map { it.id } + ) + + val links = action.feed.link.map { + Link( + it.type, + it.rel, + it.href + ) + } + + val linksState = LinksState( + byHref = links.associateBy { it.href }, + allHrefs = links.map { it.href } + ) + + val thumbnails = action.feed.entry.map { + Thumbnail( + it.thumbnail.height, + it.thumbnail.width, + it.thumbnail.url + ) + } + + val thumbnailsState = ThumbnailsState( + byUrl = thumbnails.associateBy { it.url }, + allUrls = thumbnails.map { it.url } + ) + + val feedState = FeedState( + id = id, + entries = entriesState, + links = linksState, + thumbnails = thumbnailsState + ) + + state.copy( + feed = feedState + ) + } else { + state + } +} \ No newline at end of file diff --git a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/NotificationsReducer.kt b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/NotificationsReducer.kt new file mode 100644 index 000000000..28df41f6f --- /dev/null +++ b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/NotificationsReducer.kt @@ -0,0 +1,35 @@ +package org.mobilenativefoundation.sample.octonaut.android.app.market.reducers + +import org.mobilenativefoundation.market.Market +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketState +import org.mobilenativefoundation.sample.octonaut.xplat.domain.notifications.api.Notification +import org.mobilenativefoundation.sample.octonaut.xplat.domain.notifications.api.NotificationsState + +val notificationsReducer: Market.Reducer = + Market.Reducer { state, action -> + if (action is OctonautMarketAction.UpdateNotifications) { + val notifications = action.notifications.notifications.map { + Notification( + it.id, + it.unread, + it.updatedAt, + it.lastReadAt, + it.url, + it.subscriptionUrl + ) + } + + val byId = notifications.associateBy { it.id } + val allIds = notifications.map { it.id } + + val notificationsState = NotificationsState( + byId = byId, + allIds = allIds + ) + + state.copy(notifications = notificationsState) + } else { + state + } + } \ No newline at end of file diff --git a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/RepositoriesReducer.kt b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/RepositoriesReducer.kt new file mode 100644 index 000000000..e54ddb00e --- /dev/null +++ b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/RepositoriesReducer.kt @@ -0,0 +1,39 @@ +package org.mobilenativefoundation.sample.octonaut.android.app.market.reducers + +import org.mobilenativefoundation.market.Market +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketState +import org.mobilenativefoundation.sample.octonaut.xplat.domain.repository.api.RepositoriesState +import org.mobilenativefoundation.sample.octonaut.xplat.domain.repository.api.Repository + +val repositoriesReducer: Market.Reducer = Market.Reducer { state, action -> + + if (action is OctonautMarketAction.AddRepository) { + val repository = Repository( + action.repository.id, + action.repository.name + ) + + val allIds = if (repository.id !in state.repositories.byId) { + val copy = state.repositories.allIds.toMutableList() + copy.add(repository.id) + copy + } else { + state.repositories.allIds + } + + val byId = state.repositories.byId.toMutableMap() + byId[repository.id] = repository + + val repositoriesState = RepositoriesState( + byId = byId, + allIds = allIds, + ) + + state.copy( + repositories = repositoriesState + ) + } else { + state + } +} \ No newline at end of file diff --git a/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/UsersReducer.kt b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/UsersReducer.kt new file mode 100644 index 000000000..953750545 --- /dev/null +++ b/experimental/sample/octonaut/android/app/src/main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/reducers/UsersReducer.kt @@ -0,0 +1,58 @@ +package org.mobilenativefoundation.sample.octonaut.android.app.market.reducers + +import org.mobilenativefoundation.market.Market +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction +import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketState +import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.User +import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.UsersState + +val usersReducer: Market.Reducer = Market.Reducer { state, action -> + + if (action is OctonautMarketAction.AddUser) { + val user = User( + id = action.user.id, + email = action.user.email, + name = action.user.name ?: "", + login = action.user.login, + avatarUrl = action.user.avatarUrl.toString(), + repositories = action.user.repositories.nodes?.mapNotNull { repo -> repo?.id } ?: emptyList(), + starredRepositories = action.user.starredRepositories.nodes?.mapNotNull { repo -> repo?.id } + ?: emptyList(), + organizations = action.user.organizations.nodes?.mapNotNull { org -> org?.id } ?: emptyList(), + pinnedItems = action.user.pinnedItems.let { pinnedItems -> List(pinnedItems.totalCount) { "" } }, + socialAccounts = action.user.socialAccounts.nodes?.mapNotNull { socialAccount -> + socialAccount?.let { + User.SocialAccount( + socialAccount.displayName, + socialAccount.provider.name + ) + } + } ?: emptyList() + ) + + val allIds = if (user.id !in state.users.byId) { + val copy = state.users.allIds.toMutableList() + copy.add(action.user.id) + copy + } else { + state.users.allIds + } + + val byId = state.users.byId.toMutableMap() + byId[user.id] = user + + val loginToId = allIds.mapNotNull { id -> byId[id] }.associate { it.login to it.id } + + val usersState = UsersState( + byId = byId, + allIds = allIds, + loginToId = loginToId + ) + + state.copy( + users = usersState + ) + } else { + state + } +} \ No newline at end of file diff --git a/experimental/sample/octonaut/xplat/common/market/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/common/market/OctonautMarketState.kt b/experimental/sample/octonaut/xplat/common/market/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/common/market/OctonautMarketState.kt index 0bea81944..df04203f8 100644 --- a/experimental/sample/octonaut/xplat/common/market/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/common/market/OctonautMarketState.kt +++ b/experimental/sample/octonaut/xplat/common/market/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/common/market/OctonautMarketState.kt @@ -4,11 +4,12 @@ import org.mobilenativefoundation.market.Market import org.mobilenativefoundation.sample.octonaut.xplat.domain.feed.api.FeedState import org.mobilenativefoundation.sample.octonaut.xplat.domain.notifications.api.NotificationsState import org.mobilenativefoundation.sample.octonaut.xplat.domain.repository.api.RepositoriesState +import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.CurrentUserState import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.User import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.UsersState data class OctonautMarketState( - val currentUser: User? = null, + val currentUser: CurrentUserState = CurrentUserState(), val users: UsersState = UsersState(), val notifications: NotificationsState = NotificationsState(), val feed: FeedState = FeedState(), diff --git a/experimental/sample/octonaut/xplat/domain/notifications/api/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/domain/notifications/api/NotificationsState.kt b/experimental/sample/octonaut/xplat/domain/notifications/api/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/domain/notifications/api/NotificationsState.kt index af39037db..951ada663 100644 --- a/experimental/sample/octonaut/xplat/domain/notifications/api/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/domain/notifications/api/NotificationsState.kt +++ b/experimental/sample/octonaut/xplat/domain/notifications/api/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/domain/notifications/api/NotificationsState.kt @@ -1,6 +1,8 @@ package org.mobilenativefoundation.sample.octonaut.xplat.domain.notifications.api +import org.mobilenativefoundation.market.Market + data class NotificationsState( val byId: Map = mapOf(), val allIds: List = emptyList() -) +): Market.State diff --git a/experimental/sample/octonaut/xplat/domain/user/api/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/domain/user/api/CurrentUserState.kt b/experimental/sample/octonaut/xplat/domain/user/api/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/domain/user/api/CurrentUserState.kt new file mode 100644 index 000000000..0b128628d --- /dev/null +++ b/experimental/sample/octonaut/xplat/domain/user/api/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/domain/user/api/CurrentUserState.kt @@ -0,0 +1,7 @@ +package org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api + +import org.mobilenativefoundation.market.Market + +data class CurrentUserState( + val user: User? = null +): Market.State diff --git a/experimental/sample/octonaut/xplat/feat/exploreTab/impl/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/feat/exploreTab/impl/ExploreTabWarehouseFactory.kt b/experimental/sample/octonaut/xplat/feat/exploreTab/impl/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/feat/exploreTab/impl/ExploreTabWarehouseFactory.kt index ac6606dd9..a59da33f4 100644 --- a/experimental/sample/octonaut/xplat/feat/exploreTab/impl/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/feat/exploreTab/impl/ExploreTabWarehouseFactory.kt +++ b/experimental/sample/octonaut/xplat/feat/exploreTab/impl/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/feat/exploreTab/impl/ExploreTabWarehouseFactory.kt @@ -13,7 +13,7 @@ class ExploreTabWarehouseFactory( return warehouseBuilder.extractor { marketState -> ExploreTabWarehouseState( - user = marketState.currentUser, + user = marketState.currentUser?.user, searchResults = emptyList() // TODO ) }.actionHandler { action, marketState -> diff --git a/experimental/sample/octonaut/xplat/feat/homeTab/impl/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/feat/homeTab/impl/HomeTabWarehouseFactory.kt b/experimental/sample/octonaut/xplat/feat/homeTab/impl/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/feat/homeTab/impl/HomeTabWarehouseFactory.kt index 120a2fae7..92e9f6230 100644 --- a/experimental/sample/octonaut/xplat/feat/homeTab/impl/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/feat/homeTab/impl/HomeTabWarehouseFactory.kt +++ b/experimental/sample/octonaut/xplat/feat/homeTab/impl/src/commonMain/kotlin/org/mobilenativefoundation/sample/octonaut/xplat/feat/homeTab/impl/HomeTabWarehouseFactory.kt @@ -17,13 +17,13 @@ class HomeTabWarehouseFactory( return warehouseBuilder .extractor { marketState -> - HomeTabWarehouseState(marketState.currentUser, marketState.feed) + HomeTabWarehouseState(marketState.currentUser?.user, marketState.feed) } .actionHandler { action, marketState -> when (action) { HomeTabWarehouseAction.Refresh -> { // Refresh user - val currentUser = marketState.currentUser!! + val currentUser = marketState.currentUser!!.user!! userSupplier.supply(GetUserQuery(currentUser.login)) // Refresh repositories