Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor email row to separate component (#771)

Leendert de Borst14b90fb047af
diff --git a/mobile-app/app/(tabs)/(credentials)/index.tsx b/mobile-app/app/(tabs)/(credentials)/index.tsx
index 8fea72e51..47273f403 100644
--- a/mobile-app/app/(tabs)/(credentials)/index.tsx
+++ b/mobile-app/app/(tabs)/(credentials)/index.tsx
@@ -240,13 +240,7 @@ export default function CredentialsScreen() {
/>
}
renderItem={({ item }) => (
- <TouchableOpacity
- onPress={() => handleCredentialPress(item.Id)}
- style={[styles.credentialItem]}
- activeOpacity={0.7}
- >
- <CredentialCard credential={item} />
- </TouchableOpacity>
+ <CredentialCard credential={item} />
)}
ListEmptyComponent={
<Text style={[styles.emptyText]}>
diff --git a/mobile-app/app/(tabs)/(emails)/index.tsx b/mobile-app/app/(tabs)/(emails)/index.tsx
index 327610b50..da500024a 100644
--- a/mobile-app/app/(tabs)/(emails)/index.tsx
+++ b/mobile-app/app/(tabs)/(emails)/index.tsx
@@ -1,15 +1,17 @@
import React, { useEffect, useState, useCallback } from 'react';
-import { StyleSheet, View, TouchableOpacity, RefreshControl, ActivityIndicator } from 'react-native';
-import { useRouter } from 'expo-router';
+import { StyleSheet, View, ActivityIndicator, ScrollView } from 'react-native';
+import { router, Stack } from 'expo-router';
import { MailboxEmail } from '@/utils/types/webapi/MailboxEmail';
import { useDb } from '@/context/DbContext';
import { useWebApi } from '@/context/WebApiContext';
import { ThemedText } from '@/components/ThemedText';
import { TitleContainer } from '@/components/TitleContainer';
-import ParallaxScrollView from '@/components/ParallaxScrollView';
-import { IconSymbol } from '@/components/ui/IconSymbol';
import { MailboxBulkRequest, MailboxBulkResponse } from '@/utils/types/webapi/MailboxBulk';
import EncryptionUtility from '@/utils/EncryptionUtility';
+import { useColors } from '@/hooks/useColorScheme';
+import { ThemedView } from '@/components/ThemedView';
+import { ThemedSafeAreaView } from '@/components/ThemedSafeAreaView';
+import { EmailCard } from '@/components/EmailCard';
// Simple hook for minimum duration loading state
const useMinDurationLoading = (initialState: boolean, minDuration: number): [boolean, (newState: boolean) => void] => {
@@ -36,9 +38,9 @@ const useMinDurationLoading = (initialState: boolean, minDuration: number): [boo
};
export default function EmailsScreen() {
- const router = useRouter();
const dbContext = useDb();
const webApi = useWebApi();
+ const colors = useColors();
const [error, setError] = useState<string | null>(null);
const [emails, setEmails] = useState<MailboxEmail[]>([]);
const [isLoading, setIsLoading] = useMinDurationLoading(true, 100);
@@ -141,113 +143,61 @@ export default function EmailsScreen() {
}
return emails.map((email) => (
- <TouchableOpacity
- key={email.id}
- style={styles.emailCard}
- onPress={() => router.push(`/emails/${email.id}`)}
- >
- <View style={styles.emailHeader}>
- <ThemedText style={styles.emailSubject} numberOfLines={1}>
- {email.subject}
- </ThemedText>
- <ThemedText style={styles.emailDate}>
- {formatEmailDate(email.dateSystem)}
- </ThemedText>
- </View>
- <ThemedText style={styles.emailPreview} numberOfLines={2}>
- {email.messagePreview}
- </ThemedText>
- </TouchableOpacity>
+ <EmailCard key={email.id} email={email} />
));
};
+ const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ marginBottom: 80,
+ },
+ content: {
+ flex: 1,
+ padding: 16,
+ },
+ headerImage: {
+ color: colors.textMuted,
+ bottom: -90,
+ left: -35,
+ position: 'absolute',
+ },
+ centerContainer: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ padding: 20,
+ },
+ errorText: {
+ color: colors.errorBackground,
+ textAlign: 'center',
+ },
+ emptyText: {
+ textAlign: 'center',
+ opacity: 0.7,
+ color: colors.textMuted,
+ },
+ refreshIndicator: {
+ position: 'absolute',
+ top: 20,
+ alignSelf: 'center',
+ },
+ });
+
return (
- <View style={styles.container}>
- <ParallaxScrollView
- headerBackgroundColor={{ light: '#D0D0D0', dark: '#353636' }}
- headerImage={
- <IconSymbol
- size={310}
- color="#808080"
- name="envelope.fill"
- style={styles.headerImage}
- />
- }
- >
- <TitleContainer title="Emails" />
- {renderContent()}
- </ParallaxScrollView>
- {isRefreshing && (
- <View style={styles.refreshIndicator}>
- <ActivityIndicator size="large" />
- </View>
- )}
- </View>
+ <ThemedSafeAreaView style={styles.container}>
+ <Stack.Screen options={{ title: "Emails" }} />
+ <ThemedView style={styles.content}>
+ <ScrollView>
+ <TitleContainer title="Emails" />
+ {renderContent()}
+ </ScrollView>
+ {isRefreshing && (
+ <View style={styles.refreshIndicator}>
+ <ActivityIndicator size="large" />
+ </View>
+ )}
+ </ThemedView>
+ </ThemedSafeAreaView>
);
}
-
-const styles = StyleSheet.create({
- container: {
- flex: 1,
- },
- headerImage: {
- color: '#808080',
- bottom: -90,
- left: -35,
- position: 'absolute',
- },
- centerContainer: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- padding: 20,
- },
- errorText: {
- color: '#ef4444',
- textAlign: 'center',
- },
- emptyText: {
- textAlign: 'center',
- opacity: 0.7,
- },
- emailCard: {
- backgroundColor: '#ffffff',
- borderRadius: 8,
- padding: 16,
- marginHorizontal: 16,
- marginBottom: 12,
- shadowColor: '#000',
- shadowOffset: {
- width: 0,
- height: 2,
- },
- shadowOpacity: 0.1,
- shadowRadius: 3,
- elevation: 3,
- },
- emailHeader: {
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'flex-start',
- marginBottom: 8,
- },
- emailSubject: {
- flex: 1,
- fontSize: 16,
- fontWeight: 'bold',
- marginRight: 8,
- },
- emailDate: {
- fontSize: 12,
- opacity: 0.6,
- },
- emailPreview: {
- fontSize: 14,
- opacity: 0.8,
- },
- refreshIndicator: {
- position: 'absolute',
- top: 20,
- alignSelf: 'center',
- },
-});
diff --git a/mobile-app/components/CredentialCard.tsx b/mobile-app/components/CredentialCard.tsx
index 4ee08085a..e357ec363 100644
--- a/mobile-app/components/CredentialCard.tsx
+++ b/mobile-app/components/CredentialCard.tsx
@@ -1,13 +1,13 @@
-import { StyleSheet, View, Text } from 'react-native';
+import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
import { CredentialIcon } from './CredentialIcon';
import { useColors } from '@/hooks/useColorScheme';
import { Credential } from '@/utils/types/Credential';
+import { router } from 'expo-router';
type CredentialCardProps = {
credential: Credential;
};
-
export function CredentialCard({ credential }: CredentialCardProps) {
const colors = useColors();
@@ -34,6 +34,14 @@ export function CredentialCard({ credential }: CredentialCardProps) {
};
const styles = StyleSheet.create({
+ credentialCard: {
+ backgroundColor: colors.accentBackground,
+ borderRadius: 8,
+ padding: 12,
+ marginBottom: 8,
+ borderWidth: 1,
+ borderColor: colors.accentBorder,
+ },
credentialContent: {
flexDirection: 'row',
alignItems: 'center',
@@ -60,16 +68,22 @@ export function CredentialCard({ credential }: CredentialCardProps) {
});
return (
- <View style={styles.credentialContent}>
- <CredentialIcon logo={credential.Logo} style={styles.logo} />
- <View style={styles.credentialInfo}>
- <Text style={[styles.serviceName]}>
- {credential.ServiceName ?? 'Unknown Service'}
- </Text>
- <Text style={[styles.credentialText]}>
- {getCredentialDisplayText(credential)}
- </Text>
+ <TouchableOpacity
+ style={styles.credentialCard}
+ onPress={() => router.push(`/(tabs)/(credentials)/${credential.Id}`)}
+ activeOpacity={0.7}
+ >
+ <View style={styles.credentialContent}>
+ <CredentialIcon logo={credential.Logo} style={styles.logo} />
+ <View style={styles.credentialInfo}>
+ <Text style={[styles.serviceName]}>
+ {credential.ServiceName ?? 'Unknown Service'}
+ </Text>
+ <Text style={[styles.credentialText]}>
+ {getCredentialDisplayText(credential)}
+ </Text>
+ </View>
</View>
- </View>
+ </TouchableOpacity>
);
}
diff --git a/mobile-app/components/EmailCard.tsx b/mobile-app/components/EmailCard.tsx
new file mode 100644
index 000000000..439ff290e
--- /dev/null
+++ b/mobile-app/components/EmailCard.tsx
@@ -0,0 +1,98 @@
+import { StyleSheet, View, TouchableOpacity } from 'react-native';
+import { useColors } from '@/hooks/useColorScheme';
+import { ThemedText } from './ThemedText';
+import { MailboxEmail } from '@/utils/types/webapi/MailboxEmail';
+import { router } from 'expo-router';
+
+type EmailCardProps = {
+ email: MailboxEmail;
+};
+
+export function EmailCard({ email }: EmailCardProps) {
+ const colors = useColors();
+
+ const formatEmailDate = (dateSystem: string): string => {
+ const now = new Date();
+ const emailDate = new Date(dateSystem);
+ const secondsAgo = Math.floor((now.getTime() - emailDate.getTime()) / 1000);
+
+ if (secondsAgo < 60) {
+ return 'just now';
+ } else if (secondsAgo < 3600) {
+ const minutes = Math.floor(secondsAgo / 60);
+ return `${minutes} ${minutes === 1 ? 'min' : 'mins'} ago`;
+ } else if (secondsAgo < 86400) {
+ const hours = Math.floor(secondsAgo / 3600);
+ return `${hours} ${hours === 1 ? 'hr' : 'hrs'} ago`;
+ } else if (secondsAgo < 172800) {
+ return 'yesterday';
+ } else {
+ return emailDate.toLocaleDateString('en-GB', {
+ day: '2-digit',
+ month: '2-digit'
+ });
+ }
+ };
+
+ const styles = StyleSheet.create({
+ emailCard: {
+ backgroundColor: colors.accentBackground,
+ borderRadius: 8,
+ padding: 12,
+ marginBottom: 12,
+ borderWidth: 1,
+ borderColor: colors.accentBorder,
+ shadowColor: colors.text,
+ shadowOffset: {
+ width: 0,
+ height: 2,
+ },
+ shadowOpacity: 0.1,
+ shadowRadius: 3,
+ elevation: 3,
+ },
+ emailHeader: {
+ flexDirection: 'row',
+ justifyContent: 'space-between',
+ alignItems: 'flex-start',
+ marginBottom: 8,
+ },
+ emailSubject: {
+ flex: 1,
+ fontSize: 16,
+ fontWeight: 'bold',
+ marginRight: 8,
+ color: colors.text,
+ },
+ emailDate: {
+ fontSize: 12,
+ opacity: 0.6,
+ color: colors.textMuted,
+ },
+ emailPreview: {
+ fontSize: 14,
+ opacity: 0.8,
+ color: colors.text,
+ },
+ });
+
+ return (
+ <TouchableOpacity
+ style={styles.emailCard}
+ onPress={() => router.push(`/emails/${email.id}`)}
+ activeOpacity={0.7}
+ >
+ <View style={styles.emailHeader}>
+ <ThemedText style={styles.emailSubject} numberOfLines={1}>
+ {email.subject}
+ </ThemedText>
+ <ThemedText style={styles.emailDate}>
+ {formatEmailDate(email.dateSystem)}
+ </ThemedText>
+ </View>
+ <ThemedText style={styles.emailPreview} numberOfLines={2}>
+ {email.messagePreview}
+ </ThemedText>
+ </TouchableOpacity>
+ );
+}
\ No newline at end of file