refactor(ui, navigation): implement platform-specific routing and redesign components
- Added platform detection logic `currentPlatform()` in `PlatformType.js.kt`. - Introduced platform-based behavior for LandingScreen, Dashboard, and Login flow. - Replaced Row with FlowRow in PingScreen to improve button layout. - Updated Meldestelle Dashboard with platform-specific headers and authentication checks. - Adjusted AppHeader to accept `isAuthenticated` and `username` parameters. Signed-off-by: Stefan Mogeritsch <stefan.mo.co@gmail.com>
This commit is contained in:
+46
-53
@@ -1,74 +1,67 @@
|
||||
package at.mocode.frontend.core.designsystem.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AppHeader(
|
||||
title: String,
|
||||
onNavigateToPing: (() -> Unit)? = null,
|
||||
isAuthenticated: Boolean,
|
||||
username: String?,
|
||||
onNavigateToLogin: (() -> Unit)? = null,
|
||||
onLogout: (() -> Unit)? = null,
|
||||
isAuthenticated: Boolean = false,
|
||||
username: String? = null,
|
||||
userPermissions: List<String> = emptyList()
|
||||
onLogout: (() -> Unit)? = null
|
||||
) {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surface,
|
||||
shadowElevation = 2.dp,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
fontWeight = FontWeight.Bold
|
||||
text = "Meldestelle",
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
// Ping Service button
|
||||
onNavigateToPing?.let { navigateAction ->
|
||||
TextButton(
|
||||
onClick = navigateAction
|
||||
) {
|
||||
Text("Ping Service")
|
||||
}
|
||||
}
|
||||
|
||||
// Authentication buttons
|
||||
if (isAuthenticated) {
|
||||
// Show username with admin indicator if user has deleted permissions
|
||||
username?.let { user ->
|
||||
val isAdmin = userPermissions.any { it.contains("DELETE") }
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
if (isAuthenticated) {
|
||||
// Show the username and logout button
|
||||
Text(
|
||||
text = if (isAdmin) "👑 Hallo, $user (Admin)" else "Hallo, $user",
|
||||
text = "Angemeldet als: ${username ?: "Admin"}",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = if (isAdmin)
|
||||
MaterialTheme.colorScheme.tertiary
|
||||
else
|
||||
MaterialTheme.colorScheme.onPrimaryContainer
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
onLogout?.let { logoutAction ->
|
||||
TextButton(
|
||||
onClick = logoutAction
|
||||
) {
|
||||
Text("Abmelden")
|
||||
onLogout?.let { logoutAction ->
|
||||
TextButton(onClick = logoutAction) {
|
||||
Text("Abmelden")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Show the login button
|
||||
onNavigateToLogin?.let { loginAction ->
|
||||
TextButton(
|
||||
onClick = loginAction
|
||||
) {
|
||||
Text("Anmelden")
|
||||
} else {
|
||||
// Show the login button
|
||||
onNavigateToLogin?.let { loginAction ->
|
||||
Button(
|
||||
onClick = loginAction
|
||||
) {
|
||||
Text("Login")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
titleContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
actionIconContentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import androidx.compose.ui.Modifier
|
||||
@Composable
|
||||
fun AppScaffold(
|
||||
header: @Composable () -> Unit = {
|
||||
AppHeader(title = "Meldestelle")
|
||||
AppHeader(isAuthenticated = false, username = null)
|
||||
},
|
||||
content: @Composable (PaddingValues) -> Unit,
|
||||
footer: @Composable () -> Unit = {
|
||||
|
||||
Reference in New Issue
Block a user