Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor item dropdown menu to separate component in mobile app (#2090)
Leendert de Borst6f7662f1066d
diff --git a/apps/mobile-app/app/(tabs)/items/index.tsx b/apps/mobile-app/app/(tabs)/items/index.tsxindex c4aab7a3d..50e7611b7 100644--- a/apps/mobile-app/app/(tabs)/items/index.tsx+++ b/apps/mobile-app/app/(tabs)/items/index.tsx@@ -26,6 +26,7 @@ import { ConfirmDialog } from '@/components/common/ConfirmDialog';import { FolderModal } from '@/components/folders/FolderModal';import { FolderPill, type FolderWithCount } from '@/components/folders/FolderPill';import { ItemCard } from '@/components/items/ItemCard';+import { ItemFilterMenu } from '@/components/items/ItemFilterMenu';import { SortMenu } from '@/components/items/SortMenu';import { ThemedContainer } from '@/components/themed/ThemedContainer';import { ThemedText } from '@/components/themed/ThemedText';@@ -586,88 +587,6 @@ export default function ItemsScreen(): React.ReactNode {fontSize: 20,lineHeight: 28,},- // Filter menu styles- filterMenuOverlay: {- backgroundColor: colors.accentBackground,- borderColor: colors.accentBorder,- borderRadius: 8,- borderWidth: 1,- elevation: 8,- left: 14,- overflow: 'hidden',- position: 'absolute',- right: 14,- shadowColor: colors.black,- shadowOffset: { width: 0, height: 2 },- shadowOpacity: 0.25,- shadowRadius: 4,- top: Platform.OS === 'ios' ? insets.top + 112 : 8,- zIndex: 1001,- },- filterMenuBackdrop: {- bottom: 0,- left: 0,- position: 'absolute',- right: 0,- top: 0,- zIndex: 1000,- },- filterMenuItem: {- paddingHorizontal: 16,- paddingVertical: 12,- },- filterMenuItemWithIcon: {- alignItems: 'center',- flexDirection: 'row',- gap: 8,- },- filterMenuItemIcon: {- width: 18,- },- filterMenuItemActive: {- backgroundColor: colors.primary + '20',- },- filterMenuItemText: {- color: colors.text,- fontSize: 14,- },- filterMenuItemTextActive: {- color: colors.primary,- fontWeight: '600',- },- filterMenuSeparator: {- backgroundColor: colors.accentBorder,- height: 1,- marginVertical: 4,- },- filterMenuItemWithBadge: {- alignItems: 'center',- flexDirection: 'row',- justifyContent: 'space-between',- width: '100%',- },- filterMenuItemWithToggle: {- alignItems: 'center',- flexDirection: 'row',- justifyContent: 'space-between',- },- filterMenuItemLabel: {- flex: 1,- },- filterMenuItemToggle: {- alignItems: 'center',- flexDirection: 'row',- gap: 6,- padding: 4,- },- filterMenuToggleHint: {- color: colors.textMuted,- fontSize: 12,- },- filterMenuItemBadge: {- color: colors.textMuted,- fontSize: 14,- },// Folder pills stylesfolderPillsContainer: {flexDirection: 'row',@@ -804,183 +723,6 @@ export default function ItemsScreen(): React.ReactNode {},});- /**- * Render the filter menu as an absolute overlay.- */- const renderFilterOverlay = (): React.ReactNode => {- if (!showFilterMenu) {- return null;- }-- return (- <>- {/* Backdrop to close menu when tapping outside */}- <TouchableOpacity- style={styles.filterMenuBackdrop}- activeOpacity={1}- onPress={() => setShowFilterMenu(false)}- />- {/* Menu content */}- <ThemedView style={styles.filterMenuOverlay}>- {/* Items filter with include folders toggle */}- <View- style={[- styles.filterMenuItem,- styles.filterMenuItemWithToggle,- filterType === 'all' && styles.filterMenuItemActive- ]}- >- <TouchableOpacity- style={styles.filterMenuItemLabel}- onPress={() => {- setFilterType('all');- setShowFilterMenu(false);- }}- >- <ThemedText style={[- styles.filterMenuItemText,- filterType === 'all' && styles.filterMenuItemTextActive- ]}>- {t('items.filters.all')}- </ThemedText>- </TouchableOpacity>- <TouchableOpacity- style={styles.filterMenuItemToggle}- onPress={() => {- const newValue = !showFolderItems;- setShowFolderItems(newValue);- LocalPreferencesService.setShowFolders(newValue);- setShowFilterMenu(false);- }}- hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}- >- <ThemedText style={styles.filterMenuToggleHint}>- {t('items.filters.showFolders')}- </ThemedText>- <MaterialIcons- name={showFolderItems ? 'check-box' : 'check-box-outline-blank'}- size={20}- color={showFolderItems ? colors.primary : colors.textMuted}- />- </TouchableOpacity>- </View>-- <ThemedView style={styles.filterMenuSeparator} />-- {/* Item type filters */}- {ITEM_TYPE_OPTIONS.map((option) => (- <TouchableOpacity- key={option.type}- style={[- styles.filterMenuItem,- styles.filterMenuItemWithIcon,- filterType === option.type && styles.filterMenuItemActive- ]}- onPress={() => {- setFilterType(option.type);- setShowFilterMenu(false);- }}- >- <MaterialIcons- name={option.iconName}- size={18}- color={filterType === option.type ? colors.primary : colors.textMuted}- style={styles.filterMenuItemIcon}- />- <ThemedText style={[- styles.filterMenuItemText,- filterType === option.type && styles.filterMenuItemTextActive- ]}>- {t(option.titleKey)}- </ThemedText>- </TouchableOpacity>- ))}-- <ThemedView style={styles.filterMenuSeparator} />-- {/* Passkeys filter */}- <TouchableOpacity- style={[- styles.filterMenuItem,- filterType === 'passkeys' && styles.filterMenuItemActive- ]}- onPress={() => {- setFilterType('passkeys');- setShowFilterMenu(false);- }}- >- <ThemedText style={[- styles.filterMenuItemText,- filterType === 'passkeys' && styles.filterMenuItemTextActive- ]}>- {t('items.filters.passkeys')}- </ThemedText>- </TouchableOpacity>-- {/* Attachments filter */}- <TouchableOpacity- style={[- styles.filterMenuItem,- filterType === 'attachments' && styles.filterMenuItemActive- ]}- onPress={() => {- setFilterType('attachments');- setShowFilterMenu(false);- }}- >- <ThemedText style={[- styles.filterMenuItemText,- filterType === 'attachments' && styles.filterMenuItemTextActive- ]}>- {t('common.attachments')}- </ThemedText>- </TouchableOpacity>-- {/* TOTP filter */}- <TouchableOpacity- style={[- styles.filterMenuItem,- filterType === 'totp' && styles.filterMenuItemActive- ]}- onPress={() => {- setFilterType('totp');- setShowFilterMenu(false);- }}- >- <ThemedText style={[- styles.filterMenuItemText,- filterType === 'totp' && styles.filterMenuItemTextActive- ]}>- {t('items.filters.totp')}- </ThemedText>- </TouchableOpacity>-- <ThemedView style={styles.filterMenuSeparator} />-- {/* Recently deleted */}- <TouchableOpacity- style={styles.filterMenuItem}- onPress={() => {- setShowFilterMenu(false);- router.push('/(tabs)/items/deleted');- }}- >- <View style={styles.filterMenuItemWithBadge}>- <ThemedText style={styles.filterMenuItemText}>- {t('items.recentlyDeleted.title')}- </ThemedText>- {recentlyDeletedCount > 0 && (- <ThemedText style={styles.filterMenuItemBadge}>- {recentlyDeletedCount}- </ThemedText>- )}- </View>- </TouchableOpacity>- </ThemedView>- </>- );- };-/*** Render the list header with filter button, folders, and search.*/@@ -1229,7 +971,20 @@ export default function ItemsScreen(): React.ReactNode {</ThemedView>{/* Filter menu overlay */}- {renderFilterOverlay()}+ <ItemFilterMenu+ visible={showFilterMenu}+ activeFilter={filterType}+ recentlyDeletedCount={recentlyDeletedCount}+ showFoldersToggle+ showFolders={showFolderItems}+ onClose={() => setShowFilterMenu(false)}+ onSelectFilter={(filter) => setFilterType(filter)}+ onSelectRecentlyDeleted={() => router.push('/(tabs)/items/deleted')}+ onToggleShowFolders={(next) => {+ setShowFolderItems(next);+ LocalPreferencesService.setShowFolders(next);+ }}+ />{/* Sort menu overlay */}<SortMenudiff --git a/apps/mobile-app/components/items/ItemFilterMenu.tsx b/apps/mobile-app/components/items/ItemFilterMenu.tsxnew file mode 100644index 000000000..b8d32a492--- /dev/null+++ b/apps/mobile-app/components/items/ItemFilterMenu.tsx@@ -0,0 +1,276 @@+import MaterialIcons from '@expo/vector-icons/MaterialIcons';+import { useTranslation } from 'react-i18next';+import { Platform, StyleSheet, TouchableOpacity, View } from 'react-native';+import { useSafeAreaInsets } from 'react-native-safe-area-context';++import { ItemTypes, type ItemType } from '@/utils/dist/core/models/vault';+import type { ItemFilterType } from '@/utils/ItemFilters';++import { useColors } from '@/hooks/useColorScheme';++import { ThemedText } from '@/components/themed/ThemedText';+import { ThemedView } from '@/components/themed/ThemedView';++/**+ * Active selection — `'deleted'` means the Recently Deleted page is current+ * and no item filter is highlighted.+ */+export type ItemFilterSelection = ItemFilterType | 'deleted';++type ItemTypeOption = {+ type: ItemType;+ titleKey: string;+ iconName: keyof typeof MaterialIcons.glyphMap;+};++const ITEM_TYPE_OPTIONS: ItemTypeOption[] = [+ { type: ItemTypes.Login, titleKey: 'itemTypes.login.title', iconName: 'key' },+ { type: ItemTypes.Alias, titleKey: 'itemTypes.alias.title', iconName: 'person' },+ { type: ItemTypes.CreditCard, titleKey: 'itemTypes.creditCard.title', iconName: 'credit-card' },+ { type: ItemTypes.Note, titleKey: 'itemTypes.note.title', iconName: 'description' },+];++interface ItemFilterMenuProps {+ visible: boolean;+ activeFilter: ItemFilterSelection;+ recentlyDeletedCount: number;+ showFoldersToggle?: boolean;+ showFolders?: boolean;+ /** Optional override for the overlay's top offset (used to position below custom headers). */+ topOffset?: number;+ onSelectFilter: (filter: ItemFilterType) => void;+ onSelectRecentlyDeleted: () => void;+ onToggleShowFolders?: (next: boolean) => void;+ onClose: () => void;+}++/**+ * Filter menu overlay used by the items list and Recently Deleted screens. The+ * caller renders its own trigger (e.g. in the screen header) and controls the+ * `visible` flag.+ */+export function ItemFilterMenu({+ visible,+ activeFilter,+ recentlyDeletedCount,+ showFoldersToggle = false,+ showFolders = false,+ topOffset,+ onSelectFilter,+ onSelectRecentlyDeleted,+ onToggleShowFolders,+ onClose,+}: ItemFilterMenuProps): React.ReactNode {+ const { t } = useTranslation();+ const colors = useColors();+ const insets = useSafeAreaInsets();++ if (!visible) {+ return null;+ }++ const defaultTopOffset = Platform.OS === 'ios' ? insets.top + 112 : 8;+ const resolvedTopOffset = topOffset ?? defaultTopOffset;++ const styles = StyleSheet.create({+ overlay: {+ backgroundColor: colors.accentBackground,+ borderColor: colors.accentBorder,+ borderRadius: 8,+ borderWidth: 1,+ elevation: 8,+ left: 14,+ overflow: 'hidden',+ position: 'absolute',+ right: 14,+ shadowColor: colors.black,+ shadowOffset: { width: 0, height: 2 },+ shadowOpacity: 0.25,+ shadowRadius: 4,+ top: resolvedTopOffset,+ zIndex: 1001,+ },+ backdrop: {+ bottom: 0,+ left: 0,+ position: 'absolute',+ right: 0,+ top: 0,+ zIndex: 1000,+ },+ item: {+ paddingHorizontal: 16,+ paddingVertical: 12,+ },+ itemWithIcon: {+ alignItems: 'center',+ flexDirection: 'row',+ gap: 8,+ },+ icon: {+ width: 18,+ },+ itemActive: {+ backgroundColor: colors.primary + '20',+ },+ itemText: {+ color: colors.text,+ fontSize: 14,+ },+ itemTextActive: {+ color: colors.primary,+ fontWeight: '600',+ },+ separator: {+ backgroundColor: colors.accentBorder,+ height: 1,+ marginVertical: 4,+ },+ itemWithBadge: {+ alignItems: 'center',+ flexDirection: 'row',+ justifyContent: 'space-between',+ width: '100%',+ },+ itemWithToggle: {+ alignItems: 'center',+ flexDirection: 'row',+ justifyContent: 'space-between',+ },+ itemLabel: {+ flex: 1,+ },+ toggle: {+ alignItems: 'center',+ flexDirection: 'row',+ gap: 6,+ padding: 4,+ },+ toggleHint: {+ color: colors.textMuted,+ fontSize: 12,+ },+ badge: {+ color: colors.textMuted,+ fontSize: 14,+ },+ badgeActive: {+ color: colors.primary,+ fontSize: 14,+ },+ });++ const handlePickFilter = (filter: ItemFilterType): void => {+ onClose();+ onSelectFilter(filter);+ };++ const handleRecentlyDeleted = (): void => {+ onClose();+ onSelectRecentlyDeleted();+ };++ const isActive = (filter: ItemFilterType): boolean => activeFilter === filter;+ const isRecentlyDeletedActive = activeFilter === 'deleted';++ return (+ <>+ <TouchableOpacity style={styles.backdrop} activeOpacity={1} onPress={onClose} />+ <ThemedView style={styles.overlay}>+ {/* All items + show folders toggle */}+ <View style={[styles.item, styles.itemWithToggle, isActive('all') && styles.itemActive]}>+ <TouchableOpacity style={styles.itemLabel} onPress={() => handlePickFilter('all')}>+ <ThemedText style={[styles.itemText, isActive('all') && styles.itemTextActive]}>+ {t('items.filters.all')}+ </ThemedText>+ </TouchableOpacity>+ {showFoldersToggle && onToggleShowFolders && (+ <TouchableOpacity+ style={styles.toggle}+ onPress={() => {+ onToggleShowFolders(!showFolders);+ onClose();+ }}+ hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}+ >+ <ThemedText style={styles.toggleHint}>{t('items.filters.showFolders')}</ThemedText>+ <MaterialIcons+ name={showFolders ? 'check-box' : 'check-box-outline-blank'}+ size={20}+ color={showFolders ? colors.primary : colors.textMuted}+ />+ </TouchableOpacity>+ )}+ </View>++ <ThemedView style={styles.separator} />++ {/* Item type filters */}+ {ITEM_TYPE_OPTIONS.map((option) => (+ <TouchableOpacity+ key={option.type}+ style={[styles.item, styles.itemWithIcon, isActive(option.type) && styles.itemActive]}+ onPress={() => handlePickFilter(option.type)}+ >+ <MaterialIcons+ name={option.iconName}+ size={18}+ color={isActive(option.type) ? colors.primary : colors.textMuted}+ style={styles.icon}+ />+ <ThemedText style={[styles.itemText, isActive(option.type) && styles.itemTextActive]}>+ {t(option.titleKey)}+ </ThemedText>+ </TouchableOpacity>+ ))}++ <ThemedView style={styles.separator} />++ {/* Passkeys / Attachments / TOTP */}+ <TouchableOpacity+ style={[styles.item, isActive('passkeys') && styles.itemActive]}+ onPress={() => handlePickFilter('passkeys')}+ >+ <ThemedText style={[styles.itemText, isActive('passkeys') && styles.itemTextActive]}>+ {t('items.filters.passkeys')}+ </ThemedText>+ </TouchableOpacity>+ <TouchableOpacity+ style={[styles.item, isActive('attachments') && styles.itemActive]}+ onPress={() => handlePickFilter('attachments')}+ >+ <ThemedText style={[styles.itemText, isActive('attachments') && styles.itemTextActive]}>+ {t('common.attachments')}+ </ThemedText>+ </TouchableOpacity>+ <TouchableOpacity+ style={[styles.item, isActive('totp') && styles.itemActive]}+ onPress={() => handlePickFilter('totp')}+ >+ <ThemedText style={[styles.itemText, isActive('totp') && styles.itemTextActive]}>+ {t('items.filters.totp')}+ </ThemedText>+ </TouchableOpacity>++ <ThemedView style={styles.separator} />++ {/* Recently deleted */}+ <TouchableOpacity+ style={[styles.item, isRecentlyDeletedActive && styles.itemActive]}+ onPress={handleRecentlyDeleted}+ >+ <View style={styles.itemWithBadge}>+ <ThemedText style={[styles.itemText, isRecentlyDeletedActive && styles.itemTextActive]}>+ {t('items.recentlyDeleted.title')}+ </ThemedText>+ {recentlyDeletedCount > 0 && (+ <ThemedText style={isRecentlyDeletedActive ? styles.badgeActive : styles.badge}>+ {recentlyDeletedCount}+ </ThemedText>+ )}+ </View>+ </TouchableOpacity>+ </ThemedView>+ </>+ );+}