The minimalistic document archiving platform.
refactor(mobile): improved main document screen (#1335)
Corentin Thomasset236d8034be13
diff --git a/apps/mobile/src/modules/documents/screens/documents-list.screen.tsx b/apps/mobile/src/modules/documents/screens/documents-list.screen.tsxindex 9e7395cd..342953eb 100644--- a/apps/mobile/src/modules/documents/screens/documents-list.screen.tsx+++ b/apps/mobile/src/modules/documents/screens/documents-list.screen.tsx@@ -1,13 +1,22 @@import type { ThemeColors } from '@/modules/ui/theme.constants';import { useQuery } from '@tanstack/react-query';+import { router } from 'expo-router';import { useState } from 'react';-import { ActivityIndicator, RefreshControl, StyleSheet, Text, View } from 'react-native';+import {+ ActivityIndicator,+ RefreshControl,+ StyleSheet,+ Text,+ TouchableOpacity,+ View,+} from 'react-native';import { SafeAreaView } from 'react-native-safe-area-context';import { useApiClient } from '@/modules/api/providers/api.provider';import { DocumentsList } from '@/modules/documents/components/documents-list';import { OrganizationPickerButton } from '@/modules/organizations/components/organization-picker-button';import { OrganizationPickerDrawer } from '@/modules/organizations/components/organization-picker-drawer';import { useOrganizations } from '@/modules/organizations/organizations.provider';+import { Icon } from '@/modules/ui/components/icon';import { useThemeColor } from '@/modules/ui/providers/use-theme-color';import { fetchOrganizationDocuments } from '../documents.services';import { syncUnsyncedDocuments } from '../documents.sync.services';@@ -55,8 +64,29 @@ export function DocumentsListScreen() {return (<SafeAreaView style={styles.container}><View style={styles.header}>+ <View style={styles.topRow}>+ <OrganizationPickerButton variant="plain" onPress={() => setIsDrawerVisible(true)} />+ <TouchableOpacity+ style={styles.userButton}+ onPress={() => router.navigate('/(app)/(with-organizations)/(tabs)/settings')}+ accessibilityRole="button"+ accessibilityLabel="User settings"+ >+ <Icon name="user" size={20} color={themeColors.foreground} />+ </TouchableOpacity>+ </View>+<Text style={styles.title}>Documents</Text>- <OrganizationPickerButton onPress={() => setIsDrawerVisible(true)} />++ <TouchableOpacity+ style={styles.searchButton}+ onPress={() => router.navigate('/(app)/(with-organizations)/(tabs)/search')}+ accessibilityRole="button"+ accessibilityLabel="Search documents"+ >+ <Icon name="search" size={18} color={themeColors.mutedForeground} />+ <Text style={styles.searchButtonText}>Search documents</Text>+ </TouchableOpacity></View>{documentsQuery.isLoading ? (@@ -97,15 +127,44 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {},header: {padding: 16,- paddingTop: 20,+ paddingTop: 12,+ gap: 12,+ },+ topRow: {+ flexDirection: 'row',+ alignItems: 'center',+ justifyContent: 'space-between',gap: 12,- borderBottomWidth: 1,- borderBottomColor: themeColors.border,+ },+ userButton: {+ width: 36,+ height: 36,+ borderRadius: 18,+ alignItems: 'center',+ justifyContent: 'center',+ backgroundColor: themeColors.secondaryBackground,+ borderWidth: 1,+ borderColor: themeColors.border,},title: {fontSize: 28,fontWeight: 'bold',color: themeColors.foreground,},+ searchButton: {+ flexDirection: 'row',+ alignItems: 'center',+ gap: 8,+ height: 44,+ paddingHorizontal: 12,+ borderWidth: 1,+ borderColor: themeColors.border,+ borderRadius: 8,+ backgroundColor: themeColors.secondaryBackground,+ },+ searchButtonText: {+ fontSize: 16,+ color: themeColors.mutedForeground,+ },});}diff --git a/apps/mobile/src/modules/documents/screens/documents-search.screen.tsx b/apps/mobile/src/modules/documents/screens/documents-search.screen.tsxindex 267b4ccb..03aef000 100644--- a/apps/mobile/src/modules/documents/screens/documents-search.screen.tsx+++ b/apps/mobile/src/modules/documents/screens/documents-search.screen.tsx@@ -1,7 +1,7 @@import type { ThemeColors } from '@/modules/ui/theme.constants';import { useQuery } from '@tanstack/react-query';-import { router } from 'expo-router';-import { useEffect, useState } from 'react';+import { router, useFocusEffect } from 'expo-router';+import { useCallback, useEffect, useRef, useState } from 'react';import {ActivityIndicator,Keyboard,@@ -29,6 +29,17 @@ export function DocumentsSearchScreen() {const [searchQuery, setSearchQuery] = useState('');const [debouncedSearchQuery, setDebouncedSearchQuery] = useState('');+ const searchInputRef = useRef<TextInput>(null);++ // autoFocus only applies on mount, but the tab screen stays mounted+ // after the first visit; the delay lets the tab transition settle so+ // the keyboard reliably opens+ useFocusEffect(+ useCallback(() => {+ const timeout = setTimeout(() => searchInputRef.current?.focus(), 100);+ return () => clearTimeout(timeout);+ }, []),+ );useEffect(() => {const timeout = setTimeout(@@ -82,12 +93,12 @@ export function DocumentsSearchScreen() {<View style={styles.searchInputContainer}><Icon name="search" size={18} color={themeColors.mutedForeground} /><TextInput+ ref={searchInputRef}style={styles.searchInput}placeholder="Search documents"placeholderTextColor={themeColors.mutedForeground}value={searchQuery}onChangeText={setSearchQuery}- autoFocusautoCapitalize="none"autoCorrect={false}returnKeyType="search"diff --git a/apps/mobile/src/modules/organizations/components/organization-picker-button.tsx b/apps/mobile/src/modules/organizations/components/organization-picker-button.tsxindex fb3fbe7a..695f0f24 100644--- a/apps/mobile/src/modules/organizations/components/organization-picker-button.tsx+++ b/apps/mobile/src/modules/organizations/components/organization-picker-button.tsx@@ -6,21 +6,38 @@ import { useOrganizations } from '../organizations.provider';type OrganizationPickerButtonProps = {onPress: () => void;+ variant?: 'boxed' | 'plain';};-export function OrganizationPickerButton({ onPress }: OrganizationPickerButtonProps) {+export function OrganizationPickerButton({+ onPress,+ variant = 'boxed',+}: OrganizationPickerButtonProps) {const themeColors = useThemeColor();const { organizations, currentOrganizationId } = useOrganizations();const styles = createStyles({ themeColors });const currentOrganization = organizations.find((org) => org.id === currentOrganizationId);+ const organizationName = currentOrganization?.name ?? 'Select Organization';++ if (variant === 'plain') {+ return (+ <TouchableOpacity style={styles.plainButton} onPress={onPress}>+ <Icon name="briefcase" size={18} color={themeColors.foreground} />+ <Text style={styles.orgName} numberOfLines={1}>+ {organizationName}+ </Text>+ <Icon name="chevron-down" style={styles.caret} size={18} />+ </TouchableOpacity>+ );+ }return (<TouchableOpacity style={styles.button} onPress={onPress}><View style={styles.content}><Text style={styles.orgName} numberOfLines={1}>- {currentOrganization?.name ?? 'Select Organization'}+ {organizationName}</Text></View><Icon name="chevron-down" style={styles.caret} size={20} />@@ -41,6 +58,12 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {borderWidth: 1,borderColor: themeColors.border,},+ plainButton: {+ flexDirection: 'row',+ alignItems: 'center',+ gap: 8,+ flexShrink: 1,+ },content: {flex: 1,marginRight: 8,@@ -51,6 +74,7 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {marginBottom: 2,},orgName: {+ flexShrink: 1,fontSize: 16,fontWeight: '600',color: themeColors.foreground,