Fixed themes not saving. Removed unused import
This commit is contained in:
parent
f03a268a39
commit
144b0daaa5
@ -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<ProfileScreenProps> = ({ visible, name, setName, image, setImage, setChanged, setTheme, onClose }) => {
|
||||
const ProfileScreen: React.FC<ProfileScreenProps> = ({ 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<ProfileScreenProps> = ({ 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<ProfileScreenProps> = ({ 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);
|
||||
}
|
||||
|
@ -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)}
|
||||
/>
|
||||
|
@ -49,6 +49,7 @@ export const UserProvider: React.FC<UserProviderProps> = ({ 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<UserProviderProps> = ({ 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);
|
||||
|
Loading…
Reference in New Issue
Block a user