From 4583093f358e0e174abd5f395b7e02e81122bdad Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 18 Jun 2025 18:35:59 -0700 Subject: [PATCH] Set and persist a data directory --- app/(tabs)/index.tsx | 39 +--- app/SettingsScreen.tsx | 103 +++++++-- app/_layout.tsx | 20 +- babel.config.js | 2 +- constants/Settings.ts | 0 ios/MyJourney/Info.plist | 6 + package-lock.json | 485 +++++++++++++++++++++++++++++++++++++++ package.json | 6 +- 8 files changed, 601 insertions(+), 60 deletions(-) create mode 100644 constants/Settings.ts diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 84bc650..2aa7141 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -5,6 +5,7 @@ import { HelloWave } from '@/components/HelloWave'; import ParallaxScrollView from '@/components/ParallaxScrollView'; import { ThemedText } from '@/components/ThemedText'; import { ThemedView } from '@/components/ThemedView'; +import { Text } from 'react-native-paper'; export default function HomeScreen() { return ( @@ -16,41 +17,9 @@ export default function HomeScreen() { style={styles.headerImage} /> }> - - Welcome bruh. - - - - Step 1: Try it - - Edit app/(tabs)/index.tsx to see changes. - Press{' '} - - {Platform.select({ - ios: 'cmd + d', - android: 'cmd + m', - web: 'F12', - })} - {' '} - to open developer tools. - - - - Step 2: Explore - - {`Tap the Explore tab to learn more about what's included in this starter app.`} - - - - Step 3: Get a fresh start - - {`When you're ready, run `} - npm run reset-project to get a fresh{' '} - app directory. This will move the current{' '} - app to{' '} - app-example. - - + + My Journey + ); } diff --git a/app/SettingsScreen.tsx b/app/SettingsScreen.tsx index 6c069b2..d824e20 100644 --- a/app/SettingsScreen.tsx +++ b/app/SettingsScreen.tsx @@ -1,27 +1,92 @@ -import { useState } from 'react'; -import { Button, Text, View } from 'react-native'; +import { useEffect, useState } from 'react'; +import { Button, View } from 'react-native'; import { pickDirectory } from '@react-native-documents/picker' +import { List, Text } from 'react-native-paper'; +import { Directory, Paths } from 'expo-file-system/next'; +import { StorageAccessFramework } from 'expo-file-system'; +import AsyncStorage from '@react-native-async-storage/async-storage'; + +const DATA_DIRECTORY_URI_KEY = 'dataDirectoryUri'; + +const prettyName = (uri: string | null) => { + if (!uri) return null; + const decodedUri = decodeURIComponent(uri); + const match = decodedUri.match(/.*\/primary:(.+)/); + + if (match) { + return match[1]; + } + + // Fallback to your original logic + return uri.split('%3A').pop() || "Unknown"; + +} export default function SettingsScreen() { const [directoryUri, setDirectoryUri] = useState(null); + // Load saved directory URI on component mount + useEffect(() => { + const loadDirectoryUri = async () => { + try { + const savedUri = await AsyncStorage.getItem(DATA_DIRECTORY_URI_KEY); + if (savedUri) { + setDirectoryUri(savedUri); + } + } catch (error) { + console.error('Error loading directory URI:', error); + } + }; + + loadDirectoryUri(); + }, []); + + // Save directory URI whenever it changes + const saveDirectoryUri = async (uri: string | null) => { + try { + if (uri) { + await AsyncStorage.setItem(DATA_DIRECTORY_URI_KEY, uri); + } else { + await AsyncStorage.removeItem(DATA_DIRECTORY_URI_KEY); + } + setDirectoryUri(uri); + } catch (error) { + console.error('Error saving directory URI:', error); + } + }; + return ( - - {directoryUri ?? "No directory set."} -