diff --git a/app/ProfileScreen.tsx b/app/ProfileScreen.tsx index 7fbecc4..039e516 100644 --- a/app/ProfileScreen.tsx +++ b/app/ProfileScreen.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState, useContext } from 'react'; +import React, { useEffect, useState } from 'react'; import { Platform, View, TouchableOpacity, StyleSheet } from "react-native"; import { Button, TextInput, Dialog, Portal, Avatar, useTheme, Text } from "react-native-paper"; import { Asset } from 'expo-asset'; @@ -16,10 +16,11 @@ interface ProfileScreenProps { setImage: (image: string) => void; setChanged: (dataChanged: boolean) => void; setTheme: (theme: string) => void; + currentTheme: string; onClose: () => void; } -const ProfileScreen: React.FC = ({ visible, name, setName, image, setImage, setChanged, setTheme, onClose }) => { +const ProfileScreen: React.FC = ({ visible, name, setName, image, setImage, setChanged, currentTheme, setTheme, onClose }) => { const theme = useTheme(); const isNameEmpty = !name.trim(); const themeColors = ['red', 'blue', 'yellow', 'green', 'orange', 'purple']; @@ -27,11 +28,13 @@ const ProfileScreen: React.FC = ({ visible, name, setName, i // Track the initial values when the component first mounts const [initialName, setInitialName] = useState(name); const [initialImage, setInitialImage] = useState(image); + const [initialTheme, setInitialTheme] = useState(currentTheme); useEffect(() => { if (visible) { setInitialName(name); // Store initial name when the profile opens - setInitialImage(image); // Store initial image when the profile opens + setInitialImage(image); + setInitialTheme(currentTheme)// Store initial image when the profile opens } }, [visible]); // Reset when the dialog is opened @@ -82,7 +85,7 @@ const ProfileScreen: React.FC = ({ visible, name, setName, i const handleSave = () => { // Check if the name or image has changed - const hasChanged = name !== initialName || image !== initialImage; + const hasChanged = name !== initialName || image !== initialImage || currentTheme !== initialTheme; if (hasChanged) { setChanged(true); } diff --git a/app/index.tsx b/app/index.tsx index 684508e..1143306 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -21,6 +21,7 @@ const Index = () => { setUserStatus, setUserDataChanged, setTheme, + currentTheme, isLoading, } = useUser(); @@ -54,6 +55,7 @@ const Index = () => { image={userImage} setImage={setUserImage} setTheme={setTheme} + currentTheme={currentTheme} setChanged={setUserDataChanged} onClose={() => setProfileActive(false)} /> diff --git a/context/UserContext.tsx b/context/UserContext.tsx index aec5940..4e8f71b 100644 --- a/context/UserContext.tsx +++ b/context/UserContext.tsx @@ -49,6 +49,7 @@ export const UserProvider: React.FC = ({ children }) => { const storedUserName = await AsyncStorage.getItem("userName"); const storedUserImage = await AsyncStorage.getItem("userImage"); const storedUserTheme = await AsyncStorage.getItem("theme"); + console.log("Stored theme: ", storedUserTheme); if (storedUserId) { setUserId(storedUserId); setUserName(storedUserName || ""); @@ -81,6 +82,7 @@ export const UserProvider: React.FC = ({ children }) => { await AsyncStorage.setItem("userName", userName); await AsyncStorage.setItem("userImage", userImage); await AsyncStorage.setItem("theme", currentTheme); + console.log("Current theme: ", currentTheme); setUserDataChanged(false); } catch (error) { console.error("Error saving user data:", error);