The minimalistic document archiving platform.
refactor(mobile): deduplicate tag component (#1373)
Corentin Thomasset805c34f73bea
diff --git a/apps/mobile/src/modules/documents/components/documents-list.tsx b/apps/mobile/src/modules/documents/components/documents-list.tsxindex 6c0cf539..db33cb66 100644--- a/apps/mobile/src/modules/documents/components/documents-list.tsx+++ b/apps/mobile/src/modules/documents/components/documents-list.tsx@@ -7,6 +7,7 @@ import { router } from 'expo-router';import { useState } from 'react';import { FlatList, StyleSheet, Text, TouchableOpacity, View } from 'react-native';import { DocumentActionSheet } from '@/modules/documents/components/document-action-sheet';+import { Tag } from '@/modules/tags/components/tag';import { Icon } from '@/modules/ui/components/icon';import { useThemeColor } from '@/modules/ui/providers/use-theme-color';@@ -100,15 +101,10 @@ export function DocumentsList({{item.tags.length > 0 && (<View style={styles.tagsContainer}>{item.tags.slice(0, maxVisibleTags).map((tag) => (- <View key={tag.id} style={styles.tag}>- <View style={[styles.tagDot, { backgroundColor: tag.color }]} />- <Text style={styles.tagText}>{tag.name}</Text>- </View>+ <Tag key={tag.id} name={tag.name} color={tag.color} />))}{item.tags.length > maxVisibleTags && (- <View style={styles.tag}>- <Text style={styles.tagText}>+{item.tags.length - maxVisibleTags}</Text>- </View>+ <Tag name={`+${item.tags.length - maxVisibleTags}`} />)}</View>)}@@ -202,26 +198,6 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {gap: 8,marginTop: 6,},- tag: {- flexDirection: 'row',- alignItems: 'center',- gap: 6,- paddingHorizontal: 10,- paddingVertical: 6,- borderRadius: 6,- backgroundColor: themeColors.muted,- },- tagDot: {- width: 6,- height: 6,- borderRadius: 3,- },- tagText: {- fontSize: 12,- fontWeight: '500',- lineHeight: 12,- color: themeColors.mutedForeground,- },unsyncedBadge: {flexDirection: 'row',alignItems: 'center',diff --git a/apps/mobile/src/modules/documents/screens/document-details.screen.tsx b/apps/mobile/src/modules/documents/screens/document-details.screen.tsxindex f9467730..11656aaa 100644--- a/apps/mobile/src/modules/documents/screens/document-details.screen.tsx+++ b/apps/mobile/src/modules/documents/screens/document-details.screen.tsx@@ -20,6 +20,7 @@ import * as Sharing from 'expo-sharing';import { useApiClient, useAuthClient } from '@/modules/api/providers/api.provider';import { DocumentActionSheet } from '@/modules/documents/components/document-action-sheet';import { fetchDocument, fetchDocumentFile } from '@/modules/documents/documents.services';+import { Tag } from '@/modules/tags/components/tag';import { Icon } from '@/modules/ui/components/icon';import { useAlert } from '@/modules/ui/providers/alert-provider';import { useThemeColor } from '@/modules/ui/providers/use-theme-color';@@ -299,10 +300,7 @@ export function DocumentDetailsScreen() {<Text style={styles.sectionTitle}>Tags</Text><View style={styles.tagsContainer}>{document.tags.map((tag) => (- <View key={tag.id} style={styles.tag}>- <View style={[styles.tagDot, { backgroundColor: tag.color }]} />- <Text style={styles.tagText}>{tag.name}</Text>- </View>+ <Tag key={tag.id} name={tag.name} color={tag.color} />))}</View></View>@@ -514,26 +512,6 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {flexWrap: 'wrap',gap: 8,},- tag: {- flexDirection: 'row',- alignItems: 'center',- gap: 6,- paddingHorizontal: 10,- paddingVertical: 6,- borderRadius: 6,- backgroundColor: themeColors.muted,- },- tagDot: {- width: 6,- height: 6,- borderRadius: 3,- },- tagText: {- fontSize: 13,- fontWeight: '500',- lineHeight: 13,- color: themeColors.mutedForeground,- },card: {backgroundColor: themeColors.secondaryBackground,borderRadius: 12,diff --git a/apps/mobile/src/modules/tags/components/tag.tsx b/apps/mobile/src/modules/tags/components/tag.tsxnew file mode 100644index 00000000..d3718918--- /dev/null+++ b/apps/mobile/src/modules/tags/components/tag.tsx@@ -0,0 +1,45 @@+import type { ThemeColors } from '@/modules/ui/theme.constants';+import { StyleSheet, Text, View } from 'react-native';+import { useThemeColor } from '@/modules/ui/providers/use-theme-color';++type TagProps = {+ name: string;+ color?: string;+};++export function Tag({ name, color }: TagProps) {+ const themeColors = useThemeColor();+ const styles = createStyles({ themeColors });++ return (+ <View style={styles.tag}>+ {color !== undefined && <View style={[styles.tagDot, { backgroundColor: color }]} />}+ <Text style={styles.tagText}>{name}</Text>+ </View>+ );+}++function createStyles({ themeColors }: { themeColors: ThemeColors }) {+ return StyleSheet.create({+ tag: {+ flexDirection: 'row',+ alignItems: 'center',+ gap: 6,+ paddingHorizontal: 10,+ paddingVertical: 6,+ borderRadius: 6,+ backgroundColor: themeColors.muted,+ },+ tagDot: {+ width: 6,+ height: 6,+ borderRadius: 3,+ },+ tagText: {+ fontSize: 12,+ fontWeight: '500',+ lineHeight: 12,+ color: themeColors.mutedForeground,+ },+ });+}