feat: UserSettings
This commit is contained in:
parent
b5613c6e18
commit
798e54f11c
6 changed files with 206 additions and 4 deletions
|
|
@ -53,7 +53,8 @@ export default function Layout() {
|
|||
tabBarLabel: "Home",
|
||||
tabBarIcon: ({size, color}) => (
|
||||
<FontAwesome name="home" size={size} color={color}/>),
|
||||
unmountOnBlur: true
|
||||
unmountOnBlur: true,
|
||||
href: "(tabs)/home/"
|
||||
}
|
||||
}/>
|
||||
<Tabs.Screen name="stats/index" options={
|
||||
|
|
|
|||
|
|
@ -2,15 +2,35 @@ import { Stack } from "expo-router";
|
|||
|
||||
import { View, Text } from 'react-native'
|
||||
import React from 'react'
|
||||
import { useThemeColor } from "../../../hooks/useThemeColor";
|
||||
import { useTheme } from "../../contexts/ThemeContext";
|
||||
|
||||
|
||||
export default function _Layout() {
|
||||
const { colors } = useTheme();
|
||||
return (
|
||||
<Stack>
|
||||
<Stack
|
||||
initialRouteName="index"
|
||||
screenOptions={{
|
||||
contentStyle: {
|
||||
backgroundColor:colors.backgroundColor,
|
||||
},
|
||||
headerStyle: {
|
||||
backgroundColor: colors.backgroundColor
|
||||
},
|
||||
headerTintColor: colors.primaryText
|
||||
|
||||
}}>
|
||||
<Stack.Screen name="index" options={{
|
||||
title: "test",
|
||||
headerShown: false,
|
||||
}}/>
|
||||
<Stack.Screen name="addItem"/>
|
||||
<Stack.Screen name="userSettings" options={{
|
||||
animation: "slide_from_left",
|
||||
title: "User Settings",
|
||||
headerShown: false,
|
||||
}}/>
|
||||
</Stack>
|
||||
)
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import useFetch from '../../../hooks/useFetch';
|
|||
import { useThemeColor } from "../../../hooks/useThemeColor";
|
||||
import { addExpense } from "../../../services/database";
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
import { useRouter } from "expo-router";
|
||||
|
||||
export default function Page() {
|
||||
|
||||
|
|
@ -31,6 +32,7 @@ export default function Page() {
|
|||
}
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const {onLogout} = useAuth();
|
||||
const [plusShow, setPlusShow] = useState(true);
|
||||
const prevOffset = useRef(0);
|
||||
|
|
@ -73,7 +75,7 @@ export default function Page() {
|
|||
data={data}
|
||||
ListHeaderComponent={
|
||||
<>
|
||||
<Welcome name="My Dude" image={profile} onPress={onLogout!}></Welcome>
|
||||
<Welcome name="My Dude" image={profile} onPress={() => {router.push("/home/userSettings")}}></Welcome>
|
||||
<SearchBar placeholder='Type to Search...'></SearchBar>
|
||||
</>
|
||||
}
|
||||
|
|
|
|||
109
app/(tabs)/home/userSettings.tsx
Normal file
109
app/(tabs)/home/userSettings.tsx
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
import { View, Text, StyleSheet, Image, Appearance } from 'react-native'
|
||||
import React, { useState } from 'react'
|
||||
import { useThemeColor } from '../../../hooks/useThemeColor'
|
||||
import { SIZES } from '../../../constants/theme'
|
||||
import { SafeAreaView } from 'react-native-safe-area-context'
|
||||
import { ButtonSetting, ToggleSetting } from '../../../components'
|
||||
import { useTheme } from '../../contexts/ThemeContext'
|
||||
import { deleteExpenses } from '../../../services/database'
|
||||
import { useAuth } from '../../contexts/AuthContext'
|
||||
import { TouchableOpacity } from 'react-native-gesture-handler'
|
||||
|
||||
const generateStyles = (): void => {
|
||||
styles.text = {
|
||||
color: useThemeColor('primaryText')
|
||||
}
|
||||
}
|
||||
|
||||
export default function userSettings() {
|
||||
const {onLogout} = useAuth();
|
||||
const {theme, colors, isSystemTheme, applyTheme, applySystemTheme} = useTheme();
|
||||
|
||||
const backgroundColor = useThemeColor("backgroundColor");
|
||||
styles.text = {...styles.text, color: useThemeColor("primaryText")}
|
||||
|
||||
const [systemTheme, setSystemTheme] = useState<boolean>(isSystemTheme!)
|
||||
const [darkMode, setDarkMode] = useState<boolean>(theme === "dark" ? true : false)
|
||||
|
||||
const handleSystemTheme = () => {
|
||||
if(systemTheme){
|
||||
applyTheme!(theme)
|
||||
}else{
|
||||
applySystemTheme!()
|
||||
}
|
||||
|
||||
setSystemTheme(prev => !prev)
|
||||
|
||||
}
|
||||
|
||||
const handleDarkMode = () => {
|
||||
const newTheme = darkMode ? "light" : "dark"
|
||||
|
||||
setDarkMode(prev => !prev)
|
||||
applyTheme!(newTheme);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.container, {backgroundColor: colors.backgroundColor}]}>
|
||||
<View>
|
||||
<View style={styles.header}>
|
||||
<Image style={{height: 70, width: 70, borderRadius: 200}}source={require("../../../assets/images/profile.jpg")} height={60} width={20} resizeMode='cover'/>
|
||||
<Text style={{fontSize: SIZES.xxLarge, color: colors.primaryText}}>My Profile</Text>
|
||||
<View></View>
|
||||
</View>
|
||||
<View style={styles.settingsContainer}>
|
||||
<ToggleSetting settingsTitle='Use System Theme' value={systemTheme} onChange={handleSystemTheme}/>
|
||||
<ToggleSetting settingsTitle='Dark Mode' disabled={systemTheme} onChange={handleDarkMode} value={darkMode}/>
|
||||
<ButtonSetting settingsTitle='Reset Expenses' onPress={() => {
|
||||
deleteExpenses().then(() => {
|
||||
console.log("Expenses Deleted!");
|
||||
})}}
|
||||
/>
|
||||
</View>
|
||||
|
||||
</View>
|
||||
<View style={styles.bottomNavigation}>
|
||||
<TouchableOpacity onPress={onLogout}>
|
||||
<View style={[styles.button, {backgroundColor: colors.accentColor}]}>
|
||||
<Text style={{fontSize: SIZES.large, color: colors.primaryText}}>Sign Out</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: "space-between"
|
||||
},
|
||||
|
||||
header:{
|
||||
flexDirection: 'row',
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
margin: 10,
|
||||
},
|
||||
settingsContainer: {
|
||||
marginHorizontal: 10
|
||||
},
|
||||
|
||||
upperPart:{
|
||||
flex: 1
|
||||
},
|
||||
|
||||
bottomNavigation:{
|
||||
marginBottom: 20,
|
||||
alignItems:"center"
|
||||
|
||||
},
|
||||
button:{
|
||||
borderRadius: 80,
|
||||
minHeight: 60,
|
||||
justifyContent: "center",
|
||||
paddingHorizontal: 20
|
||||
},
|
||||
text: {}
|
||||
})
|
||||
66
components/home/userSettings/Setting.tsx
Normal file
66
components/home/userSettings/Setting.tsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import { View, Text, StyleSheet, Switch, SwitchProps, useColorScheme, TouchableOpacityProps, TouchableOpacity, ViewProps } from 'react-native'
|
||||
import React from 'react'
|
||||
import { SIZES } from '../../../constants/theme'
|
||||
import { useThemeColor } from '../../../hooks/useThemeColor';
|
||||
import { CustomCard } from "../../"
|
||||
import { useTheme } from '../../../app/contexts/ThemeContext';
|
||||
|
||||
interface ToggleSettingProps extends SwitchProps {
|
||||
settingsTitle: string;
|
||||
}
|
||||
|
||||
export function ToggleSetting(props: ToggleSettingProps) {
|
||||
const {settingsTitle, ...rest} = props;
|
||||
const { colors } = useTheme()
|
||||
|
||||
return (
|
||||
|
||||
<View style={[{ backgroundColor: colors.containerColor}, styles.settingsTile]}>
|
||||
<Text style={[styles.settingTitle, {color: rest.disabled ? colors.secondaryText: colors.primaryText }]}>
|
||||
{settingsTitle}
|
||||
</Text>
|
||||
<Switch
|
||||
{...rest}
|
||||
thumbColor={rest.thumbColor === undefined ? colors.accentColor: rest.thumbColor}
|
||||
trackColor={rest.trackColor === undefined ? {true: "#E88C3F", false: colors.elementDefaultColor}: rest.trackColor}
|
||||
|
||||
></Switch>
|
||||
</View>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
interface ButtonSettingProps extends TouchableOpacityProps {
|
||||
settingsTitle: string,
|
||||
}
|
||||
|
||||
export function ButtonSetting(props: ButtonSettingProps){
|
||||
const {settingsTitle, ...rest} = props;
|
||||
const { colors } = useTheme();
|
||||
|
||||
return (
|
||||
<TouchableOpacity {...rest}>
|
||||
<View style={[styles.settingsTile, {backgroundColor: colors.containerColor}]}>
|
||||
<Text style={[styles.settingTitle, {color: colors.primaryText}]}>{settingsTitle}</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
settingTitle: {
|
||||
fontSize: SIZES.large
|
||||
},
|
||||
settingsTile: {
|
||||
width: "100%",
|
||||
minHeight: 60,
|
||||
paddingVertical: 5,
|
||||
paddingHorizontal: 20,
|
||||
borderRadius: 80,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
marginBottom: 10
|
||||
}
|
||||
})
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
//home
|
||||
import ExpenseItem from "./home/expenseItem/expenseItem"
|
||||
import Welcome from "./home/Welcome/Welcome"
|
||||
import { ToggleSetting, ButtonSetting } from "./home/userSettings/Setting"
|
||||
|
||||
//common
|
||||
import LoadingSymbol from "./common/loadingSymbol/loadingSymbol"
|
||||
import Plus from "./common/plus/plus"
|
||||
import SearchBar from "./common/searchBar/SearchBar"
|
||||
import CustomCard from "./common/customCard/CustomCard"
|
||||
|
||||
|
||||
//login
|
||||
|
|
@ -14,6 +16,8 @@ import Input from "./login/input"
|
|||
export {
|
||||
ExpenseItem, Input,
|
||||
LoadingSymbol, Plus,
|
||||
SearchBar, Welcome
|
||||
SearchBar, Welcome,
|
||||
ToggleSetting, CustomCard,
|
||||
ButtonSetting
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue