Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

screens/ #40

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 6 additions & 3 deletions Components/EventDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const EventDropdown: React.FC<EventDropdownProps> = ({ token, onEventSelect }) =
const fetchEvents = async () => {
try {
const eventData = await getEvents(token);
setEvents(eventData);
setEvents([{
eventId: 'checkin',
name: 'checkin'
}, ...eventData]);
} catch (error) {
console.error('Error fetching events:', error);
}
Expand All @@ -43,7 +46,7 @@ const EventDropdown: React.FC<EventDropdownProps> = ({ token, onEventSelect }) =
value: event.eventId,
}))}
style={pickerSelectStyles}
placeholder={{ label: 'Select an event...', value: null}}
placeholder={{ label: 'Select an event...', value: null }}
/>
</View>
);
Expand Down Expand Up @@ -83,7 +86,7 @@ const pickerSelectStyles = StyleSheet.create({
color: Colors.WHITE,
fontFamily: "Inter_500Medium",
paddingRight: 12, // to ensure the text is never behind the icon

},
inputAndroid: {
fontSize: 20,
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
16 changes: 16 additions & 0 deletions api/postRPCheckIn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import axios from "axios";

export const postRPCheckIn = async(token, eventId, qrCode) => {
const payload = { eventId, qrCode }
try {
const response = await axios.post('https://api.reflectionsprojections.org/checkin/', payload, {
headers: {
Authorization: token
}
});
//console.log('post CheckIn:', response.data)
} catch (error) {
console.log('Error posting check in:', error)
alert(`Error with scanning QR Code!`);
}
};
5 changes: 3 additions & 2 deletions navigation/EventDaysNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Inter_500Medium,
Inter_700Bold,
} from "@expo-google-fonts/inter";
import { useFocusEffect } from "@react-navigation/native";

const eventsURL = "https://api.reflectionsprojections.org/events/";

Expand All @@ -16,7 +17,7 @@ const WeekTab = createMaterialTopTabNavigator();
const EventDaysNavigator = () => {
const [eventsData, setEventsData] = useState([]);

useEffect(() => {
useFocusEffect(() => {
const fetchEvents = async () => {
try {
const response = await fetch(eventsURL);
Expand All @@ -31,7 +32,7 @@ const EventDaysNavigator = () => {
};

fetchEvents();
}, []); // Empty dependency array ensures useEffect runs only once
}); // Empty dependency array ensures useEffect runs only once

const filterEventsByDay = (day) => {
return eventsData.filter((event) => {
Expand Down
25 changes: 20 additions & 5 deletions screens/AdminScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { postCheckIn } from "../api/postCheckIn";
import { StyledButton } from "../Components/Buttons";
import axios from "axios";
import Colors from "../constants/Colors";
import { postRPCheckIn } from "../api/postRPCheckIn";

// import { Button, ButtonText, ButtonIcon, AddIcon } from "@gluestack-ui/themed";

Expand All @@ -31,9 +32,16 @@ const AdminScanner: React.FC = () => {

const handleBarCodeScanned = ({type, data}) => {
setScanned(true);
postCheckIn(token, selectedEvent, data)
if (selectedEvent == 'checkin') {
postRPCheckIn(token, selectedEvent, data)
} else {
postCheckIn(token, selectedEvent, data)
}
};

const handleSelectedEvent = (event) => {
setSelectedEvent(event);
}
// mute={true} is used to mute the camera so we dont need mic permissions
// https://github.com/expo/expo/issues/27984 of course it is undocumented <333

Expand All @@ -43,7 +51,7 @@ const AdminScanner: React.FC = () => {
<View style = {styles.cameraContainer}>
{token && (
<View style = {styles.dropdownContainer}>
<EventDropdown token={token} onEventSelect={setSelectedEvent}/>
<EventDropdown token={token} onEventSelect={handleSelectedEvent}/>
</View>
)}
<CameraView
Expand All @@ -52,12 +60,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
7 changes: 3 additions & 4 deletions screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RootState } from "../redux/store";
import CurrentEventCard from "../Components/CurrentEventCard";
import Colors from "../constants/Colors";
import { Text } from "@gluestack-ui/themed";
import Notification from "../Notification";
import { useFocusEffect } from "@react-navigation/native";

const { width, height } = Dimensions.get("window");

Expand All @@ -21,7 +21,7 @@ const Home: React.FC = () => {
const [currNextEvent, setCurrNextEvent] = useState(null);
const [loading, setLoading] = useState(true); // To track loading state

useEffect(() => {
useFocusEffect(() => {
const fetchCurrNext = async () => {
try {
const event = await getCurrentOrNext(token);
Expand All @@ -34,7 +34,7 @@ const Home: React.FC = () => {
};

fetchCurrNext();
}, [token]);
});

if (loading) {
return (
Expand Down Expand Up @@ -71,7 +71,6 @@ const Home: React.FC = () => {
)}

</View>
<Notification/>
</SafeAreaView>
);
};
Expand Down
25 changes: 8 additions & 17 deletions screens/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useFonts, Kufam_400Regular, Kufam_700Bold, Kufam_700Bold_Italic } from
import FoodWaveSVG from "../Components/FoodWaveSVG"
import { Dimensions } from "react-native";
import { logout } from "../redux/actions";
import { useNavigation } from "@react-navigation/native";
import { useFocusEffect, useNavigation } from "@react-navigation/native";
import { StackNavigationProp } from "@react-navigation/stack";

import QRFrame from '../assets/SVGs/qrcode/QRFrame1.svg'
Expand All @@ -40,37 +40,28 @@ 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));
}
}, [token, attendee, qrcode, dispatch]);
}, [token, attendee, dispatch]);

useEffect(() => {
useFocusEffect(() => {
const fetchFoodWave = async () => {
const foodwave = await getFoodWave(token);
setFoodWave(foodwave.foodwave);
}
fetchFoodWave();
}, [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
Loading