From 798e54f11c885934827f5a7de6eb61ee4b0e39d4 Mon Sep 17 00:00:00 2001 From: Jakob Stornig Date: Sun, 17 Dec 2023 19:26:15 +0100 Subject: [PATCH] feat: UserSettings --- app/(tabs)/_layout.tsx | 3 +- app/(tabs)/home/_layout.tsx | 22 ++++- app/(tabs)/home/index.tsx | 4 +- app/(tabs)/home/userSettings.tsx | 109 +++++++++++++++++++++++ components/home/userSettings/Setting.tsx | 66 ++++++++++++++ components/index.tsx | 6 +- 6 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 app/(tabs)/home/userSettings.tsx create mode 100644 components/home/userSettings/Setting.tsx diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index 299bba8..bbff5e2 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -53,7 +53,8 @@ export default function Layout() { tabBarLabel: "Home", tabBarIcon: ({size, color}) => ( ), - unmountOnBlur: true + unmountOnBlur: true, + href: "(tabs)/home/" } }/> + + ) } \ No newline at end of file diff --git a/app/(tabs)/home/index.tsx b/app/(tabs)/home/index.tsx index 8b406f8..132c2cf 100644 --- a/app/(tabs)/home/index.tsx +++ b/app/(tabs)/home/index.tsx @@ -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={ <> - + {router.push("/home/userSettings")}}> } diff --git a/app/(tabs)/home/userSettings.tsx b/app/(tabs)/home/userSettings.tsx new file mode 100644 index 0000000..755c305 --- /dev/null +++ b/app/(tabs)/home/userSettings.tsx @@ -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(isSystemTheme!) + const [darkMode, setDarkMode] = useState(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 ( + + + + + My Profile + + + + + + { + deleteExpenses().then(() => { + console.log("Expenses Deleted!"); + })}} + /> + + + + + + + Sign Out + + + + + ) +} + +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: {} +}) \ No newline at end of file diff --git a/components/home/userSettings/Setting.tsx b/components/home/userSettings/Setting.tsx new file mode 100644 index 0000000..19b2123 --- /dev/null +++ b/components/home/userSettings/Setting.tsx @@ -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 ( + + + + {settingsTitle} + + + + + ) +} + +interface ButtonSettingProps extends TouchableOpacityProps { + settingsTitle: string, +} + +export function ButtonSetting(props: ButtonSettingProps){ + const {settingsTitle, ...rest} = props; + const { colors } = useTheme(); + + return ( + + + {settingsTitle} + + + ) +} + + +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 + } +}) \ No newline at end of file diff --git a/components/index.tsx b/components/index.tsx index b95c4c8..7d697da 100644 --- a/components/index.tsx +++ b/components/index.tsx @@ -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 }