Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun HomePageSectionView(
onClickRecipe: (recipe: TandoorRecipeOverview) -> Unit
) {
val lazyGridState =
rememberForeverLazyGridState(key = "RouteMainSubrouteHome/lazyGridState/${section.hashCode()}")
rememberForeverLazyGridState(key = "RouteMainSubrouteHome/lazyGridState/${section?.title ?: "loading"}")

Column {
Text(
Expand All @@ -59,12 +59,7 @@ fun HomePageSectionView(
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
if(section != null) {
items(section.recipeIds.size, key = { index ->
val recipeId = section.recipeIds[index]
val recipe = client?.container?.recipeOverview?.get(recipeId)

recipe?.let { "recipe-$it" } ?: "index-$index"
}) { index ->
items(section.recipeIds.size, key = {index -> section.recipeIds[index]}) { index ->
val recipeId = section.recipeIds[index]
val recipe = client?.container?.recipeOverview?.get(recipeId)
?: return@items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,22 @@ fun HomeDynamicLayout(
}
}

LaunchedEffect(homePageSectionList.toList()) {
if(homePageSectionList.size < 2) return@LaunchedEffect
pageLoadingState = ErrorLoadingSuccessState.SUCCESS
}
LaunchedEffect(homePage, homePage?.sectionsStateList?.size) {
if (homePage == null) return@LaunchedEffect

LaunchedEffect(homePage?.sectionsStateList?.toList()) {
if(homePage == null) return@LaunchedEffect
val newSections = homePage!!.sections.onEach { section ->
section.recipeIds.removeIf { !p.vm.tandoorClient!!.container.recipeOverview.contains(it) }
}

homePageSectionList.clear()
homePageSectionList.addAll(homePage!!.sections)
if (homePageSectionList != newSections) {
homePageSectionList.clear()
homePageSectionList.addAll(newSections)
}

// keep page from loading indefinitely (prob. only happens when user has less than two recipes in space)
if(homePage?.sectionsStateList?.size == 0)
if (homePage!!.sectionsStateList.isEmpty() || homePageSectionList.size >= 2) {
pageLoadingState = ErrorLoadingSuccessState.SUCCESS

// remove deleted recipes
homePageSectionList.forEach { section ->
section.recipeIds.removeIf {
!p.vm.tandoorClient!!.container.recipeOverview.contains(it)
}
}

}

val isScrollingUp = scrollState.isScrollingUp()
Expand Down Expand Up @@ -195,7 +190,7 @@ fun HomeDynamicLayout(
}
}

if(homePageSectionList.size == 0 && pageLoadingState != ErrorLoadingSuccessState.SUCCESS) {
if(homePageSectionList.isEmpty() && pageLoadingState != ErrorLoadingSuccessState.SUCCESS) {
repeat(5) {
HomePageSectionView(
client = p.vm.tandoorClient,
Expand Down