Skip to content

Commit

Permalink
fix crash through flowredux collection
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Jul 14, 2024
1 parent 994e14d commit 32cbf73
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.arkivanov.decompose.value.Value
import dev.datlag.burningseries.model.HosterScraping
import dev.datlag.burningseries.model.Series
import dev.datlag.burningseries.network.SaveStateMachine
import dev.datlag.burningseries.network.common.dispatchIgnoreCollect
import dev.datlag.burningseries.network.state.SaveAction
import dev.datlag.burningseries.network.state.SaveState
import dev.datlag.burningseries.ui.navigation.DialogComponent
Expand Down Expand Up @@ -116,7 +117,7 @@ class ActivateScreenComponent(
if (converted != null) {
if (!savedData.contains(converted.href)) {
launchIO {
saveStateMachine.dispatch(SaveAction.Save(episodeHref, converted))
saveStateMachine.dispatchIgnoreCollect(SaveAction.Save(episodeHref, converted))
}
}

Expand All @@ -131,7 +132,7 @@ class ActivateScreenComponent(
stream: ImmutableCollection<DirectLink>
) {
launchIO {
saveStateMachine.dispatch(SaveAction.Clear)
saveStateMachine.dispatchIgnoreCollect(SaveAction.Clear)
withMainContext {
dialogNavigation.activate(DialogConfig.Success(series, episode, stream))
}
Expand All @@ -144,7 +145,7 @@ class ActivateScreenComponent(
stream: ImmutableCollection<DirectLink>
) {
launchIO {
saveStateMachine.dispatch(SaveAction.Clear)
saveStateMachine.dispatchIgnoreCollect(SaveAction.Clear)
withMainContext {
dialogNavigation.activate(DialogConfig.Error(series, episode, stream))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dev.datlag.burningseries.github.model.UserAndRelease
import dev.datlag.burningseries.model.SeriesData
import dev.datlag.burningseries.network.HomeStateMachine
import dev.datlag.burningseries.network.SearchStateMachine
import dev.datlag.burningseries.network.common.dispatchIgnoreCollect
import dev.datlag.burningseries.network.state.HomeState
import dev.datlag.burningseries.network.state.SearchAction
import dev.datlag.burningseries.network.state.SearchState
Expand Down Expand Up @@ -159,13 +160,13 @@ class HomeScreenComponent(

override fun search(query: String?) {
launchIO {
searchStateMachine.dispatch(SearchAction.Query(query?.ifBlank { null }))
searchStateMachine.dispatchIgnoreCollect(SearchAction.Query(query?.ifBlank { null }))
}
}

override fun retryLoadingSearch() {
launchIO {
searchStateMachine.dispatch(SearchAction.Retry)
searchStateMachine.dispatchIgnoreCollect(SearchAction.Retry)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import dev.datlag.burningseries.model.Series
import dev.datlag.burningseries.model.SeriesData
import dev.datlag.burningseries.network.EpisodeStateMachine
import dev.datlag.burningseries.network.SeriesStateMachine
import dev.datlag.burningseries.network.common.dispatchIgnoreCollect
import dev.datlag.burningseries.network.state.EpisodeAction
import dev.datlag.burningseries.network.state.EpisodeState
import dev.datlag.burningseries.network.state.SeriesState
Expand Down Expand Up @@ -246,7 +247,7 @@ class MediumScreenComponent(

override fun episode(episode: Series.Episode) {
launchIO {
episodeStateMachine.dispatch(EpisodeAction.Load(episode))
episodeStateMachine.dispatchIgnoreCollect(EpisodeAction.Load(episode))
}
}

Expand All @@ -256,7 +257,7 @@ class MediumScreenComponent(
streams: ImmutableCollection<DirectLink>
) {
launchIO {
episodeStateMachine.dispatch(EpisodeAction.Clear)
episodeStateMachine.dispatchIgnoreCollect(EpisodeAction.Clear)
withMainContext {
onWatch(series, episode, streams)
}
Expand All @@ -265,7 +266,7 @@ class MediumScreenComponent(

override fun activate(series: Series, episode: Series.Episode) {
launchIO {
episodeStateMachine.dispatch(EpisodeAction.Clear)
episodeStateMachine.dispatchIgnoreCollect(EpisodeAction.Clear)
withMainContext {
dialogNavigation.activate(DialogConfig.Activate(series, episode))
}
Expand Down Expand Up @@ -301,7 +302,7 @@ class MediumScreenComponent(
} else {
launchMain {
if (withIOContext { userHelper.requiresSponsoring() }) {
episodeStateMachine.dispatch(EpisodeAction.Clear)
episodeStateMachine.dispatchIgnoreCollect(EpisodeAction.Clear)
dialogNavigation.activate(
DialogConfig.Sponsor(
series, episode, streams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dev.datlag.burningseries.database.common.updateLength
import dev.datlag.burningseries.database.common.updateProgress
import dev.datlag.burningseries.model.Series
import dev.datlag.burningseries.network.EpisodeStateMachine
import dev.datlag.burningseries.network.common.dispatchIgnoreCollect
import dev.datlag.burningseries.network.state.EpisodeAction
import dev.datlag.burningseries.network.state.EpisodeState
import dev.datlag.skeo.DirectLink
Expand Down Expand Up @@ -76,7 +77,7 @@ class VideoScreenComponent(

if (nextEpisode != null) {
launchIO {
episodeState.dispatch(EpisodeAction.LoadNonSuccess(nextEpisode))
episodeState.dispatchIgnoreCollect(EpisodeAction.LoadNonSuccess(nextEpisode))
}
}
}
Expand All @@ -96,7 +97,7 @@ class VideoScreenComponent(

override fun next(episode: Series.Episode, streams: ImmutableCollection<DirectLink>) {
launchIO {
episodeState.dispatch(EpisodeAction.Clear)
episodeState.dispatchIgnoreCollect(EpisodeAction.Clear)
withMainContext {
onNext(episode, streams)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.datlag.burningseries.network.common

import com.freeletics.mad.statemachine.StateMachine
import dev.datlag.tooling.async.suspendCatching

suspend fun <Action : Any> StateMachine<*, Action>.dispatchIgnoreCollect(action: Action): Boolean = suspendCatching {
this@dispatchIgnoreCollect.dispatch(action)
}.isSuccess

0 comments on commit 32cbf73

Please sign in to comment.