Skip to content

Commit

Permalink
make home items clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 1, 2023
1 parent 2fb77b2 commit 9272d4e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface HomeComponent : Component {
val homeState: StateFlow<HomeState>

fun retryLoadingHome(): Any?
fun itemClicked(config: HomeConfig)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ package dev.datlag.burningseries.ui.screen.initial.home

import com.arkivanov.essenty.parcelable.Parcelable
import com.arkivanov.essenty.parcelable.Parcelize
import dev.datlag.burningseries.model.Home

@Parcelize
sealed class HomeConfig : Parcelable {

@Parcelize
data object Series : HomeConfig(), Parcelable
data class Series(
val title: String,
val href: String,
val coverHref: String?,
) : HomeConfig(), Parcelable {
constructor(series: Home.Series) : this(series.title, series.href, series.coverHref)
constructor(episode: Home.Episode) : this(episode.series ?: episode.title, episode.href, episode.href)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private fun MainView(home: Home, component: HomeComponent, modifier: Modifier =
it.href
}) { episode ->
EpisodeItem(episode) {
// episode clicked
component.itemClicked(HomeConfig.Series(episode))
}
}
header {
Expand All @@ -136,7 +136,7 @@ private fun MainView(home: Home, component: HomeComponent, modifier: Modifier =
it.href
}) { series ->
SeriesItem(series) {
// series clicked
component.itemClicked(HomeConfig.Series(series))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.router.slot.ChildSlot
import com.arkivanov.decompose.router.slot.SlotNavigation
import com.arkivanov.decompose.router.slot.activate
import com.arkivanov.decompose.router.slot.childSlot
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
Expand Down Expand Up @@ -33,7 +34,13 @@ class HomeScreenComponent(
handleBackButton = true
) { config, context ->
when (config) {
is HomeConfig.Series -> SeriesScreenComponent(context, di)
is HomeConfig.Series -> SeriesScreenComponent(
componentContext = context,
di = di,
initialTitle = config.title,
initialHref = config.href,
initialCoverHref = config.coverHref
)
}
}

Expand All @@ -45,4 +52,8 @@ class HomeScreenComponent(
override fun retryLoadingHome(): Any? = ioScope().launchIO {
homeStateMachine.dispatch(HomeAction.Retry)
}

override fun itemClicked(config: HomeConfig) {
navigation.activate(config)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import org.kodein.di.DI

class SeriesScreenComponent(
componentContext: ComponentContext,
override val di: DI
override val di: DI,
val initialTitle: String,
val initialHref: String,
val initialCoverHref: String?
) : SeriesComponent, ComponentContext by componentContext {

@Composable
Expand Down

0 comments on commit 9272d4e

Please sign in to comment.