MigrationPreviewSheet.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/migration/MigrationPreviewSheet.kt
1package eu.friedcutlet.yokan.ui.screens.migration23import androidx.compose.foundation.layout.Arrangement4import androidx.compose.foundation.layout.Box5import androidx.compose.foundation.layout.Column6import androidx.compose.foundation.layout.PaddingValues7import androidx.compose.foundation.layout.Row8import androidx.compose.foundation.layout.Spacer9import androidx.compose.foundation.layout.fillMaxSize10import androidx.compose.foundation.layout.fillMaxWidth11import androidx.compose.foundation.layout.height12import androidx.compose.foundation.layout.heightIn13import androidx.compose.foundation.layout.padding14import androidx.compose.foundation.layout.size15import androidx.compose.foundation.layout.width16import androidx.compose.foundation.lazy.items17import androidx.compose.foundation.shape.RoundedCornerShape18import androidx.compose.material.icons.Icons19import androidx.compose.material.icons.automirrored.filled.MenuBook20import androidx.compose.material.icons.filled.SwapHoriz21import androidx.compose.material3.ExperimentalMaterial3Api22import androidx.compose.material3.Icon23import androidx.compose.material3.MaterialTheme24import androidx.compose.material3.Text25import androidx.compose.runtime.Composable26import androidx.compose.ui.Alignment27import androidx.compose.ui.Modifier28import androidx.compose.ui.draw.clip29import androidx.compose.ui.text.font.FontWeight30import androidx.compose.ui.text.style.TextOverflow31import androidx.compose.ui.unit.dp32import eu.friedcutlet.yokan.ui.components.compactSheetWidth33import eu.friedcutlet.yokan.services.extensions.languageName34import org.jetbrains.compose.resources.stringResource35import yokan.composeapp.generated.resources.Res36import yokan.composeapp.generated.resources.action_cancel3738/**39 * Bottom-sheet preview of the remote detail (cover, description and chapters) that lets the user40 * confirm a per-manga migration.41 *42 * Keeps the user on the migration screen — the sheet itself dismisses on43 * success and the parent screen closes back to the previous detail page.44 */45@OptIn(ExperimentalMaterial3Api::class)46@Composable47internal fun MigrationPreviewSheet(48 preview: MigrationPreview,49 onDismiss: () -> Unit,50 onMigrate: () -> Unit,51) {52 val sheetState = androidx.compose.material3.rememberModalBottomSheetState(skipPartiallyExpanded = false)53 val candidate = preview.candidate54 val destSource = preview.source55 val loading = preview.loading56 val error = preview.error57 val migrating = preview.migrating5859 androidx.compose.material3.ModalBottomSheet(60 onDismissRequest = onDismiss,61 modifier = Modifier.compactSheetWidth(),62 sheetState = sheetState,63 ) {64 Column(65 modifier = Modifier66 .fillMaxWidth()67 .padding(horizontal = 20.dp, vertical = 12.dp),68 verticalArrangement = Arrangement.spacedBy(12.dp),69 ) {70 // Header: cover + title + source line.71 Row(72 modifier = Modifier.fillMaxWidth(),73 horizontalArrangement = Arrangement.spacedBy(14.dp),74 ) {75 Box(76 modifier = Modifier77 .size(width = 88.dp, height = 124.dp)78 .clip(MaterialTheme.shapes.medium),79 ) {80 eu.friedcutlet.yokan.ui.components.CoverImage(81 model = candidate.thumbnailUrl,82 contentDescription = candidate.title,83 modifier = Modifier.fillMaxSize(),84 fallbackInitials = candidate.title.take(2).uppercase(),85 )86 }87 Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {88 Text(89 candidate.title,90 style = MaterialTheme.typography.titleMedium,91 fontWeight = FontWeight.SemiBold,92 maxLines = 3,93 overflow = TextOverflow.Ellipsis,94 )95 Text(96 "${destSource.name} • ${languageName(destSource.lang)}",97 style = MaterialTheme.typography.labelMedium,98 color = MaterialTheme.colorScheme.primary,99 )100 if (loading) {101 androidx.compose.material3.LinearProgressIndicator(102 modifier = Modifier103 .fillMaxWidth()104 .height(4.dp)105 .clip(RoundedCornerShape(50)),106 )107 }108 }109 }110111 error?.let { message ->112 androidx.compose.material3.Surface(113 shape = MaterialTheme.shapes.large,114 color = MaterialTheme.colorScheme.errorContainer,115 ) {116 Text(117 message,118 modifier = Modifier.padding(12.dp),119 color = MaterialTheme.colorScheme.onErrorContainer,120 style = MaterialTheme.typography.bodySmall,121 )122 }123 }124125 preview.detail?.let { d ->126 if (d.description.isNotBlank()) {127 Text(128 d.description,129 style = MaterialTheme.typography.bodySmall,130 color = MaterialTheme.colorScheme.onSurfaceVariant,131 maxLines = 4,132 overflow = TextOverflow.Ellipsis,133 )134 }135 Text(136 "Chapters (${d.chapters.size})",137 style = MaterialTheme.typography.labelLarge,138 color = MaterialTheme.colorScheme.primary,139 fontWeight = FontWeight.SemiBold,140 )141 val previewState = androidx.compose.foundation.lazy.rememberLazyListState()142 eu.friedcutlet.yokan.ui.components.ScrollableLazyColumn(143 modifier = Modifier144 .fillMaxWidth()145 .heightIn(max = 280.dp),146 state = previewState,147 verticalArrangement = Arrangement.spacedBy(2.dp),148 ) {149 if (d.chapters.isEmpty()) {150 item {151 Text(152 "This source returned no chapters for the candidate.",153 style = MaterialTheme.typography.bodySmall,154 color = MaterialTheme.colorScheme.onSurfaceVariant,155 modifier = Modifier.padding(vertical = 8.dp),156 )157 }158 } else {159 items(d.chapters, key = { it.url }) { chapter ->160 Row(161 modifier = Modifier162 .fillMaxWidth()163 .clip(MaterialTheme.shapes.large)164 .padding(horizontal = 8.dp, vertical = 6.dp),165 verticalAlignment = Alignment.CenterVertically,166 horizontalArrangement = Arrangement.spacedBy(8.dp),167 ) {168 Icon(169 Icons.AutoMirrored.Filled.MenuBook,170 contentDescription = null,171 tint = MaterialTheme.colorScheme.onSurfaceVariant,172 modifier = Modifier.size(16.dp),173 )174 Column(modifier = Modifier.weight(1f)) {175 Text(176 chapter.title,177 style = MaterialTheme.typography.bodyMedium,178 maxLines = 1,179 overflow = TextOverflow.Ellipsis,180 )181 val sub = listOfNotNull(182 chapter.scanlator.takeIf { it.isNotBlank() },183 chapter.dateUpload.takeIf { it.isNotBlank() },184 ).joinToString(" • ")185 if (sub.isNotEmpty()) {186 Text(187 sub,188 style = MaterialTheme.typography.labelSmall,189 color = MaterialTheme.colorScheme.onSurfaceVariant,190 maxLines = 1,191 overflow = TextOverflow.Ellipsis,192 )193 }194 }195 }196 }197 }198 }199 }200201 // Action row at the bottom: Cancel + Migrate pill.202 Row(203 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),204 horizontalArrangement = Arrangement.spacedBy(8.dp),205 ) {206 androidx.compose.material3.OutlinedButton(207 onClick = onDismiss,208 shape = RoundedCornerShape(50),209 contentPadding = PaddingValues(horizontal = 20.dp, vertical = 8.dp),210 ) {211 Text(stringResource(Res.string.action_cancel), style = MaterialTheme.typography.labelLarge)212 }213 Spacer(Modifier.weight(1f))214 androidx.compose.material3.Button(215 onClick = onMigrate,216 enabled = !loading && !migrating && error == null,217 shape = RoundedCornerShape(50),218 contentPadding = PaddingValues(horizontal = 22.dp, vertical = 8.dp),219 ) {220 if (migrating) {221 androidx.compose.material3.CircularProgressIndicator(222 strokeWidth = 2.dp,223 modifier = Modifier.size(18.dp),224 color = MaterialTheme.colorScheme.onPrimary,225 )226 } else {227 Icon(Icons.Filled.SwapHoriz, contentDescription = null, modifier = Modifier.size(18.dp))228 }229 Spacer(Modifier.width(8.dp))230 Text(231 if (migrating) "Migrating…" else "Migrate",232 style = MaterialTheme.typography.labelLarge,233 fontWeight = FontWeight.SemiBold,234 )235 }236 }237 Spacer(Modifier.height(8.dp))238 }239 }240}241