Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
reedoooo committed Nov 24, 2023
1 parent 2fbbd9a commit 50bc63e
Show file tree
Hide file tree
Showing 144 changed files with 4,274 additions and 9,102 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@
"react-helmet": "^6.1.0",
"react-icons": "^4.10.1",
"react-if": "^4.1.5",
"react-material-ui-carousel": "^3.4.2",
"react-pro-sidebar": "^1.1.0-alpha.1",
"react-redux": "^8.1.1",
"react-responsive-carousel": "^3.2.23",
"react-router-dom": "^6.17.0",
"react-scripts": "5.0.1",
"react-slick": "^0.29.0",
"react-spinners": "^0.13.8",
"react-stripe-checkout": "^2.6.3",
"react-swipeable-views": "^0.14.0",
"slick-carousel": "^1.8.1",
"socket.io-client": "^4.7.2",
"stripe": "^12.14.0",
"styled-components": "^6.0.5",
Expand Down Expand Up @@ -75,6 +79,7 @@
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.9.0",
"eslint-plugin-prettier": "^5.0.0",
"http-proxy-middleware": "^2.0.6",
"prettier": "^3.0.0"
}
}
196 changes: 31 additions & 165 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// External Imports
import React, { useEffect, useRef, useState } from 'react';
import {
BrowserRouter as Router,
Route,
Routes,
useLocation,
} from 'react-router-dom';
import React, { useContext, useEffect, useRef, useState } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import styled, { createGlobalStyle } from 'styled-components';

// Component Imports
import Header from './components/headings/header/Header';
import Footer from './components/headings/footer/Footer';
import PrivateRoute from './components/Auth/PrivateRoute';
import PrivateRoute from './components/reusable/PrivateRoute';

// Page Imports
import SplashPage from './pages/SplashPage';
Expand All @@ -22,182 +16,54 @@ import CartPage from './pages/CartPage';
import ProfilePage from './pages/ProfilePage';
import CollectionPage from './pages/CollectionPage';
import DeckBuilderPage from './pages/DeckBuilderPage';
import ThreeJsCube from './pages/ThreeJsCube';
import CardDeckAnimation from './pages/CardDeckAnimation';
import ThreeJsCube from './assets/animations/ThreeJsCube';
import CardDeckAnimation from './assets/animations/CardDeckAnimation';

// Context Hooks Imports
import { useCombinedContext } from './context/CombinedProvider';
import { useUserContext } from './context/UserContext/UserContext';
import { useCollectionStore } from './context/CollectionContext/CollectionContext';
import { useUtilityContext } from './context/UtilityContext/UtilityContext';
import { AppContainer } from './pages/pageStyles/StyledComponents';
import { useCardImages } from './context/CardImagesContext/CardImagesContext';
import { useCookies } from 'react-cookie';
const App = () => {
const [cookies] = useCookies(['user']);

// Styled Components
const AppContainer = styled.div`
display: flex;
flex-direction: column;
height: 100vh;
`;

const GlobalStyle = createGlobalStyle`
/* Your global styles here */
`;
const user = cookies.user;
const [currentPage, setCurrentPage] = useState('');
// const { setContext } = useAppContext(); // Assuming useAppContext provides setContext
const { fetchAllCollectionsForUser, selectedCollection } =
useCollectionStore();
const { isLoading, setIsLoading } = useUtilityContext();

// Custom Hook for Cron Job
const useCronJob = (lastCronJobTriggerTime, setLastCronJobTriggerTime) => {
const {
cronData,
handleSendAllCardsInCollections,
listOfMonitoredCards,
// handleRetreiveListOfMonitoredCards,
// retrievedListOfMonitoredCards,
allCollectionsUpdated,
} = useCombinedContext();
const { allCollections } = useCollectionStore();
const [priceHistory, setPriceHistory] = useState([]);
// const { getRandomCardImages } = useCardImages(); // Add this line

const { handlePricesActivateCron, cardsWithChangedPrice } =
useCombinedContext();
const { user } = useUserContext();
const [priceFlux, setPriceFlux] = useState(null);
const userId = user?.userID;
useEffect(() => {
setLastCronJobTriggerTime(new Date().getTime());
}, [setLastCronJobTriggerTime]);
// ---------------------------------------------------------------
// useEffect(() => {
// handlePricesActivateCron(
// userId,
// listOfMonitoredCards,
// allCollections,
// cardsWithChangedPrice
// );
// }, [
// userId,
// listOfMonitoredCards,
// allCollections,
// cardsWithChangedPrice,
// priceFlux,
// ]);

useEffect(() => {
const handleTriggerCronJob = () => {
const currentTime = new Date().getTime();
const timeDifference = currentTime - lastCronJobTriggerTime;
const previousTotalPrice = allCollections?.totalPrice;
if (!priceHistory.includes(previousTotalPrice)) {
priceHistory.push(previousTotalPrice);
}
const minutes = Math.floor(timeDifference / 60000); // 1 minute = 60000 milliseconds
const seconds = Math.floor((timeDifference % 60000) / 1000); // remainder in milliseconds converted to seconds

// Output the remaining time in minutes and seconds
console.log(
`REMAINING TIME: ${minutes} minute(s) and ${seconds} second(s)`
);

for (const collection of allCollections) {
if (
collection?.cards &&
collection?.cards?.length > 0 &&
collection.totalPrice !== previousTotalPrice // Implement your logic here
) {
setPriceFlux(new Date().getTime()); // Trigger a re-render
console.log('PRICE FLUX:', priceFlux);
}
}
// if (collection.totalPrice !== previousTotalPrice) {
// // Update dependencies of useEffect
// setPriceFlux(new Date().getTime()); // Trigger a re-render
// }
if (currentTime - lastCronJobTriggerTime >= 60000) {
setLastCronJobTriggerTime(currentTime);
if (userId && listOfMonitoredCards) {
console.log('RETRIEVING LIST OF MONITORED CARDS (paused)');
handleSendAllCardsInCollections(
userId,
listOfMonitoredCards
// handleRetrieveListOfMonitoredCards()
);
console.log('Triggered the cron job.');
}
}
};

const interval = setInterval(handleTriggerCronJob, 60000);
return () => clearInterval(interval);
}, [
cronData,
lastCronJobTriggerTime,
allCollectionsUpdated,
// handleRetrieveListOfMonitoredCards,
handleSendAllCardsInCollections,
listOfMonitoredCards,
userId,
]);
};

// Main Component
const App = () => {
const { user } = useUserContext();
const { isLoading, setIsContextLoading } = useUtilityContext();
const { fetchAllCollectionsForUser, allCollections } = useCollectionStore();
const [lastCronJobTriggerTime, setLastCronJobTriggerTime] = useState(null);

useCronJob(lastCronJobTriggerTime, setLastCronJobTriggerTime);
// getRandomCardImages(10); // Fetch 10 random images on app start
// }, []); // Add this useEffect

useEffect(() => {
if (user) {
console.log('Private routes now available');
fetchAllCollectionsForUser(user.id)
.then(() => {
setIsLoading(false);
})
.catch((error) => {
console.error('Error fetching collections:', error);
setIsLoading(false);
});
}
}, [user, fetchAllCollectionsForUser, setIsLoading, selectedCollection]);

return () => {
console.log('Private routes no longer available');
};
}, [user]);

// Handle initial loading state
useEffect(() => {
if (!isLoading) {
setIsContextLoading(false);
setIsLoading(false);
}
}, [isLoading, setIsContextLoading]);

useEffect(() => {
const timer = setTimeout(() => {
setIsContextLoading(false);
}, 5500);
return () => clearTimeout(timer);
}, [setIsContextLoading]);

useEffect(() => {
let isMounted = true; // Add a flag to track if the component is mounted
const fetchCollections = async () => {
if (user && isMounted) {
try {
// const response = fet
await fetchAllCollectionsForUser(user.userID);
if (isMounted) {
console.log('Fetched collections because none were present.');
// Update state only if the component is still mounted
console.log('RESPONSE:', isMounted);
// setOfficialCollectionDatasets(response.data);
}
} catch (err) {
console.error('Failed to fetch collections:', err);
}
}
};

fetchCollections();

// Cleanup function to cancel any ongoing tasks when the component unmounts
return () => {
isMounted = false;
};
}, [user, fetchAllCollectionsForUser, allCollections]);
}, [isLoading, setIsLoading]);

return (
<>
<GlobalStyle />
<Helmet>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';
import * as THREE from 'three';
import placeholder from '../assets/images/placeholder.jpeg';
import placeholder from '../images/placeholder.jpeg';

const CardDeckAnimation = () => {
// Initialize the scene, camera, and renderer here
Expand Down
File renamed without changes.
Loading

0 comments on commit 50bc63e

Please sign in to comment.