The first public release of Fabled Minstrel #158

Merged
bvandeusen merged 256 commits from dev into main 2026-12-03 21:41:58 -05:00
4 changed files with 75 additions and 48 deletions
Showing only changes of commit 9b36effbaf - Show all commits
@@ -145,13 +145,21 @@ class MutationReplayer @Inject constructor(
// never reaches the server before the create of its list. // never reaches the server before the create of its list.
val waiting = HashSet<String>() val waiting = HashSet<String>()
for (row in rows) { for (row in rows) {
if (row.id in superseded) { replayRow(row, superseded = row.id in superseded, waiting = waiting)
dao.delete(row.id)
continue
} }
}
/**
* Sends one row, or drops it when a later row has superseded it, or
* leaves it queued when an earlier change to the same playlist is still
* waiting. A row that has to retry makes its playlist wait in [waiting].
*/
private suspend fun replayRow(row: CachedMutationEntity, superseded: Boolean, waiting: MutableSet<String>) {
val playlistId = playlistIdOf(row, json) val playlistId = playlistIdOf(row, json)
if (playlistId != null && playlistId in waiting) continue when {
when (outcomeFor(row)) { superseded -> dao.delete(row.id)
playlistId != null && playlistId in waiting -> Unit
else -> when (outcomeFor(row)) {
Outcome.SENT, Outcome.DROP -> dao.delete(row.id) Outcome.SENT, Outcome.DROP -> dao.delete(row.id)
Outcome.RETRY -> { Outcome.RETRY -> {
dao.recordAttempt(row.id, Clock.System.now()) dao.recordAttempt(row.id, Clock.System.now())
@@ -437,10 +437,35 @@ fun PlaylistDetailScreen(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
snackbarHost = { SnackbarHost(snackbarHostState) }, snackbarHost = { SnackbarHost(snackbarHostState) },
topBar = { topBar = {
PlaylistDetailTopBar(state, viewModel, onBack = { navController.popBackStack() })
},
) { inner ->
PullToRefreshScaffold(
onRefresh = { viewModel.refresh().join() },
modifier = Modifier.fillMaxSize().padding(inner),
) {
PlaylistDetailContent(
state = state,
viewModel = viewModel,
playerViewModel = playerViewModel,
navController = navController,
)
}
}
}
/** The title and back arrow, and the owner's menu when the list is theirs to change. */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun PlaylistDetailTopBar(
state: PlaylistDetailUiState,
viewModel: PlaylistDetailViewModel,
onBack: () -> Unit,
) {
TopAppBar( TopAppBar(
title = { Text(currentTitle(state)) }, title = { Text(currentTitle(state)) },
navigationIcon = { navigationIcon = {
IconButton(onClick = { navController.popBackStack() }) { IconButton(onClick = onBack) {
Icon(Lucide.ArrowLeft, contentDescription = "Back") Icon(Lucide.ArrowLeft, contentDescription = "Back")
} }
}, },
@@ -456,20 +481,6 @@ fun PlaylistDetailScreen(
} }
}, },
) )
},
) { inner ->
PullToRefreshScaffold(
onRefresh = { viewModel.refresh().join() },
modifier = Modifier.fillMaxSize().padding(inner),
) {
PlaylistDetailContent(
state = state,
viewModel = viewModel,
playerViewModel = playerViewModel,
navController = navController,
)
}
}
} }
@Composable @Composable
@@ -204,12 +204,20 @@ fun PlaylistsListScreen(
}, },
snackbarHost = { SnackbarHost(snackbar) }, snackbarHost = { SnackbarHost(snackbar) },
) { inner -> ) { inner ->
val state by viewModel.uiState.collectAsStateWithLifecycle()
val offline by viewModel.offline.collectAsStateWithLifecycle()
PullToRefreshScaffold( PullToRefreshScaffold(
onRefresh = { viewModel.refresh().join() }, onRefresh = { viewModel.refresh().join() },
modifier = Modifier.fillMaxSize().padding(inner), modifier = Modifier.fillMaxSize().padding(inner),
) { ) {
PlaylistsListBody(viewModel, onOpen = { id -> navController.navigate(PlaylistDetail(id)) })
}
}
}
/** Loading, empty, error, or the grid of playlists. */
@Composable
private fun PlaylistsListBody(viewModel: PlaylistsListViewModel, onOpen: (String) -> Unit) {
val state by viewModel.uiState.collectAsStateWithLifecycle()
val offline by viewModel.offline.collectAsStateWithLifecycle()
when (val s = state) { when (val s = state) {
UiState.Loading -> LoadingCentered() UiState.Loading -> LoadingCentered()
UiState.Empty -> EmptyState( UiState.Empty -> EmptyState(
@@ -226,12 +234,10 @@ fun PlaylistsListScreen(
is UiState.Success -> PlaylistsGrid( is UiState.Success -> PlaylistsGrid(
playlists = s.data, playlists = s.data,
offline = offline, offline = offline,
onPlaylistClick = { id -> navController.navigate(PlaylistDetail(id)) }, onPlaylistClick = onOpen,
onPlay = viewModel::playPlaylist, onPlay = viewModel::playPlaylist,
) )
} }
}
}
} }
@Composable @Composable
@@ -1,3 +1,5 @@
@file:Suppress("MatchingDeclarationName") // The file is named for its row; ReorderHandles is the row's parameter type.
package com.fabledsword.minstrel.shared.widgets package com.fabledsword.minstrel.shared.widgets
import androidx.compose.foundation.background import androidx.compose.foundation.background