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

Redeem merch #41

Merged
merged 3 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
40 changes: 24 additions & 16 deletions navigation/EventDaysNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, useRef, useCallback } from "react";
import { createMaterialTopTabNavigator } from "@react-navigation/material-top-tabs";
import DayEvent from "./DayEvent";
import Colors from "../constants/Colors";
Expand All @@ -16,23 +16,31 @@ const WeekTab = createMaterialTopTabNavigator();

const EventDaysNavigator = () => {
const [eventsData, setEventsData] = useState([]);
const loaded = useRef(false)

useFocusEffect(() => {
const fetchEvents = async () => {
try {
const response = await fetch(eventsURL);
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
setEventsData(data); // Update eventsData state with fetched data
} catch (error) {
console.error("Error fetching events:", error);
useFocusEffect(
useCallback(() => {
if (!loaded.current) {
const fetchEvents = async () => {
try {
const response = await fetch(eventsURL);
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
setEventsData(data); // Update eventsData state with fetched data
} catch (error) {
console.error("Error fetching events:", error);
}
};
fetchEvents();
loaded.current = true;
}
};

fetchEvents();
}); // Empty dependency array ensures useEffect runs only once
return () => {
loaded.current = false;
}
}, [])
); // Empty dependency array ensures useEffect runs only once

const filterEventsByDay = (day) => {
return eventsData.filter((event) => {
Expand Down
37 changes: 23 additions & 14 deletions screens/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useCallback, useRef } from "react";
import { SafeAreaView } from "react-native-safe-area-context";
import { Dimensions, View, StyleSheet, ActivityIndicator } from "react-native";
import { useFonts, PressStart2P_400Regular } from "@expo-google-fonts/press-start-2p";
Expand All @@ -21,20 +21,29 @@ const Home: React.FC = () => {
const [currNextEvent, setCurrNextEvent] = useState(null);
const [loading, setLoading] = useState(true); // To track loading state

useFocusEffect(() => {
const fetchCurrNext = async () => {
try {
const event = await getCurrentOrNext(token);
setCurrNextEvent(event);
} catch (error) {
console.error("error fetching current/next event:", error);
} finally {
setLoading(false); // Stop loading once the fetch is complete
}
};
const loaded = useRef(false)

fetchCurrNext();
});
useFocusEffect(
useCallback(() => {
if (!loaded.current) {
const fetchEvents = async () => {
try {
const event = await getCurrentOrNext(token);
setCurrNextEvent(event); // Update eventsData state with fetched data
} catch (error) {
console.error("Error fetching events:", error);
} finally {
setLoading(false)
}
};
fetchEvents();
loaded.current = true;
}
return () => {
loaded.current = false;
}
}, [])
); // Empty dependency array ensures useEffect runs only once

if (loading) {
return (
Expand Down
7 changes: 5 additions & 2 deletions screens/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const Profile: React.FC = () => {
if (token && !attendee) {
dispatch(getAttendee(token));
}
if (token && !qrcode) {
getQRCode(token, setQRCode);
}
}, [token, attendee, dispatch]);

useFocusEffect(() => {
Expand All @@ -59,9 +62,9 @@ const Profile: React.FC = () => {
})

useEffect(() => {
const interval = setInterval(async () => {await getQRCode(token, setQRCode)}, 20000);
const interval = setInterval(async () => {await getQRCode(token, setQRCode)}, 18000 + (Math.random() * 5000));
//return () => clearInterval(interval);
}, [token]);
});

const handleLogOut = () => {
console.log("logging out")
Expand Down
Loading