Skip to content

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

Add email preview component (#771)

Leendert de Borstaf3e455477f2
diff --git a/mobile-app/app/(tabs)/(credentials)/[id].tsx b/mobile-app/app/(tabs)/(credentials)/[id].tsx
index 0061850f8..30dd867cc 100644
--- a/mobile-app/app/(tabs)/(credentials)/[id].tsx
+++ b/mobile-app/app/(tabs)/(credentials)/[id].tsx
@@ -11,6 +11,7 @@ import { Credential } from '@/utils/types/Credential';
import { LoginCredentials } from '@/components/credentialDetails/LoginCredentials';
import { AliasDetails } from '@/components/credentialDetails/AliasDetails';
import { NotesSection } from '@/components/credentialDetails/NotesSection';
+import { EmailPreview } from '@/components/credentialDetails/EmailPreview';
export default function CredentialDetailsScreen() {
const { id } = useLocalSearchParams();
@@ -77,6 +78,7 @@ export default function CredentialDetailsScreen() {
)}
</View>
</ThemedView>
+ <EmailPreview email={credential.Alias.Email} />
<NotesSection credential={credential} />
<LoginCredentials credential={credential} />
<AliasDetails credential={credential} />
diff --git a/mobile-app/app/(tabs)/(credentials)/_layout.tsx b/mobile-app/app/(tabs)/(credentials)/_layout.tsx
index e8aae0f2c..a851b2c78 100644
--- a/mobile-app/app/(tabs)/(credentials)/_layout.tsx
+++ b/mobile-app/app/(tabs)/(credentials)/_layout.tsx
@@ -22,6 +22,16 @@ export default function CredentialsLayout() {
},
}}
/>
+ <Stack.Screen
+ name="email/[id]"
+ options={{
+ title: 'Email Preview',
+ headerShown: true,
+ headerStyle: {
+ backgroundColor: colors.headerBackground,
+ },
+ }}
+ />
</Stack>
);
}
\ No newline at end of file
diff --git a/mobile-app/app/(tabs)/(credentials)/email/[id].tsx b/mobile-app/app/(tabs)/(credentials)/email/[id].tsx
new file mode 100644
index 000000000..2c2601ae8
--- /dev/null
+++ b/mobile-app/app/(tabs)/(credentials)/email/[id].tsx
@@ -0,0 +1,18 @@
+import React from 'react';
+import EmailDetailsScreen from '../../(emails)/[id]';
+
+/**
+ * CredentialEmailPreviewScreen Component
+ *
+ * This screen component displays email details within the credentials tab stack.
+ * It reuses the EmailDetailsScreen component from the emails tab stack to maintain
+ * consistency and provide a seamless user experience.
+ *
+ * Purpose:
+ * - Avoids forcing users to switch between tab stacks when viewing email details
+ * - Maintains UI consistency by reusing the same email details view
+ * - Provides a better user experience by keeping context within the credentials flow
+ */
+export default function CredentialEmailPreviewScreen() {
+ return <EmailDetailsScreen />;
+}
diff --git a/mobile-app/app/(tabs)/(emails)/[id].tsx b/mobile-app/app/(tabs)/(emails)/[id].tsx
index f35878928..d753ff7a2 100644
--- a/mobile-app/app/(tabs)/(emails)/[id].tsx
+++ b/mobile-app/app/(tabs)/(emails)/[id].tsx
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { StyleSheet, View, TouchableOpacity, ActivityIndicator, Alert, Share, useColorScheme, TextInput, Linking } from 'react-native';
-import { useLocalSearchParams, useRouter, useNavigation } from 'expo-router';
+import { useLocalSearchParams, useRouter, useNavigation, Stack } from 'expo-router';
import { Email } from '@/utils/types/webapi/Email';
import { Credential } from '@/utils/types/Credential';
import { useDb } from '@/context/DbContext';
@@ -297,6 +297,7 @@ export default function EmailDetailsScreen() {
if (isLoading) {
return (
<View style={[styles.centerContainer, isDarkMode ? styles.viewDark : styles.viewLight]}>
+ <Stack.Screen options={{ title: 'Email Details' }} />
<ActivityIndicator size="large" />
</View>
);
@@ -428,6 +429,7 @@ export default function EmailDetailsScreen() {
return (
<View style={[styles.container, isDarkMode ? styles.viewDark : styles.viewLight]}>
+ <Stack.Screen options={{ title: 'Email Details' }} />
{metadataView}
{emailView}
{email.attachments && email.attachments.length > 0 && (
diff --git a/mobile-app/components/credentialDetails/AliasDetails.tsx b/mobile-app/components/credentialDetails/AliasDetails.tsx
index 4119c5a79..12194306a 100644
--- a/mobile-app/components/credentialDetails/AliasDetails.tsx
+++ b/mobile-app/components/credentialDetails/AliasDetails.tsx
@@ -56,6 +56,6 @@ const styles = {
section: {
padding: 16,
paddingBottom: 0,
- gap: 12,
+ gap: 8,
},
};
\ No newline at end of file
diff --git a/mobile-app/components/credentialDetails/EmailPreview.tsx b/mobile-app/components/credentialDetails/EmailPreview.tsx
new file mode 100644
index 000000000..bab8e8d59
--- /dev/null
+++ b/mobile-app/components/credentialDetails/EmailPreview.tsx
@@ -0,0 +1,137 @@
+import React, { useState, useEffect } from 'react';
+import { View, StyleSheet, TouchableOpacity } from 'react-native';
+import { useWebApi } from '@/context/WebApiContext';
+import { useDb } from '@/context/DbContext';
+import { MailboxEmail } from '@/utils/types/webapi/MailboxEmail';
+import { MailboxBulkRequest, MailboxBulkResponse } from '@/utils/types/webapi/MailboxBulk';
+import EncryptionUtility from '@/utils/EncryptionUtility';
+import { ThemedText } from '../ThemedText';
+import { useColors } from '@/hooks/useColorScheme';
+import { router } from 'expo-router';
+import { ThemedView } from '../ThemedView';
+type EmailPreviewProps = {
+ email: string | undefined;
+};
+
+export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {
+ const [emails, setEmails] = useState<MailboxEmail[]>([]);
+ const [loading, setLoading] = useState(true);
+ const [lastEmailId, setLastEmailId] = useState<number>(0);
+ const webApi = useWebApi();
+ const dbContext = useDb();
+ const colors = useColors();
+
+ // Sanity check: if no email is provided, don't render anything.
+ if (!email) {
+ return null;
+ }
+
+ useEffect(() => {
+ const loadEmails = async () => {
+ try {
+ if (!dbContext?.sqliteClient) return;
+
+ // Get unique email addresses from all credentials
+ const emailAddresses = await dbContext.sqliteClient.getAllEmailAddresses();
+
+ // For now we only show the latest 2 emails
+ const data = await webApi.post<MailboxBulkRequest, MailboxBulkResponse>('EmailBox/bulk', {
+ addresses: emailAddresses,
+ page: 1,
+ pageSize: 2,
+ });
+
+ // Decrypt emails locally using private key associated with the email address
+ const encryptionKeys = await dbContext.sqliteClient.getAllEncryptionKeys();
+ const decryptedEmails = await EncryptionUtility.decryptEmailList(data.mails, encryptionKeys);
+
+ if (loading && decryptedEmails.length > 0) {
+ setLastEmailId(decryptedEmails[0].id);
+ }
+
+ setEmails(decryptedEmails);
+ } catch (err) {
+ console.error('Error loading emails:', err);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ loadEmails();
+ // Set up auto-refresh interval
+ const interval = setInterval(loadEmails, 2000);
+ return () => clearInterval(interval);
+ }, [email, loading, webApi, dbContext]);
+
+ const styles = StyleSheet.create({
+ section: {
+ padding: 16,
+ paddingBottom: 0,
+ },
+ title: {
+ fontSize: 20,
+ fontWeight: 'bold',
+ marginBottom: 8,
+ color: colors.text,
+ },
+ emailItem: {
+ padding: 12,
+ borderRadius: 8,
+ marginBottom: 12,
+ borderWidth: 1,
+ borderColor: colors.accentBorder,
+ backgroundColor: colors.accentBackground,
+ },
+ subject: {
+ fontSize: 16,
+ color: colors.text,
+ fontWeight: 'bold',
+ },
+ date: {
+ fontSize: 12,
+ opacity: 0.7,
+ color: colors.textMuted,
+ },
+ });
+
+ if (loading) {
+ return (
+ <ThemedView style={styles.section}>
+ <ThemedText type="title" style={styles.title}>Recent emails</ThemedText>
+ <ThemedText>Loading emails...</ThemedText>
+ </ThemedView>
+ );
+ }
+
+ if (emails.length === 0) {
+ return (
+ <ThemedView style={styles.section}>
+ <ThemedText type="title" style={styles.title}>Recent emails</ThemedText>
+ <ThemedText>No emails received yet.</ThemedText>
+ </ThemedView>
+ );
+ }
+
+ return (
+ <ThemedView style={styles.section}>
+ <ThemedText type="title" style={styles.title}>Recent emails</ThemedText>
+ {emails.map((mail) => (
+ <TouchableOpacity
+ key={mail.id}
+ style={[
+ styles.emailItem,
+ mail.id > lastEmailId && { backgroundColor: colors.accentBackground }
+ ]}
+ onPress={() => router.push(`/(tabs)/(credentials)/email/${mail.id}`)}
+ >
+ <ThemedText style={styles.subject} numberOfLines={1}>
+ {mail.subject}
+ </ThemedText>
+ <ThemedText style={styles.date}>
+ {new Date(mail.dateSystem).toLocaleDateString()}
+ </ThemedText>
+ </TouchableOpacity>
+ ))}
+ </ThemedView>
+ );
+};
\ No newline at end of file
diff --git a/mobile-app/components/credentialDetails/LoginCredentials.tsx b/mobile-app/components/credentialDetails/LoginCredentials.tsx
index b67b434b7..5c70f4dbe 100644
--- a/mobile-app/components/credentialDetails/LoginCredentials.tsx
+++ b/mobile-app/components/credentialDetails/LoginCredentials.tsx
@@ -43,6 +43,6 @@ const styles = {
section: {
padding: 16,
paddingBottom: 0,
- gap: 12,
+ gap: 8,
},
};
\ No newline at end of file
diff --git a/mobile-app/components/credentialDetails/NotesSection.tsx b/mobile-app/components/credentialDetails/NotesSection.tsx
index bbfb1db44..2a8d2c325 100644
--- a/mobile-app/components/credentialDetails/NotesSection.tsx
+++ b/mobile-app/components/credentialDetails/NotesSection.tsx
@@ -106,7 +106,7 @@ const styles = StyleSheet.create({
section: {
padding: 16,
paddingBottom: 8,
- gap: 12,
+ gap: 8,
},
notesContainer: {
padding: 12,