Skip to content

Commit

Permalink
scanning fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bahl-Aryan committed Sep 13, 2024
1 parent d81c830 commit 9ce2827
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 32 deletions.
3 changes: 3 additions & 0 deletions Components/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const StyledButton = styled(Button,
},
scan: {
bg: Colors.DARK_BLUE
},
scan_green: {
bg: "$green"
}
},
},
Expand Down
30 changes: 15 additions & 15 deletions api/getQRCode.tsx
Original file line number Diff line number Diff line change
@@ -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);
};
};
2 changes: 1 addition & 1 deletion api/postCheckIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!`);
Expand Down
13 changes: 10 additions & 3 deletions screens/AdminScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,19 @@ const AdminScanner: React.FC = () => {
barcodeScannerSettings={{barcodeTypes: ["qr"]}}
/>
<View style={styles.buttonContainer}>
{scanned &&
<StyledButton styleVariant="scan"
{(scanned) ? (
<StyledButton styleVariant="scan_green"
onPress={() => setScanned(false)}
>
<ButtonText color={Colors.WHITE}>Tap to Scan Again </ButtonText>
<ButtonText color={Colors.WHITE}>Scanned!</ButtonText>
</StyledButton>
) : (
<StyledButton styleVariant="scan"
onPress={() => setScanned(true)}
>
<ButtonText color={Colors.WHITE}>Tap to Scan Again </ButtonText>
</StyledButton>
)
}
</View>
</View>
Expand Down
16 changes: 5 additions & 11 deletions screens/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ const Profile: React.FC = () => {
const navigation = useNavigation<ProfileScreenNavigationProp>();
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]);

Expand All @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions screens/Shop.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -21,7 +22,7 @@ const Shop: React.FC = () => {
PressStart2P_400Regular,
});

useEffect(() => {
useFocusEffect(() => {
const fetchUserPoints = async () => {
try {
const points = await getPoints(token);
Expand All @@ -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 <AppLoading />;
Expand Down

0 comments on commit 9ce2827

Please sign in to comment.