From 39533f15be8c9b57b62e8a274aa1cabdda436a5d Mon Sep 17 00:00:00 2001 From: TymianekPL Date: Thu, 31 Oct 2024 11:02:23 +0100 Subject: [PATCH 1/7] change naviation -> router --- app/(tabs)/login.tsx | 5 ++--- app/(tabs)/signup.tsx | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/(tabs)/login.tsx b/app/(tabs)/login.tsx index 0897436..ddfeb97 100644 --- a/app/(tabs)/login.tsx +++ b/app/(tabs)/login.tsx @@ -4,14 +4,13 @@ import React from "react"; import LoginSignupHeader from "@/components/LoginSignupHeader"; import {CustomInput} from "@/components/elements/CustomInput"; import CustomButton from "@/components/elements/CustomButton"; -import {useNavigation} from "expo-router"; +import {router, useNavigation} from "expo-router"; import {LoginSignupFooter} from "@/components/elements/LoginSignupFooter"; export default function Login() { - const navigation = useNavigation(); const handleSignupPress = () => { - navigation.navigate("signup"); + router.push("(tabs)/signup"); } return ( diff --git a/app/(tabs)/signup.tsx b/app/(tabs)/signup.tsx index 939a915..63e558e 100644 --- a/app/(tabs)/signup.tsx +++ b/app/(tabs)/signup.tsx @@ -4,14 +4,14 @@ import React from "react"; import LoginSignupHeader from "@/components/LoginSignupHeader"; import {CustomInput} from "@/components/elements/CustomInput"; import CustomButton from "@/components/elements/CustomButton"; -import {useNavigation} from "expo-router"; +import {router, useNavigation} from "expo-router"; import {LoginSignupFooter} from "@/components/elements/LoginSignupFooter"; export default function Signup() { const navigation = useNavigation(); const handleSignupPress = () => { - navigation.navigate("login"); + router.push("(tabs)/login"); } return ( From f793a1c520a798e642822e6341b61e369ce58968 Mon Sep 17 00:00:00 2001 From: TymianekPL Date: Thu, 31 Oct 2024 11:47:41 +0100 Subject: [PATCH 2/7] add states to login/signup --- app/(tabs)/login.tsx | 13 ++++++++----- app/(tabs)/signup.tsx | 14 ++++++++------ components/elements/CustomInput.tsx | 8 ++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/(tabs)/login.tsx b/app/(tabs)/login.tsx index ddfeb97..82fe9a6 100644 --- a/app/(tabs)/login.tsx +++ b/app/(tabs)/login.tsx @@ -1,24 +1,27 @@ import {View, SafeAreaView, TouchableOpacity, Text} from 'react-native'; -import React from "react"; +import React, { useState } from "react"; import LoginSignupHeader from "@/components/LoginSignupHeader"; import {CustomInput} from "@/components/elements/CustomInput"; import CustomButton from "@/components/elements/CustomButton"; -import {router, useNavigation} from "expo-router"; +import {router} from "expo-router"; import {LoginSignupFooter} from "@/components/elements/LoginSignupFooter"; export default function Login() { + const [login, setLogin] = useState(""); + const [password, setPassword] = useState(""); + const handleSignupPress = () => { - router.push("(tabs)/signup"); + router.push("/(tabs)/signup"); } return ( - - + + Nie masz konta? diff --git a/app/(tabs)/signup.tsx b/app/(tabs)/signup.tsx index 63e558e..48a61db 100644 --- a/app/(tabs)/signup.tsx +++ b/app/(tabs)/signup.tsx @@ -1,6 +1,6 @@ import {View, SafeAreaView, TouchableOpacity, Text} from 'react-native'; -import React from "react"; +import React, { useState } from "react"; import LoginSignupHeader from "@/components/LoginSignupHeader"; import {CustomInput} from "@/components/elements/CustomInput"; import CustomButton from "@/components/elements/CustomButton"; @@ -9,18 +9,20 @@ import {LoginSignupFooter} from "@/components/elements/LoginSignupFooter"; export default function Signup() { - const navigation = useNavigation(); + const [login, setLogin] = useState(""); + const [password, setPassword] = useState(""); + const [confirmPassword, setConfirmPassword] = useState(""); const handleSignupPress = () => { - router.push("(tabs)/login"); + router.push("/(tabs)/login"); } return ( - - - + + + Posiadasz konto? diff --git a/components/elements/CustomInput.tsx b/components/elements/CustomInput.tsx index 9809917..fec5a43 100644 --- a/components/elements/CustomInput.tsx +++ b/components/elements/CustomInput.tsx @@ -1,4 +1,4 @@ -import {StyleSheet, View, TextInput} from "react-native"; +import { StyleSheet, View, TextInput, NativeSyntheticEvent, TextInputChangeEventData } from "react-native"; import React from "react"; type InputType = "text" | "password" | "email"; @@ -6,9 +6,11 @@ type InputType = "text" | "password" | "email"; type CustomInputOptions = { type?: InputType, placeholder?: string, + value?: string, + onChangeText?: ((text: string) => void) | undefined }; -export function CustomInput({type, placeholder, ...rest}: Readonly) { +export function CustomInput({ type, placeholder, value, onChangeText, ...rest }: Readonly) { if (type === undefined) type = "text"; return ( ); } From f52040853a27ce256ebae2f7416ff90996e6ac7e Mon Sep 17 00:00:00 2001 From: TymianekPL Date: Thu, 31 Oct 2024 11:49:24 +0100 Subject: [PATCH 3/7] add settings tab --- app/(tabs)/_layout.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index cc306ce..ac5e445 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -50,6 +50,15 @@ export default function TabLayout() { ), }} /> + ( + + ), + }} + /> ); } From 14037284bd33a3da979cb28ff64246002dfff4c5 Mon Sep 17 00:00:00 2001 From: TymianekPL Date: Thu, 31 Oct 2024 12:27:29 +0100 Subject: [PATCH 4/7] temp-commit --- app/(tabs)/index.tsx | 9 ++++++--- app/(tabs)/login.tsx | 3 +++ functions/shuffleArray.tsx | 14 +++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 3dab8fb..5626fa9 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -6,9 +6,12 @@ import { collection, getDocs, orderBy, query } from "firebase/firestore" import { FIREBASE_DB } from '@/firebase.config'; import { shuffleArray } from '@/functions/shuffleArray'; +interface Tip { + +} const HomeScreen = () => { - const [tips, setTips] = useState([]); + const [tips, setTips] = useState([]); useEffect(() => { const fetchTips = async () => { @@ -30,7 +33,7 @@ const HomeScreen = () => { }, []) function displayTips(hm = 20){ - const rows = shuffleArray(tips).splice(0, hm).reduce((rows, card, index) => { + const rows = shuffleArray(tips).splice(0, hm).reduce((rows: any[][], card: any, index: number) => { if (index % 2 === 0) { rows.push([]); } @@ -38,7 +41,7 @@ const HomeScreen = () => { return rows; }, []).map((row, rowIndex) => ( - {row.map(card => ( + {row.map((card: { id: React.Key | null | undefined; imageName: string; title: string; }) => ( ))} diff --git a/app/(tabs)/login.tsx b/app/(tabs)/login.tsx index 82fe9a6..3234c0c 100644 --- a/app/(tabs)/login.tsx +++ b/app/(tabs)/login.tsx @@ -14,6 +14,9 @@ export default function Login() { const handleSignupPress = () => { router.push("/(tabs)/signup"); + } + const handleFormSubmit = () => { + } return ( diff --git a/functions/shuffleArray.tsx b/functions/shuffleArray.tsx index 7e1b75c..93dc6de 100644 --- a/functions/shuffleArray.tsx +++ b/functions/shuffleArray.tsx @@ -1,7 +1,7 @@ -export const shuffleArray = (array) => { - for (let i = array.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); - [array[i], array[j]] = [array[j], array[i]]; - } - return array; - }; \ No newline at end of file +export function shuffleArray(array: T[]): T[] { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array; +}; \ No newline at end of file From e3066a3e2d1704d461224a657976abd274a50236 Mon Sep 17 00:00:00 2001 From: Tymianek Date: Wed, 6 Nov 2024 19:25:46 +0100 Subject: [PATCH 5/7] Update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6623142..17d004b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ web-build/ # The following patterns were generated by expo-cli expo-env.d.ts -# @end expo-cli \ No newline at end of file +# @end expo-cli +.idea/ \ No newline at end of file From dfe94f1b76659c5424bd1226e95596b818383e99 Mon Sep 17 00:00:00 2001 From: Tymianek Date: Sat, 9 Nov 2024 21:24:13 +0100 Subject: [PATCH 6/7] add welcome --- app/(tabs)/welcome.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/(tabs)/welcome.tsx diff --git a/app/(tabs)/welcome.tsx b/app/(tabs)/welcome.tsx new file mode 100644 index 0000000..292f8ac --- /dev/null +++ b/app/(tabs)/welcome.tsx @@ -0,0 +1,18 @@ +import {ThemedText} from "@/components/ThemedText"; +import {SafeAreaView} from "react-native-safe-area-context"; +import React from "react"; +import {ImageBackground} from "react-native"; + +export default function Welcome(props: {}) { + return + + Save + The + Planet + ; +} \ No newline at end of file From 0f2afa1c7e086f4f49dca717e0753f8f52c80f5e Mon Sep 17 00:00:00 2001 From: Tymianek Date: Sat, 9 Nov 2024 21:58:05 +0100 Subject: [PATCH 7/7] add shop --- app/(tabs)/shop.tsx | 64 ++++++++++++++++++++--- app/_layout.tsx | 1 + app/shop/[id]/index.tsx | 84 ++++++++++++++++++++++++++++++ app/shop/index.tsx | 64 +++++++++++++++++++++++ components/HomePage/ScrollCard.tsx | 10 ++-- typing.d.ts | 9 +++- 6 files changed, 219 insertions(+), 13 deletions(-) create mode 100644 app/shop/[id]/index.tsx create mode 100644 app/shop/index.tsx diff --git a/app/(tabs)/shop.tsx b/app/(tabs)/shop.tsx index e751f92..eb7fd9b 100644 --- a/app/(tabs)/shop.tsx +++ b/app/(tabs)/shop.tsx @@ -1,10 +1,58 @@ -import { SafeAreaView, Text, View } from "react-native"; - -function Shop() { - return - - Shop - - +import {ImageBackground, ScrollView, Text, TextInput, View} from "react-native"; +import SectionText from "@/components/HomePage/SectionText"; +import ScrollCard from "@/components/HomePage/ScrollCard"; +import React, {useEffect, useState} from "react"; +import {collection, getDocs, query} from "firebase/firestore"; +import {FIREBASE_DB} from "@/firebase.config"; +import {shuffleArray} from "@/functions/shuffleArray"; +import {Ionicons} from "@expo/vector-icons"; + +const Shop = () => { + const [shopItems, setShopItems] = useState([]); + useEffect(() => { + + const fetchItems = async () => { + const shopCollectionReference = collection(FIREBASE_DB, "shop"); + const shopQuery = query(shopCollectionReference); + const querySnapshot = await getDocs(shopQuery); + + const fetchedTips: ShopItem[] = querySnapshot.docs.map((doc) => ({ + id: doc.id, + ...doc.data() as ShopItemData + })); + + setShopItems(fetchedTips); + } + fetchItems(); + }, []); + return + + + + + Treebie + + + Ucz się, działaj, zgarniaj + + + + + + + + {shopItems.slice(0, 5).map((item) => { + return + })} + + + ; } + export default Shop; \ No newline at end of file diff --git a/app/_layout.tsx b/app/_layout.tsx index 8672935..8ad55c9 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -42,6 +42,7 @@ export default function RootLayout() { + diff --git a/app/shop/[id]/index.tsx b/app/shop/[id]/index.tsx new file mode 100644 index 0000000..a966f44 --- /dev/null +++ b/app/shop/[id]/index.tsx @@ -0,0 +1,84 @@ +/* eslint-disable @typescript-eslint/no-require-imports */ +import { Image, ImageBackground, ScrollView, Text, TouchableOpacity, View } from "react-native"; +import CustomButton from "@/components/elements/CustomButton"; +import { Ionicons } from "@expo/vector-icons"; +import { Href, router, useLocalSearchParams } from "expo-router"; +import { useEffect, useState } from "react"; +import { addDoc, collection, deleteDoc, doc, getDoc, getDocs, query, where } from "firebase/firestore"; +import { FIREBASE_DB } from "@/firebase.config"; +import TipListElement from "@/components/TipsPage/TipListElement"; +import React from "react"; +import { ThemedText } from "@/components/ThemedText"; +import { ThemedView } from "@/components/ThemedView"; + +type TipFields = { + title: string; + description: string; + list: string[]; +}; + +const Index = () => { + const local = useLocalSearchParams(); + let redirect = "/shop" + if (local.redirect) { + redirect = local.redirect === "liked" ? "/shop?allType=liked" : "/shop?allType=all"; + } + const [liked, setLiked] = useState(false); + const [item, setItem] = useState(undefined); + const USERID = "1"; + + useEffect(() => { + const getData = async (id: string) => { + try { + const docRef = doc(FIREBASE_DB, "shop", id); + const res = await getDoc(docRef); + if (res.exists()) { + setItem(res.data() as ShopItem); + } else { + console.warn("No such document!"); + } + } catch (error) { + console.error("Error fetching document: ", error); + router.replace("/(tabs)/"); + } + }; + + + if (local.id) { + getData(local.id.toString()); + } + }, [local.id]); + + return ( + + + + + + router.replace(redirect as Href)} + > + + + + + + + + + + + {item?.name} + + + + + ); +}; + +export default Index; diff --git a/app/shop/index.tsx b/app/shop/index.tsx new file mode 100644 index 0000000..d6f6831 --- /dev/null +++ b/app/shop/index.tsx @@ -0,0 +1,64 @@ +import {SafeAreaView, ScrollView, Text, TouchableOpacity, View} from "react-native"; +import {router, useLocalSearchParams} from "expo-router"; +import {collection, getDocs, query} from "firebase/firestore"; +import {FIREBASE_DB} from "@/firebase.config"; +import {shuffleArray} from "@/functions/shuffleArray"; +import React, {useEffect, useState} from "react"; +import {Ionicons} from "@expo/vector-icons"; +import {ThemedText} from "@/components/ThemedText"; +import ScrollCard from "@/components/HomePage/ScrollCard"; + +function Index() { + const [shopItems, setShopItems] = useState([]); + const [displayShopItems, setDisplayShopItems] = useState([]); + useEffect(() => { + + const fetchItems = async () => { + const shopCollectionReference = collection(FIREBASE_DB, "shop"); + const shopQuery = query(shopCollectionReference); + const querySnapshot = await getDocs(shopQuery); + + const fetchedTips: ShopItem[] = querySnapshot.docs.map((doc) => ({ + id: doc.id, + ...doc.data() as ShopItemData + })); + + setShopItems(fetchedTips); + setDisplayShopItems(shuffleArray([...fetchedTips]).slice(0, 20)); + } + fetchItems(); + }, []); + + function displayItems(): JSX.Element[] { + return displayShopItems + .reduce((rows, card, index) => { + if (index % 2 === 0) rows.push([]); + rows[rows.length - 1].push(card); + return rows; + }, []) + .map((row, rowIndex) => ( + + {row.map((card) => ( + + ))} + + )); + } + + return + + router.replace("/shop")} + > + + + + + {displayItems()} + + +} + +export default Index; \ No newline at end of file diff --git a/components/HomePage/ScrollCard.tsx b/components/HomePage/ScrollCard.tsx index 50f17fd..94f4999 100644 --- a/components/HomePage/ScrollCard.tsx +++ b/components/HomePage/ScrollCard.tsx @@ -8,14 +8,16 @@ interface ScrollCardProps { title: string; imageName: string; containerStyle?: string; - redirect?: string + redirect?: string; + routeBase?: string; } -const ScrollCard = ({ id, title, imageName, containerStyle, redirect }: ScrollCardProps) => { +const ScrollCard = ({ id, title, imageName, containerStyle, redirect, routeBase }: ScrollCardProps) => { + routeBase ??= "tip"; const handlePress = () => { const route: Href = redirect - ? (`/tip/${id}?redirect=${redirect}` as Href) - : (`/tip/${id}` as Href); + ? (`/${routeBase}/${id}?redirect=${redirect}` as Href) + : (`/${routeBase}/${id}` as Href); router.push(route); } return ( diff --git a/typing.d.ts b/typing.d.ts index 2b52c41..2a03a3f 100644 --- a/typing.d.ts +++ b/typing.d.ts @@ -21,7 +21,14 @@ interface TipFields extends TipData { interface ChallengeFields extends ChallengeData { id: string; } - +interface ShopItemData { + name: string; + price: number; + image: string; +} +interface ShopItem extends ShopItemData { + id: string; +} interface MessageType { message: string;