generated from JetBrains/compose-multiplatform-ios-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 added SpotlightRepository to take care of loading and holding spotl…
…ight data for the current session
- Loading branch information
1 parent
918bf55
commit 863492d
Showing
10 changed files
with
243 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
shared/src/commonMain/kotlin/net/schacher/mcc/shared/repositories/SpotlightRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.schacher.mcc.shared.repositories | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.datetime.LocalDate | ||
import net.schacher.mcc.shared.datasource.http.MarvelCDbDataSource | ||
import net.schacher.mcc.shared.model.Deck | ||
|
||
class SpotlightRepository( | ||
private val cardRepository: CardRepository, | ||
private val marvelCDbDataSource: MarvelCDbDataSource, | ||
) { | ||
private val _state = MutableStateFlow<Map<LocalDate, List<Deck>>>(emptyMap()) | ||
|
||
val state = _state.asStateFlow() | ||
|
||
fun getDeckById(deckId: Int): Deck? = | ||
this.state.value.values.flatten().find { it.id == deckId } | ||
|
||
suspend fun getSpotlightDecks(localDate: LocalDate): List<Deck> { | ||
val spotlight = this.marvelCDbDataSource.getSpotlightDecksByDate(localDate) { | ||
this.cardRepository.getCard(it) | ||
}.getOrNull() | ||
|
||
if (spotlight != null) { | ||
_state.update { | ||
it.toMutableMap().apply { | ||
put(localDate, spotlight) | ||
} | ||
} | ||
} | ||
|
||
return spotlight ?: emptyList() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
shared/src/commonMain/kotlin/net/schacher/mcc/shared/screens/AppScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.schacher.mcc.shared.screens | ||
|
||
enum class AppScreen(val route: String) { | ||
Login(route = "login"), | ||
Main(route = "main"), | ||
Deck(route = "deck/{deckId}"), | ||
Card(route = "card/{cardCode}"), | ||
AddDeck(route = "add_deck") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.