Files
MeowSpool/mobile/app/(app)/filaments/[id]/qrcode.tsx
T
Felipe 416e13893c feat: implement authentication flow and session management
- Update RootLayout to handle authentication state and redirect users based on their auth status.
- Create an Index component to redirect unauthenticated users to the login page.
- Modify ApiAuthRepository to fetch user session data using access and refresh tokens.
- Introduce a new container file to manage use case instances for authentication and filament operations.
- Enhance authStore to validate tokens and fetch user data from the API.
- Add babel-plugin-module-resolver for improved module imports.
- Update package.json scripts for running the app on Android and iOS.
- Add expo-camera dependency for camera functionalities.
- Update tsconfig.json to include infrastructure path mapping.
2026-03-14 13:22:17 -03:00

186 lines
5.4 KiB
TypeScript

import React from 'react';
import {
View, Text, TouchableOpacity, StyleSheet, Alert, Share,
} from 'react-native';
import { useLocalSearchParams, useRouter } from 'expo-router';
import { Ionicons } from '@expo/vector-icons';
import { SafeAreaView } from 'react-native-safe-area-context';
import QRCode from 'react-native-qrcode-svg';
import { useFilamentStore } from '@store/filamentStore';
import { colors, typography, spacing, radius } from '@shared/theme';
import { Button } from '@presentation/components/ui/Button';
/**
* Tela de QR Code — 1CF-0
*/
export default function QRCodeScreen(): React.ReactElement {
const { id } = useLocalSearchParams<{ id: string }>();
const router = useRouter();
const { filaments } = useFilamentStore();
const filament = filaments.find((f) => f.id === id);
const slug = filament
? `${filament.brand.toLowerCase()}-${(filament.model ?? '').toLowerCase()}-${filament.colorHex.replace('#', '').toLowerCase()}`.replace(/\s+/g, '-')
: 'desconhecido';
const deepLink = `meowspool://filament/${id}`;
async function handleShare(): Promise<void> {
try {
await Share.share({ message: deepLink });
} catch {
// cancelled
}
}
async function handleCopyLink(): Promise<void> {
Alert.alert('Link', deepLink);
}
if (!filament) {
return (
<SafeAreaView style={styles.safe}>
<View style={styles.notFound}>
<Text style={styles.notFoundText}>Filamento não encontrado</Text>
</View>
</SafeAreaView>
);
}
return (
<SafeAreaView style={styles.safe}>
{/* Header */}
<View style={styles.header}>
<TouchableOpacity onPress={() => router.back()}>
<Ionicons name="chevron-back" size={24} color={colors.textPrimary} />
</TouchableOpacity>
<Text style={styles.headerTitle}>QR Code</Text>
<View style={{ width: 24 }} />
</View>
{/* Filament identity */}
<View style={styles.identity}>
<View style={[styles.swatch, { backgroundColor: filament.colorHex }]} />
<View>
<Text style={styles.name}>
{filament.brand}{filament.model ? ` ${filament.model}` : ''}
</Text>
<Text style={styles.meta}>
{filament.brand} · {filament.material} · {filament.colorHex}
</Text>
</View>
</View>
{/* QR Code area */}
<View style={styles.qrContainer}>
<View style={styles.qrCard}>
<QRCode
value={deepLink}
size={200}
backgroundColor="#F5EFE0"
color="#1E1B18"
/>
</View>
<Text style={styles.qrHint}>Aponte a câmera para escanear</Text>
<View style={styles.linkBadge}>
<Text style={styles.linkText}>{deepLink}</Text>
</View>
</View>
{/* Actions */}
<View style={styles.footer}>
<Button
label="Compartilhar QR Code"
leftIcon={<Ionicons name="share-outline" size={18} color={colors.bgBase} />}
onPress={handleShare}
/>
<TouchableOpacity style={styles.copyBtn} onPress={handleCopyLink}>
<Text style={styles.copyBtnText}>Copiar link</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safe: { flex: 1, backgroundColor: colors.bgBase },
notFound: { flex: 1, alignItems: 'center', justifyContent: 'center' },
notFoundText: { fontFamily: typography.fontFamily.ui, fontSize: typography.fontSize.base, color: colors.textSecondary },
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: spacing[5],
paddingVertical: spacing[4],
},
headerTitle: {
fontFamily: typography.fontFamily.ui,
fontSize: typography.fontSize.md,
fontWeight: typography.fontWeight.semibold,
color: colors.textPrimary,
},
identity: {
flexDirection: 'row',
alignItems: 'center',
gap: spacing[3],
paddingHorizontal: spacing[5],
paddingBottom: spacing[4],
},
swatch: { width: 44, height: 44, borderRadius: radius.md },
name: {
fontFamily: typography.fontFamily.ui,
fontSize: typography.fontSize.base,
fontWeight: typography.fontWeight.semibold,
color: colors.textPrimary,
},
meta: {
fontFamily: typography.fontFamily.ui,
fontSize: typography.fontSize.sm,
color: colors.textSecondary,
},
qrContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
gap: spacing[4],
paddingHorizontal: spacing[5],
},
qrCard: {
backgroundColor: '#F5EFE0',
borderRadius: radius.xl,
padding: spacing[6],
},
qrHint: {
fontFamily: typography.fontFamily.ui,
fontSize: typography.fontSize.sm,
color: colors.textSecondary,
},
linkBadge: {
backgroundColor: colors.bgSurface,
paddingHorizontal: spacing[4],
paddingVertical: spacing[2],
borderRadius: radius.full,
borderWidth: 1,
borderColor: colors.border,
},
linkText: {
fontFamily: typography.fontFamily.mono,
fontSize: typography.fontSize.xs,
color: colors.accent,
},
footer: {
padding: spacing[5],
gap: spacing[3],
borderTopWidth: 1,
borderTopColor: colors.border,
backgroundColor: colors.bgBase,
},
copyBtn: { alignItems: 'center', paddingVertical: spacing[2] },
copyBtnText: {
fontFamily: typography.fontFamily.ui,
fontSize: typography.fontSize.base,
color: colors.textSecondary,
},
});