From 9ce2827cd3298805238d03699c0db9708d705212 Mon Sep 17 00:00:00 2001 From: Bahl-Aryan Date: Thu, 12 Sep 2024 22:07:07 -0500 Subject: [PATCH] scanning fixes --- Components/Buttons.tsx | 3 +++ api/getQRCode.tsx | 30 +++++++++++++++--------------- api/postCheckIn.tsx | 2 +- screens/AdminScanner.tsx | 13 ++++++++++--- screens/Profile.tsx | 16 +++++----------- screens/Shop.tsx | 6 ++++-- 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/Components/Buttons.tsx b/Components/Buttons.tsx index f1a25ae..603e42a 100644 --- a/Components/Buttons.tsx +++ b/Components/Buttons.tsx @@ -16,6 +16,9 @@ const StyledButton = styled(Button, }, scan: { bg: Colors.DARK_BLUE + }, + scan_green: { + bg: "$green" } }, }, diff --git a/api/getQRCode.tsx b/api/getQRCode.tsx index f7448aa..3b4a9c9 100644 --- a/api/getQRCode.tsx +++ b/api/getQRCode.tsx @@ -1,18 +1,18 @@ import { setQRCode } from "../redux/actions"; -export const getQRCode = (token: string) => { - return async (dispatch: any) => { - try { - const response = await fetch('https://api.reflectionsprojections.org/attendee/qr/', { - headers: { - Authorization: token, - 'Content-Type': 'application/json' - }, - }); - const data = await response.json(); - dispatch(setQRCode(data.qrCode)); - } catch (error) { - console.error('Error fetching qrcode:', error); - } - }; +export const getQRCode = async (token: string, callback:Function) => { + try { + const response = await fetch('https://api.reflectionsprojections.org/attendee/qr/', { + headers: { + Authorization: token, + 'Content-Type': 'application/json' + }, + }); + const data = await response.json(); + console.log(data) + //dispatch(setQRCode(data.qrCode)); + callback(data.qrCode) + } catch (error) { + console.error('Error fetching qrcode:', error); + }; }; \ No newline at end of file diff --git a/api/postCheckIn.tsx b/api/postCheckIn.tsx index 6251283..0d84cec 100644 --- a/api/postCheckIn.tsx +++ b/api/postCheckIn.tsx @@ -8,7 +8,7 @@ export const postCheckIn = async(token, eventId, qrCode) => { Authorization: token } }); - console.log('post CheckIn:', response.data) + //console.log('post CheckIn:', response.data) } catch (error) { console.log('Error posting check in:', error) alert(`Error with scanning QR Code!`); diff --git a/screens/AdminScanner.tsx b/screens/AdminScanner.tsx index 1e0a76f..734b7f7 100644 --- a/screens/AdminScanner.tsx +++ b/screens/AdminScanner.tsx @@ -55,12 +55,19 @@ const AdminScanner: React.FC = () => { barcodeScannerSettings={{barcodeTypes: ["qr"]}} /> - {scanned && - setScanned(false)} > - Tap to Scan Again + Scanned! + + ) : ( + setScanned(true)} + > + Tap to Scan Again + ) } diff --git a/screens/Profile.tsx b/screens/Profile.tsx index 2d21880..1f4b7d0 100644 --- a/screens/Profile.tsx +++ b/screens/Profile.tsx @@ -40,16 +40,16 @@ const Profile: React.FC = () => { const navigation = useNavigation(); const token = useAppSelector((state: RootState) => state.token); const attendee = useAppSelector((state: RootState) => state.attendee); - const qrcode = useAppSelector((state: RootState) => state.qrCodeURL); const [foodWave, setFoodWave] = useState(null); + const [qrcode, setQRCode] = useState(null); useEffect(() => { if (token && !attendee) { dispatch(getAttendee(token)); } if (token && !qrcode) { - dispatch(getQRCode(token)); + getQRCode(token, setQRCode); } }, [token, attendee, qrcode, dispatch]); @@ -62,15 +62,9 @@ const Profile: React.FC = () => { }, [token]) useEffect(() => { - const fetchQRCode = async() => { - if (token) { - await(dispatch(getQRCode(token))); - } - }; - fetchQRCode(); - const interval = setInterval(getQRCode, 20000); - return () => clearInterval(interval); - }, [token, dispatch]); + const interval = setInterval(async () => {await getQRCode(token, setQRCode)}, 20000); + //return () => clearInterval(interval); + }, [token]); const handleLogOut = () => { console.log("logging out") diff --git a/screens/Shop.tsx b/screens/Shop.tsx index be1faee..17f6220 100644 --- a/screens/Shop.tsx +++ b/screens/Shop.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from "react"; +import { useFocusEffect } from "@react-navigation/native"; import { RootState } from "../redux/store"; import { useAppSelector } from "../redux/hooks"; import { SafeAreaView, View, Text, Image, StyleSheet } from "react-native"; @@ -21,7 +22,7 @@ const Shop: React.FC = () => { PressStart2P_400Regular, }); - useEffect(() => { + useFocusEffect(() => { const fetchUserPoints = async () => { try { const points = await getPoints(token); @@ -30,8 +31,9 @@ const Shop: React.FC = () => { console.error("error fetching points for user:", error); } }; + console.log("points") fetchUserPoints(); // Fetch points when component mounts - }, [token]); // Empty dependency array means this effect runs once on mount + }); // Empty dependency array means this effect runs once on mount if (!fontsLoaded) { return ;