From 7028adab68d6bc82ed58b9678735f83d9c2bf2bf Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:35:19 -0700 Subject: [PATCH 01/10] fixinggggg --- .../Cases/QRCodeScanner/AddCase/index.tsx | 78 +++++++++++++++++++ .../Cases/QRCodeScanner/AddCase/styles.ts | 40 ++++++++++ src/supabase/queries/case.ts | 28 +++++++ 3 files changed, 146 insertions(+) create mode 100644 src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx create mode 100644 src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts create mode 100644 src/supabase/queries/case.ts diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx new file mode 100644 index 00000000..fd68110f --- /dev/null +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx @@ -0,0 +1,78 @@ +import { useLocalSearchParams, useRouter } from 'expo-router'; +import React, { useEffect, useState } from 'react'; +import { Image, Text, TouchableOpacity, View } from 'react-native'; +import { getCase, uploadCase } from '../../../../../supabase/queries/case'; +import styles from './styles'; + +enum caseStatus { + NotStarted, + InProgress, + Settled, + Cancelled, +} + +export interface Case { + id: number; + approved: boolean; + title: string; + summary: string; + image: string; + caseStatus: caseStatus; +} + +function AddCase() { + const local = useLocalSearchParams(); + const { caseId } = local; + const router = useRouter(); + + const [dataImage, setDataImage] = useState(''); + const [dataTitle, setDataTitle] = useState(''); + const [dataSummary, setDataSummary] = useState(''); + + const parseData = (data: any) => { + const myData = { + ...(data[0] as Partial), + }; + return myData as Case; + }; + + useEffect(() => { + const getData = async () => { + const { data, error } = await getCase(caseId); + if (error) { + console.log('error'); + } + + const myData = parseData(data); + const { image, title, summary } = myData; + + setDataImage(image); + setDataTitle(title); + setDataSummary(summary); + console.log(data); + }; + getData(); + }, []); + + const addToCases = async () => { + const { error } = uploadCase(caseId); + if (error) { + console.log(error); + } + }; + return ( + + {dataTitle} + + {dataSummary} + + ADD TO CASES + + router.back()} style={styles.button}> + CANCEL + + + ); +} + +export default AddCase; diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts new file mode 100644 index 00000000..516fe7b5 --- /dev/null +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts @@ -0,0 +1,40 @@ +import { StyleSheet } from 'react-native'; + +export default StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + margin: 40, + }, + + title: { + fontSize: 30, + fontWeight: 'bold', + }, + + image: { + height: 200, + width: 334, + marginTop: 10, + marginBottom: 10, + }, + + blurb: { + fontSize: 17, + marginTop: 10, + marginBottom: 50, + }, + + button: { + border: 'solid', + borderWidth: 2, + marginTop: 10, + marginBottom: 10, + alignItems: 'center', + justifyContent: 'center', + backgroundColor: '#339FFF', + height: 75, + width: 334, + borderRadius: 20, + }, +}); diff --git a/src/supabase/queries/case.ts b/src/supabase/queries/case.ts new file mode 100644 index 00000000..280c422a --- /dev/null +++ b/src/supabase/queries/case.ts @@ -0,0 +1,28 @@ +import supabase from '../createClient'; + +export const getCase = async (caseId: any) => { + const { data, error } = await supabase + .from('Cases') + .select() + .eq('id', caseId); + return { data, error }; +}; + +export const uploadCase = async (caseId: any) => { + // temporary signin + await supabase.auth.signInWithPassword({ + email: 'example@email.com', + password: 'example-password', + }); + + const { + data: { user }, + } = await supabase.auth.getUser(); + const userId = user?.identities[0].user_id; + const { error } = await supabase.from('status').insert({ caseId, userId }); + + // temporary sign out + await supabase.auth.signOut(); + console.log(error); + return { error }; +}; From 598f9e0b20dc9c19ceb4f90190c8b7b2923de705 Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:48:50 -0700 Subject: [PATCH 02/10] i'm so goated --- .../Cases/QRCodeScanner/AddCase/index.tsx | 5 +---- .../Cases/QRCodeScanner/index.tsx | 22 +++++++++---------- src/supabase/queries/case.ts | 10 +-------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx index fd68110f..89cfd225 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx @@ -55,10 +55,7 @@ function AddCase() { }, []); const addToCases = async () => { - const { error } = uploadCase(caseId); - if (error) { - console.log(error); - } + uploadCase(caseId); }; return ( diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx index 07fe6b4e..d9a7a1b4 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx @@ -2,9 +2,7 @@ import { BarCodeScanner, BarCodeScannerResult } from 'expo-barcode-scanner'; import { router } from 'expo-router'; import React, { useEffect, useState } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; - import styles from './styles'; -import { signOutUser } from '../../../../supabase/queries/auth'; enum permissions { UNDETERMINED, @@ -14,8 +12,7 @@ enum permissions { function QRCodeScannerScreen() { const [hasPermission, setHasPermission] = useState(permissions.UNDETERMINED); - const [scanned, setScanned] = useState(false); - const [data, setData] = useState('NOTHING'); + const [message, setMessage] = useState(''); useEffect(() => { const getBarCodeScannerPermissions = async () => { @@ -27,10 +24,16 @@ function QRCodeScannerScreen() { getBarCodeScannerPermissions(); }, []); + const isValidBarcode = (caseId: string) => true; + const handleBarCodeScanned = async (result: BarCodeScannerResult) => { - if (!scanned) { - setScanned(true); - setData(result.data); + if (isValidBarcode(result.data)) { + router.push({ + pathname: '/Cases/QRCodeScanner/AddCase', + params: { caseId: result.data }, + }); + } else { + setMessage('INVALID QR CODE!'); } }; @@ -45,13 +48,10 @@ function QRCodeScannerScreen() { onBarCodeScanned={handleBarCodeScanned} style={[styles.scanner]} /> - Current Scanning: {data} + Current Scanning: {message} router.back()} style={styles.button}> Go Back - signOutUser()} style={styles.button}> - Sign out - ); } diff --git a/src/supabase/queries/case.ts b/src/supabase/queries/case.ts index 280c422a..45b8090e 100644 --- a/src/supabase/queries/case.ts +++ b/src/supabase/queries/case.ts @@ -9,20 +9,12 @@ export const getCase = async (caseId: any) => { }; export const uploadCase = async (caseId: any) => { - // temporary signin - await supabase.auth.signInWithPassword({ - email: 'example@email.com', - password: 'example-password', - }); - const { data: { user }, } = await supabase.auth.getUser(); - const userId = user?.identities[0].user_id; + const userId = user?.id; const { error } = await supabase.from('status').insert({ caseId, userId }); - // temporary sign out - await supabase.auth.signOut(); console.log(error); return { error }; }; From 1a6394cea5389c96535891340a6a71cc03cb0029 Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:35:19 -0700 Subject: [PATCH 03/10] fixinggggg --- .../Cases/QRCodeScanner/AddCase/index.tsx | 78 +++++++++++++++++++ .../Cases/QRCodeScanner/AddCase/styles.ts | 40 ++++++++++ src/supabase/queries/case.ts | 28 +++++++ 3 files changed, 146 insertions(+) create mode 100644 src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx create mode 100644 src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts create mode 100644 src/supabase/queries/case.ts diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx new file mode 100644 index 00000000..fd68110f --- /dev/null +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx @@ -0,0 +1,78 @@ +import { useLocalSearchParams, useRouter } from 'expo-router'; +import React, { useEffect, useState } from 'react'; +import { Image, Text, TouchableOpacity, View } from 'react-native'; +import { getCase, uploadCase } from '../../../../../supabase/queries/case'; +import styles from './styles'; + +enum caseStatus { + NotStarted, + InProgress, + Settled, + Cancelled, +} + +export interface Case { + id: number; + approved: boolean; + title: string; + summary: string; + image: string; + caseStatus: caseStatus; +} + +function AddCase() { + const local = useLocalSearchParams(); + const { caseId } = local; + const router = useRouter(); + + const [dataImage, setDataImage] = useState(''); + const [dataTitle, setDataTitle] = useState(''); + const [dataSummary, setDataSummary] = useState(''); + + const parseData = (data: any) => { + const myData = { + ...(data[0] as Partial), + }; + return myData as Case; + }; + + useEffect(() => { + const getData = async () => { + const { data, error } = await getCase(caseId); + if (error) { + console.log('error'); + } + + const myData = parseData(data); + const { image, title, summary } = myData; + + setDataImage(image); + setDataTitle(title); + setDataSummary(summary); + console.log(data); + }; + getData(); + }, []); + + const addToCases = async () => { + const { error } = uploadCase(caseId); + if (error) { + console.log(error); + } + }; + return ( + + {dataTitle} + + {dataSummary} + + ADD TO CASES + + router.back()} style={styles.button}> + CANCEL + + + ); +} + +export default AddCase; diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts new file mode 100644 index 00000000..516fe7b5 --- /dev/null +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts @@ -0,0 +1,40 @@ +import { StyleSheet } from 'react-native'; + +export default StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + margin: 40, + }, + + title: { + fontSize: 30, + fontWeight: 'bold', + }, + + image: { + height: 200, + width: 334, + marginTop: 10, + marginBottom: 10, + }, + + blurb: { + fontSize: 17, + marginTop: 10, + marginBottom: 50, + }, + + button: { + border: 'solid', + borderWidth: 2, + marginTop: 10, + marginBottom: 10, + alignItems: 'center', + justifyContent: 'center', + backgroundColor: '#339FFF', + height: 75, + width: 334, + borderRadius: 20, + }, +}); diff --git a/src/supabase/queries/case.ts b/src/supabase/queries/case.ts new file mode 100644 index 00000000..280c422a --- /dev/null +++ b/src/supabase/queries/case.ts @@ -0,0 +1,28 @@ +import supabase from '../createClient'; + +export const getCase = async (caseId: any) => { + const { data, error } = await supabase + .from('Cases') + .select() + .eq('id', caseId); + return { data, error }; +}; + +export const uploadCase = async (caseId: any) => { + // temporary signin + await supabase.auth.signInWithPassword({ + email: 'example@email.com', + password: 'example-password', + }); + + const { + data: { user }, + } = await supabase.auth.getUser(); + const userId = user?.identities[0].user_id; + const { error } = await supabase.from('status').insert({ caseId, userId }); + + // temporary sign out + await supabase.auth.signOut(); + console.log(error); + return { error }; +}; From 9cd8681f8c555926ebc67f88a68062d53eb2788f Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:48:50 -0700 Subject: [PATCH 04/10] i'm so goated --- .../Cases/QRCodeScanner/AddCase/index.tsx | 5 +---- .../Cases/QRCodeScanner/index.tsx | 22 +++++++++---------- src/supabase/queries/case.ts | 10 +-------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx index fd68110f..89cfd225 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx @@ -55,10 +55,7 @@ function AddCase() { }, []); const addToCases = async () => { - const { error } = uploadCase(caseId); - if (error) { - console.log(error); - } + uploadCase(caseId); }; return ( diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx index 07fe6b4e..d9a7a1b4 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx @@ -2,9 +2,7 @@ import { BarCodeScanner, BarCodeScannerResult } from 'expo-barcode-scanner'; import { router } from 'expo-router'; import React, { useEffect, useState } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; - import styles from './styles'; -import { signOutUser } from '../../../../supabase/queries/auth'; enum permissions { UNDETERMINED, @@ -14,8 +12,7 @@ enum permissions { function QRCodeScannerScreen() { const [hasPermission, setHasPermission] = useState(permissions.UNDETERMINED); - const [scanned, setScanned] = useState(false); - const [data, setData] = useState('NOTHING'); + const [message, setMessage] = useState(''); useEffect(() => { const getBarCodeScannerPermissions = async () => { @@ -27,10 +24,16 @@ function QRCodeScannerScreen() { getBarCodeScannerPermissions(); }, []); + const isValidBarcode = (caseId: string) => true; + const handleBarCodeScanned = async (result: BarCodeScannerResult) => { - if (!scanned) { - setScanned(true); - setData(result.data); + if (isValidBarcode(result.data)) { + router.push({ + pathname: '/Cases/QRCodeScanner/AddCase', + params: { caseId: result.data }, + }); + } else { + setMessage('INVALID QR CODE!'); } }; @@ -45,13 +48,10 @@ function QRCodeScannerScreen() { onBarCodeScanned={handleBarCodeScanned} style={[styles.scanner]} /> - Current Scanning: {data} + Current Scanning: {message} router.back()} style={styles.button}> Go Back - signOutUser()} style={styles.button}> - Sign out - ); } diff --git a/src/supabase/queries/case.ts b/src/supabase/queries/case.ts index 280c422a..45b8090e 100644 --- a/src/supabase/queries/case.ts +++ b/src/supabase/queries/case.ts @@ -9,20 +9,12 @@ export const getCase = async (caseId: any) => { }; export const uploadCase = async (caseId: any) => { - // temporary signin - await supabase.auth.signInWithPassword({ - email: 'example@email.com', - password: 'example-password', - }); - const { data: { user }, } = await supabase.auth.getUser(); - const userId = user?.identities[0].user_id; + const userId = user?.id; const { error } = await supabase.from('status').insert({ caseId, userId }); - // temporary sign out - await supabase.auth.signOut(); console.log(error); return { error }; }; From 47ae70d23b0ab22a034ea0131574d215fc6bf2e1 Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:35:19 -0700 Subject: [PATCH 05/10] fixinggggg --- .../Cases/QRCodeScanner/AddCase/index.tsx | 78 +++++++++++++++++++ .../Cases/QRCodeScanner/AddCase/styles.ts | 40 ++++++++++ src/supabase/queries/case.ts | 28 +++++++ 3 files changed, 146 insertions(+) create mode 100644 src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx create mode 100644 src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts create mode 100644 src/supabase/queries/case.ts diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx new file mode 100644 index 00000000..fd68110f --- /dev/null +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx @@ -0,0 +1,78 @@ +import { useLocalSearchParams, useRouter } from 'expo-router'; +import React, { useEffect, useState } from 'react'; +import { Image, Text, TouchableOpacity, View } from 'react-native'; +import { getCase, uploadCase } from '../../../../../supabase/queries/case'; +import styles from './styles'; + +enum caseStatus { + NotStarted, + InProgress, + Settled, + Cancelled, +} + +export interface Case { + id: number; + approved: boolean; + title: string; + summary: string; + image: string; + caseStatus: caseStatus; +} + +function AddCase() { + const local = useLocalSearchParams(); + const { caseId } = local; + const router = useRouter(); + + const [dataImage, setDataImage] = useState(''); + const [dataTitle, setDataTitle] = useState(''); + const [dataSummary, setDataSummary] = useState(''); + + const parseData = (data: any) => { + const myData = { + ...(data[0] as Partial), + }; + return myData as Case; + }; + + useEffect(() => { + const getData = async () => { + const { data, error } = await getCase(caseId); + if (error) { + console.log('error'); + } + + const myData = parseData(data); + const { image, title, summary } = myData; + + setDataImage(image); + setDataTitle(title); + setDataSummary(summary); + console.log(data); + }; + getData(); + }, []); + + const addToCases = async () => { + const { error } = uploadCase(caseId); + if (error) { + console.log(error); + } + }; + return ( + + {dataTitle} + + {dataSummary} + + ADD TO CASES + + router.back()} style={styles.button}> + CANCEL + + + ); +} + +export default AddCase; diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts new file mode 100644 index 00000000..516fe7b5 --- /dev/null +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts @@ -0,0 +1,40 @@ +import { StyleSheet } from 'react-native'; + +export default StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + margin: 40, + }, + + title: { + fontSize: 30, + fontWeight: 'bold', + }, + + image: { + height: 200, + width: 334, + marginTop: 10, + marginBottom: 10, + }, + + blurb: { + fontSize: 17, + marginTop: 10, + marginBottom: 50, + }, + + button: { + border: 'solid', + borderWidth: 2, + marginTop: 10, + marginBottom: 10, + alignItems: 'center', + justifyContent: 'center', + backgroundColor: '#339FFF', + height: 75, + width: 334, + borderRadius: 20, + }, +}); diff --git a/src/supabase/queries/case.ts b/src/supabase/queries/case.ts new file mode 100644 index 00000000..280c422a --- /dev/null +++ b/src/supabase/queries/case.ts @@ -0,0 +1,28 @@ +import supabase from '../createClient'; + +export const getCase = async (caseId: any) => { + const { data, error } = await supabase + .from('Cases') + .select() + .eq('id', caseId); + return { data, error }; +}; + +export const uploadCase = async (caseId: any) => { + // temporary signin + await supabase.auth.signInWithPassword({ + email: 'example@email.com', + password: 'example-password', + }); + + const { + data: { user }, + } = await supabase.auth.getUser(); + const userId = user?.identities[0].user_id; + const { error } = await supabase.from('status').insert({ caseId, userId }); + + // temporary sign out + await supabase.auth.signOut(); + console.log(error); + return { error }; +}; From 843a069397c3dc845c3cdaf228ca272e1643a7bc Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:48:50 -0700 Subject: [PATCH 06/10] i'm so goated --- .../Cases/QRCodeScanner/AddCase/index.tsx | 5 +---- .../Cases/QRCodeScanner/index.tsx | 22 +++++++++---------- src/supabase/queries/case.ts | 10 +-------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx index fd68110f..89cfd225 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx @@ -55,10 +55,7 @@ function AddCase() { }, []); const addToCases = async () => { - const { error } = uploadCase(caseId); - if (error) { - console.log(error); - } + uploadCase(caseId); }; return ( diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx index 07fe6b4e..d9a7a1b4 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx @@ -2,9 +2,7 @@ import { BarCodeScanner, BarCodeScannerResult } from 'expo-barcode-scanner'; import { router } from 'expo-router'; import React, { useEffect, useState } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; - import styles from './styles'; -import { signOutUser } from '../../../../supabase/queries/auth'; enum permissions { UNDETERMINED, @@ -14,8 +12,7 @@ enum permissions { function QRCodeScannerScreen() { const [hasPermission, setHasPermission] = useState(permissions.UNDETERMINED); - const [scanned, setScanned] = useState(false); - const [data, setData] = useState('NOTHING'); + const [message, setMessage] = useState(''); useEffect(() => { const getBarCodeScannerPermissions = async () => { @@ -27,10 +24,16 @@ function QRCodeScannerScreen() { getBarCodeScannerPermissions(); }, []); + const isValidBarcode = (caseId: string) => true; + const handleBarCodeScanned = async (result: BarCodeScannerResult) => { - if (!scanned) { - setScanned(true); - setData(result.data); + if (isValidBarcode(result.data)) { + router.push({ + pathname: '/Cases/QRCodeScanner/AddCase', + params: { caseId: result.data }, + }); + } else { + setMessage('INVALID QR CODE!'); } }; @@ -45,13 +48,10 @@ function QRCodeScannerScreen() { onBarCodeScanned={handleBarCodeScanned} style={[styles.scanner]} /> - Current Scanning: {data} + Current Scanning: {message} router.back()} style={styles.button}> Go Back - signOutUser()} style={styles.button}> - Sign out - ); } diff --git a/src/supabase/queries/case.ts b/src/supabase/queries/case.ts index 280c422a..45b8090e 100644 --- a/src/supabase/queries/case.ts +++ b/src/supabase/queries/case.ts @@ -9,20 +9,12 @@ export const getCase = async (caseId: any) => { }; export const uploadCase = async (caseId: any) => { - // temporary signin - await supabase.auth.signInWithPassword({ - email: 'example@email.com', - password: 'example-password', - }); - const { data: { user }, } = await supabase.auth.getUser(); - const userId = user?.identities[0].user_id; + const userId = user?.id; const { error } = await supabase.from('status').insert({ caseId, userId }); - // temporary sign out - await supabase.auth.signOut(); console.log(error); return { error }; }; From 2b611dacaa5376503adb5a7a659ec21ba401493f Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Sat, 21 Oct 2023 10:48:59 -0700 Subject: [PATCH 07/10] hi --- .eslintignore 2 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .eslintignore 2 diff --git a/.eslintignore 2 b/.eslintignore 2 new file mode 100644 index 00000000..4cf897b0 --- /dev/null +++ b/.eslintignore 2 @@ -0,0 +1,2 @@ +/.expo +node_modules \ No newline at end of file From e83fd77e30bee9e5028cdaf8b6129c57b0fa321f Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Sat, 21 Oct 2023 11:32:37 -0700 Subject: [PATCH 08/10] fixed some supabase issues --- .../Cases/QRCodeScanner/AddCase/index.tsx | 64 ++++--------------- .../Cases/QRCodeScanner/index.tsx | 4 +- src/supabase/queries/cases.ts | 2 +- 3 files changed, 17 insertions(+), 53 deletions(-) diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx index 89cfd225..35c7e333 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx @@ -2,66 +2,28 @@ import { useLocalSearchParams, useRouter } from 'expo-router'; import React, { useEffect, useState } from 'react'; import { Image, Text, TouchableOpacity, View } from 'react-native'; import { getCase, uploadCase } from '../../../../../supabase/queries/case'; +import { CaseUid } from '../../../../../types/types'; import styles from './styles'; -enum caseStatus { - NotStarted, - InProgress, - Settled, - Cancelled, -} - -export interface Case { - id: number; - approved: boolean; - title: string; - summary: string; - image: string; - caseStatus: caseStatus; -} - function AddCase() { - const local = useLocalSearchParams(); - const { caseId } = local; + const { id, title, summary, image } = useLocalSearchParams<{ + id: CaseUid; + title: string; + summary: string; + image: string; + }>(); + console.log(id, title, summary, image); const router = useRouter(); - const [dataImage, setDataImage] = useState(''); - const [dataTitle, setDataTitle] = useState(''); - const [dataSummary, setDataSummary] = useState(''); - - const parseData = (data: any) => { - const myData = { - ...(data[0] as Partial), - }; - return myData as Case; - }; - - useEffect(() => { - const getData = async () => { - const { data, error } = await getCase(caseId); - if (error) { - console.log('error'); - } - - const myData = parseData(data); - const { image, title, summary } = myData; - - setDataImage(image); - setDataTitle(title); - setDataSummary(summary); - console.log(data); - }; - getData(); - }, []); - const addToCases = async () => { - uploadCase(caseId); + uploadCase(id); + router.push('/Cases'); }; return ( - {dataTitle} - - {dataSummary} + {title} + + {summary} ADD TO CASES diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx index d9a7a1b4..546a42b2 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx @@ -2,6 +2,7 @@ import { BarCodeScanner, BarCodeScannerResult } from 'expo-barcode-scanner'; import { router } from 'expo-router'; import React, { useEffect, useState } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; +import { getCaseById } from '../../../../supabase/queries/cases'; import styles from './styles'; enum permissions { @@ -28,9 +29,10 @@ function QRCodeScannerScreen() { const handleBarCodeScanned = async (result: BarCodeScannerResult) => { if (isValidBarcode(result.data)) { + const { id, title, summary, image } = await getCaseById(result.data); router.push({ pathname: '/Cases/QRCodeScanner/AddCase', - params: { caseId: result.data }, + params: { id, title, summary, image }, }); } else { setMessage('INVALID QR CODE!'); diff --git a/src/supabase/queries/cases.ts b/src/supabase/queries/cases.ts index c4ad8dd4..72e2b937 100644 --- a/src/supabase/queries/cases.ts +++ b/src/supabase/queries/cases.ts @@ -79,7 +79,7 @@ export async function getCasesByIds(caseIds: CaseUid[]): Promise { */ export function parseCase(item: any): Case { const formattedCase: Case = { - id: item.id, + id: item.caseId, approved: item.approved, title: item.title, blurb: item.blurb, From df2329c66dcea0947ef584874d263981f1d510a8 Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Sat, 21 Oct 2023 11:39:45 -0700 Subject: [PATCH 09/10] hello --- .../Cases/QRCodeScanner/AddCase/styles.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts index 516fe7b5..b6b6f8c9 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/styles.ts @@ -13,8 +13,8 @@ export default StyleSheet.create({ }, image: { - height: 200, - width: 334, + height: '35%', + width: '100%', marginTop: 10, marginBottom: 10, }, @@ -33,8 +33,8 @@ export default StyleSheet.create({ alignItems: 'center', justifyContent: 'center', backgroundColor: '#339FFF', - height: 75, - width: 334, + height: '10%', + width: '100%', borderRadius: 20, }, }); From 2ebf1e7634e4a95037b75c4451965b12145799bb Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Sat, 21 Oct 2023 11:44:28 -0700 Subject: [PATCH 10/10] fixed the query doubled file --- .../Cases/QRCodeScanner/AddCase/index.tsx | 3 +-- src/supabase/queries/case.ts | 20 ------------------- src/supabase/queries/cases.ts | 11 ++++++++++ 3 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 src/supabase/queries/case.ts diff --git a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx index 35c7e333..d7c9324f 100644 --- a/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx @@ -1,7 +1,6 @@ import { useLocalSearchParams, useRouter } from 'expo-router'; -import React, { useEffect, useState } from 'react'; import { Image, Text, TouchableOpacity, View } from 'react-native'; -import { getCase, uploadCase } from '../../../../../supabase/queries/case'; +import { uploadCase } from '../../../../../supabase/queries/cases'; import { CaseUid } from '../../../../../types/types'; import styles from './styles'; diff --git a/src/supabase/queries/case.ts b/src/supabase/queries/case.ts deleted file mode 100644 index 45b8090e..00000000 --- a/src/supabase/queries/case.ts +++ /dev/null @@ -1,20 +0,0 @@ -import supabase from '../createClient'; - -export const getCase = async (caseId: any) => { - const { data, error } = await supabase - .from('Cases') - .select() - .eq('id', caseId); - return { data, error }; -}; - -export const uploadCase = async (caseId: any) => { - const { - data: { user }, - } = await supabase.auth.getUser(); - const userId = user?.id; - const { error } = await supabase.from('status').insert({ caseId, userId }); - - console.log(error); - return { error }; -}; diff --git a/src/supabase/queries/cases.ts b/src/supabase/queries/cases.ts index 72e2b937..002bbafb 100644 --- a/src/supabase/queries/cases.ts +++ b/src/supabase/queries/cases.ts @@ -71,6 +71,17 @@ export async function getCasesByIds(caseIds: CaseUid[]): Promise { } } +export const uploadCase = async (caseId: any) => { + const { + data: { user }, + } = await supabase.auth.getUser(); + const userId = user?.id; + const { error } = await supabase.from('status').insert({ caseId, userId }); + + console.log(error); + return { error }; +}; + /** * Parse supabase case query and return Case object. *