From 899b50ded400ad197b13a73332946650e1f1692e Mon Sep 17 00:00:00 2001 From: Jakob Stornig Date: Thu, 25 Jan 2024 20:35:09 +0100 Subject: [PATCH] last changes --- app/(tabs)/(budget)/addCategory.tsx | 2 +- app/(tabs)/(budget)/editCategory.tsx | 3 +- app/(tabs)/(budget)/index.tsx | 1 - app/(tabs)/(stats)/index.tsx | 39 ++++++++++++------ app/(tabs)/stats/index.tsx | 52 ------------------------ app/expense/new.tsx | 2 - components/budget/typeSelectorSwitch.tsx | 2 +- components/stats/BudgetOverview.tsx | 4 +- components/stats/BudgetTotal.tsx | 6 +-- components/stats/SavingsOverview.tsx | 6 +-- hooks/useCategoryData.ts | 2 +- package-lock.json | 8 ++-- package.json | 2 +- services/DebugMenu.tsx | 3 +- services/database.ts | 6 +-- types/dbItems.ts | 4 ++ 16 files changed, 53 insertions(+), 89 deletions(-) delete mode 100644 app/(tabs)/stats/index.tsx diff --git a/app/(tabs)/(budget)/addCategory.tsx b/app/(tabs)/(budget)/addCategory.tsx index eced44a..695a708 100644 --- a/app/(tabs)/(budget)/addCategory.tsx +++ b/app/(tabs)/(budget)/addCategory.tsx @@ -5,7 +5,7 @@ import { SafeAreaView } from 'react-native-safe-area-context'; import { AutoDecimalInput, CustomColorPicker, NavigationButton, TypeSelectorSwitch } from "../../../components"; import { addCategory } from "../../../services/database"; import { useTheme } from "../../contexts/ThemeContext"; -import { CategoryType } from "../../../services/database"; +import { CategoryType } from "../../../types/dbItems"; export default function Page() { const {colors} = useTheme(); diff --git a/app/(tabs)/(budget)/editCategory.tsx b/app/(tabs)/(budget)/editCategory.tsx index e0b2706..19dc3e0 100644 --- a/app/(tabs)/(budget)/editCategory.tsx +++ b/app/(tabs)/(budget)/editCategory.tsx @@ -6,6 +6,7 @@ import useFetch from "../../../hooks/useFetch"; import { deleteCategory, deleteExpense, updateCategory } from "../../../services/database"; import { useTheme } from "../../contexts/ThemeContext"; import { SafeAreaView } from 'react-native-safe-area-context'; +import { CategoryType } from "../../../types/dbItems"; const addCategory = () => { const {colors} = useTheme(); @@ -13,7 +14,7 @@ const addCategory = () => { const [categoryName, setCategoryName] = useState(category_name.toString()); const [categoryColor, setCategoryColor] = useState(category_color.toString()); - const [selectedType, setSelectedType] = useState(category_type.toString()); + const [selectedType, setSelectedType] = useState(category_type === "expense" ? CategoryType.EXPENSE : CategoryType.SAVING); const [amount, setAmount] = useState(Number.parseFloat(category_amount.toString())); const {data} = useFetch({sql: "SELECT * FROM expense WHERE category_guid = ?", args: [category_guid.toString()]}); diff --git a/app/(tabs)/(budget)/index.tsx b/app/(tabs)/(budget)/index.tsx index 9b38322..fce6f05 100644 --- a/app/(tabs)/(budget)/index.tsx +++ b/app/(tabs)/(budget)/index.tsx @@ -67,7 +67,6 @@ export default function Page() { }) }, [data, searchString, selectedPage]); - console.log(selectedPage) return ( diff --git a/app/(tabs)/(stats)/index.tsx b/app/(tabs)/(stats)/index.tsx index 6a6c0c9..5113d08 100644 --- a/app/(tabs)/(stats)/index.tsx +++ b/app/(tabs)/(stats)/index.tsx @@ -1,24 +1,39 @@ import React from 'react'; -import { SafeAreaView } from 'react-native'; + import { Graph } from '../../../components'; import BudgetOverview from '../../../components/stats/BudgetOverview'; -import BudgetRemaining from '../../../components/stats/BudgetRemaining'; +import BudgetRemaining from '../../../components/stats/SavingsOverview'; import SavingsOverview from '../../../components/stats/SavingsOverview'; import Widget from '../../../components/stats/Widget'; +import FinancialAdvice from '../../../components/stats/FinancialAdvice'; +import BudgetTotal from '../../../components/stats/BudgetTotal'; +import { ScrollView } from 'react-native-gesture-handler'; +import { SafeAreaView } from 'react-native-safe-area-context'; +import DebugMenu from '../../../services/DebugMenu'; export default function Page() { return ( - - - - - - - - - - + + + {/* */} + + + + + + + + + + + + {/* + + */} + + + ); } diff --git a/app/(tabs)/stats/index.tsx b/app/(tabs)/stats/index.tsx deleted file mode 100644 index 97a3b74..0000000 --- a/app/(tabs)/stats/index.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import React from 'react'; -import { StyleSheet, View, ScrollView } from 'react-native'; -import BudgetTotal from '../../../components/stats/BudgetTotal'; -import { useTheme } from '../../contexts/ThemeContext'; -import Widget from '../../../components/stats/Widget'; -import DebugMenu from '../../../services/DebugMenu'; -import SavingsOverview from '../../../components/stats/SavingsOverview'; -import FinancialAdvice from '../../../components/stats/FinancialAdvice'; -import BudgetOverview from '../../../components/stats/BudgetOverview'; - -export default function Page() { - const { colors } = useTheme(); - - // Mock data #TODO Database einbinden - // what to do when amount too small? - - const spent = 120.75; - const budget = 696.96; - - - - const styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: colors.backgroundColor, - marginTop: 50, - alignItems: 'center', - }, - }); - - return ( - - - - - - - - - - - - - - - - - - - - ); -} diff --git a/app/expense/new.tsx b/app/expense/new.tsx index d0456e7..bfbd7bd 100644 --- a/app/expense/new.tsx +++ b/app/expense/new.tsx @@ -54,9 +54,7 @@ export default function AddItem() { useEffect(()=>{ if(searchParams.category !== undefined){ - console.log(searchParams.category) executeQuery({sql: "SELECT * FROM category WHERE guid = ?", args: [searchParams.category]}).then((result) =>{ - console.log("then") if("rows" in result[0]){ const category = result[0]["rows"][0]; setSelectedCategory({name: category["name"], color: category["color"], guid: category["guid"]}) diff --git a/components/budget/typeSelectorSwitch.tsx b/components/budget/typeSelectorSwitch.tsx index a4edf58..f3e8f25 100644 --- a/components/budget/typeSelectorSwitch.tsx +++ b/components/budget/typeSelectorSwitch.tsx @@ -1,7 +1,7 @@ import { StyleSheet, Text, TouchableOpacity, View } from "react-native"; import { useTheme } from "../../app/contexts/ThemeContext"; -import { CategoryType } from "../../services/database"; +import { CategoryType } from "../../types/dbItems"; export type TypeSelectorSwitchProperties = { handleButtonPress: (type: CategoryType) => void, diff --git a/components/stats/BudgetOverview.tsx b/components/stats/BudgetOverview.tsx index de40065..4148e6a 100644 --- a/components/stats/BudgetOverview.tsx +++ b/components/stats/BudgetOverview.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { Text, StyleSheet } from 'react-native'; import { useTheme } from '../../app/contexts/ThemeContext'; import useFetch from '../../hooks/useFetch'; -import { CategoryType } from '../../services/database'; +import { CategoryType } from '../../types/dbItems'; import {useCategoryData} from '../../hooks/useCategoryData'; const styles = StyleSheet.create({ @@ -47,7 +47,7 @@ const BudgetTotal: React.FC = ({ goodColor = 'green', badColor return ( <> - You have spent {expenseTotal.toFixed(2)}€ out of your Budget of {total.toFixed(2)}€ . + You have spent {expenseTotal.toFixed(2)}€ out of your Budget of {total.toFixed(2)}€ ); diff --git a/components/stats/BudgetTotal.tsx b/components/stats/BudgetTotal.tsx index 6acfa6b..f4b0aa8 100644 --- a/components/stats/BudgetTotal.tsx +++ b/components/stats/BudgetTotal.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { Text, StyleSheet } from 'react-native'; import { useTheme } from '../../app/contexts/ThemeContext'; import useFetch from '../../hooks/useFetch'; -import { CategoryType } from '../../services/database'; +import { CategoryType } from '../../types/dbItems'; import {useCategoryData} from '../../hooks/useCategoryData'; const styles = StyleSheet.create({ @@ -48,11 +48,11 @@ const BudgetTotal: React.FC = ({ goodColor = 'green', badColor {remaining >= 0 ? ( <> - Your remaining overall Budget is {remaining.toFixed(2)}€. + Your remaining overall Budget is {remaining.toFixed(2)}€ ) : ( <> - Your Budget is overspent by -{Math.abs(remaining).toFixed(2)}€. + Your Budget is overspent by -{Math.abs(remaining).toFixed(2)}€ )} diff --git a/components/stats/SavingsOverview.tsx b/components/stats/SavingsOverview.tsx index 064cf5e..ea906a1 100644 --- a/components/stats/SavingsOverview.tsx +++ b/components/stats/SavingsOverview.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { Text, StyleSheet } from 'react-native'; import { useTheme } from '../../app/contexts/ThemeContext'; import useFetch from '../../hooks/useFetch'; -import { CategoryType } from '../../services/database'; +import { CategoryType } from '../../types/dbItems'; import {useCategoryData} from '../../hooks/useCategoryData'; const styles = StyleSheet.create({ @@ -48,11 +48,11 @@ const BudgetTotal: React.FC = ({ goodColor = 'green', badColor {remaining >= 0 ? ( <> - You have saved {expenseTotal.toFixed(2)}€ out of your Goal of {total.toFixed(2)}€ . + You have saved {expenseTotal.toFixed(2)}€ out of your Goal of {total.toFixed(2)}€ ) : ( <> - You have surpassed your Savings Goal of {total.toFixed(2)}€ by {Math.abs(remaining).toFixed(2)}€. + You have surpassed your Savings Goal of {total.toFixed(2)}€ by {Math.abs(remaining).toFixed(2)}€ )} diff --git a/hooks/useCategoryData.ts b/hooks/useCategoryData.ts index 3939a53..72cbe8b 100644 --- a/hooks/useCategoryData.ts +++ b/hooks/useCategoryData.ts @@ -1,6 +1,6 @@ import { useState, useEffect } from 'react'; import useFetch from './useFetch'; -import { CategoryType } from '../services/database'; +import { CategoryType } from '../types/dbItems'; export const useCategoryData = (CategoryType: string) => { const [data, setData] = useState({ total: 0, expenseTotal: 0 }); diff --git a/package-lock.json b/package-lock.json index 3c97807..8eacd8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "react-native-calendars": "^1.1303.0", "react-native-chart-kit": "^6.12.0", "react-native-gesture-handler": "~2.12.0", - "react-native-reanimated": "^3.3.0", + "react-native-reanimated": "~3.3.0", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", "react-native-uuid": "^2.0.1", @@ -16163,9 +16163,9 @@ } }, "node_modules/react-native-reanimated": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-3.6.1.tgz", - "integrity": "sha512-F4vG9Yf9PKmE3GaWtVGUpzj3SM6YY2cx1yRHCwiMd1uY7W0gU017LfcVUorboJnj0y5QZqEriEK1Usq2Y8YZqg==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-3.3.0.tgz", + "integrity": "sha512-LzfpPZ1qXBGy5BcUHqw3pBC0qSd22qXS3t8hWSbozXNrBkzMhhOrcILE/nEg/PHpNNp1xvGOW8NwpAMF006roQ==", "dependencies": { "@babel/plugin-transform-object-assign": "^7.16.7", "@babel/preset-typescript": "^7.16.7", diff --git a/package.json b/package.json index 6203ad9..f8cf56a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "react-native-calendars": "^1.1303.0", "react-native-chart-kit": "^6.12.0", "react-native-gesture-handler": "~2.12.0", - "react-native-reanimated": "^3.3.0", + "react-native-reanimated": "~3.3.0", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", "react-native-uuid": "^2.0.1", diff --git a/services/DebugMenu.tsx b/services/DebugMenu.tsx index 29ce4e8..ff728ff 100644 --- a/services/DebugMenu.tsx +++ b/services/DebugMenu.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { View, Button, Alert } from 'react-native'; import { addCategory, addExpense, deleteExpenses, deleteCategories, DEV_populateDatabase, deleteDatabase } from './database'; import uuid from 'react-native-uuid'; +import { CategoryType } from '../types/dbItems'; const randomColors = ["red", "blue", "green", "purple", "yellow"]; @@ -46,7 +47,7 @@ const DebugMenu = () => { const allocated_amount = getRandomNumber(); const type = "expense"; - addCategory(name, color, type, allocated_amount) + addCategory(name, color, CategoryType.EXPENSE, allocated_amount) .then(() => Alert.alert("Category Added", `Name: ${name}, Color: ${color}`)) .catch((error: any) => console.error("Error adding category: ", error)); }; diff --git a/services/database.ts b/services/database.ts index 029131d..e4c25bf 100644 --- a/services/database.ts +++ b/services/database.ts @@ -4,13 +4,11 @@ import uuid from "react-native-uuid"; import { Query } from "expo-sqlite"; import { SimpleDate } from "../util/SimpleDate"; +import { CategoryType } from "../types/dbItems"; let db: SQLite.SQLiteDatabase; -export enum CategoryType { - SAVING = "saving", - EXPENSE = "expense", -} + export const initDatabase = async () => { db = SQLite.openDatabase("interactive_systeme.db"); diff --git a/types/dbItems.ts b/types/dbItems.ts index c2df2dc..2d9906d 100644 --- a/types/dbItems.ts +++ b/types/dbItems.ts @@ -1,3 +1,7 @@ +export enum CategoryType { + SAVING = "saving", + EXPENSE = "expense", +} export interface Category { guid? : string; name? : string;