|
| 1 | +import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"; |
| 2 | + |
| 3 | +import { config } from "../config"; |
| 4 | +import type { RootStackParamList, ScreenProps } from "../navigation"; |
| 5 | +import { colors, radius, spacing } from "../theme"; |
| 6 | + |
| 7 | +type Destination = { |
| 8 | + title: string; |
| 9 | + subtitle: string; |
| 10 | + route: keyof Pick< |
| 11 | + RootStackParamList, |
| 12 | + "MessageCompose" | "Preferences" | "TenantSwitcher" |
| 13 | + >; |
| 14 | +}; |
| 15 | + |
| 16 | +const destinations: Destination[] = [ |
| 17 | + { |
| 18 | + title: "Compose message", |
| 19 | + subtitle: "Trigger a workflow from the app", |
| 20 | + route: "MessageCompose", |
| 21 | + }, |
| 22 | + { |
| 23 | + title: "Notification preferences", |
| 24 | + subtitle: "Per-channel opt-ins for this user", |
| 25 | + route: "Preferences", |
| 26 | + }, |
| 27 | + { |
| 28 | + title: "Switch tenant", |
| 29 | + subtitle: "Scope feeds and preferences to a tenant", |
| 30 | + route: "TenantSwitcher", |
| 31 | + }, |
| 32 | +]; |
| 33 | + |
| 34 | +export default function MainScreen({ navigation }: ScreenProps<"Main">) { |
| 35 | + return ( |
| 36 | + <ScrollView style={styles.root} contentContainerStyle={styles.content}> |
| 37 | + <View style={styles.header}> |
| 38 | + <Text style={styles.label}>Signed in as</Text> |
| 39 | + <Text style={styles.userId}>{config.userId}</Text> |
| 40 | + </View> |
| 41 | + |
| 42 | + {destinations.map(({ title, subtitle, route }) => ( |
| 43 | + <Pressable |
| 44 | + key={route} |
| 45 | + onPress={() => navigation.navigate(route)} |
| 46 | + style={({ pressed }) => [styles.row, pressed && styles.pressed]} |
| 47 | + > |
| 48 | + <Text style={styles.rowTitle}>{title}</Text> |
| 49 | + <Text style={styles.rowSubtitle}>{subtitle}</Text> |
| 50 | + </Pressable> |
| 51 | + ))} |
| 52 | + |
| 53 | + <Pressable |
| 54 | + onPress={() => navigation.popToTop()} |
| 55 | + style={({ pressed }) => [styles.signOut, pressed && styles.pressed]} |
| 56 | + > |
| 57 | + <Text style={styles.signOutText}>Sign out</Text> |
| 58 | + </Pressable> |
| 59 | + </ScrollView> |
| 60 | + ); |
| 61 | +} |
| 62 | + |
| 63 | +const styles = StyleSheet.create({ |
| 64 | + root: { |
| 65 | + flex: 1, |
| 66 | + backgroundColor: colors.background, |
| 67 | + }, |
| 68 | + content: { |
| 69 | + padding: spacing.lg, |
| 70 | + gap: spacing.md, |
| 71 | + }, |
| 72 | + header: { |
| 73 | + marginBottom: spacing.md, |
| 74 | + }, |
| 75 | + label: { |
| 76 | + color: colors.mutedText, |
| 77 | + fontSize: 12, |
| 78 | + textTransform: "uppercase", |
| 79 | + letterSpacing: 0.5, |
| 80 | + marginBottom: spacing.xs, |
| 81 | + }, |
| 82 | + userId: { |
| 83 | + color: colors.text, |
| 84 | + fontSize: 18, |
| 85 | + fontWeight: "500", |
| 86 | + }, |
| 87 | + row: { |
| 88 | + backgroundColor: colors.surface, |
| 89 | + borderWidth: 1, |
| 90 | + borderColor: colors.border, |
| 91 | + borderRadius: radius.md, |
| 92 | + padding: spacing.md, |
| 93 | + gap: spacing.xs, |
| 94 | + }, |
| 95 | + rowTitle: { |
| 96 | + color: colors.text, |
| 97 | + fontSize: 16, |
| 98 | + fontWeight: "500", |
| 99 | + }, |
| 100 | + rowSubtitle: { |
| 101 | + color: colors.mutedText, |
| 102 | + fontSize: 13, |
| 103 | + }, |
| 104 | + pressed: { |
| 105 | + opacity: 0.7, |
| 106 | + }, |
| 107 | + signOut: { |
| 108 | + marginTop: spacing.lg, |
| 109 | + alignItems: "center", |
| 110 | + paddingVertical: spacing.md, |
| 111 | + }, |
| 112 | + signOutText: { |
| 113 | + color: colors.mutedText, |
| 114 | + fontSize: 15, |
| 115 | + }, |
| 116 | +}); |
0 commit comments