diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6a3095a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version: '18.16.0' + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test + + - name: Build + run: npm run build + + - name: Install Netlify CLI + run: npm install netlify-cli -g + + - name: Deploy to Netlify + run: npx netlify deploy --dir=src --prod + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} diff --git a/package.json b/package.json index 15f8115..576afc4 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/src/App.js b/src/App.js index bfc7c23..2f136d0 100644 --- a/src/App.js +++ b/src/App.js @@ -1,13 +1,12 @@ // External Imports -import React, { useEffect, useState } from 'react'; +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'; @@ -17,104 +16,72 @@ 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'; +import { useDeckStore } from './context/DeckContext/DeckContext'; +import { useCartStore } from './context/CartContext/CartContext'; +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 */ -`; - -// Custom Hook for Cron Job -const useCronJob = (lastCronJobTriggerTime, setLastCronJobTriggerTime) => { - const { - cronData, - handleSendAllCardsInCollections, - listOfMonitoredCards, - handleRetreiveListOfMonitoredCards, - retrievedListOfMonitoredCards, - allCollectionsUpdated, - } = useCombinedContext(); + const user = cookies.user; + const [currentPage, setCurrentPage] = useState(''); + // const { setContext } = useAppContext(); // Assuming useAppContext provides setContext + const { fetchAllCollectionsForUser, selectedCollection } = + useCollectionStore(); + const { allDecks, fetchAllDecksForUser, selectedDeck } = useDeckStore(); + const { fetchUserCart, cartData } = useCartStore(); + const { isLoading, setIsLoading } = useUtilityContext(); - const { user } = useUserContext(); - const userId = user?.userID; + // const { getRandomCardImages } = useCardImages(); // Add this line - useEffect(() => { - setLastCronJobTriggerTime(new Date().getTime()); - }, [setLastCronJobTriggerTime]); + // useEffect(() => { + // getRandomCardImages(10); // Fetch 10 random images on app start + // }, []); // Add this useEffect useEffect(() => { - const handleTriggerCronJob = () => { - const currentTime = new Date().getTime(); - if (currentTime - lastCronJobTriggerTime >= 60000) { - setLastCronJobTriggerTime(currentTime); - if (userId && listOfMonitoredCards && retrievedListOfMonitoredCards) { - handleSendAllCardsInCollections( - userId, - listOfMonitoredCards, - retrievedListOfMonitoredCards - ); - console.log('SENDING ALL CARDS IN COLLECTIONS'); - } else if (userId && listOfMonitoredCards) { - console.log('RETRIEVING LIST OF MONITORED CARDS'); - handleSendAllCardsInCollections( - userId, - listOfMonitoredCards, - handleRetreiveListOfMonitoredCards() - ); - console.log('Triggered the cron job.'); - } - } - }; - - const interval = setInterval(handleTriggerCronJob, 60000); - return () => clearInterval(interval); - }, [ - cronData, - lastCronJobTriggerTime, - allCollectionsUpdated, - handleRetreiveListOfMonitoredCards, - handleSendAllCardsInCollections, - listOfMonitoredCards, - retrievedListOfMonitoredCards, - userId, - ]); -}; - -// Main Component -const App = () => { - const [lastCronJobTriggerTime, setLastCronJobTriggerTime] = useState(null); - const { isLoading, setIsContextLoading } = useUtilityContext(); - + if (user) { + fetchAllCollectionsForUser() + .then(() => { + setIsLoading(false); + }) + .catch((error) => { + console.error('Error fetching collections:', error); + setIsLoading(false); + }); + } + }, [user, fetchAllCollectionsForUser, setIsLoading, selectedCollection]); + // useEffect(() => { + // if (user) { + // fetchAllDecksForUser(user?.id).catch((err) => + // console.error('Failed to get all decks:', err) + // ); + // } + // }, [fetchAllDecksForUser]); + // useEffect(() => { + // if (user) { + // fetchUserCart(user?.id).catch((err) => + // console.error('Failed to get cart:', err) + // ); + // } + // }, [fetchUserCart]); + + // Handle initial loading state useEffect(() => { if (!isLoading) { - setIsContextLoading(false); + setIsLoading(false); } - }, [isLoading, setIsContextLoading]); - - useEffect(() => { - const timer = setTimeout(() => { - setIsContextLoading(false); - }, 5500); - return () => clearTimeout(timer); - }, [setIsContextLoading]); - - useCronJob(lastCronJobTriggerTime, setLastCronJobTriggerTime); + }, [isLoading, setIsLoading]); return ( <> - { {isLoading ? ( ) : ( - +
+ {/* {setCurrentPage(useLocation())} */} + } /> } /> } /> @@ -176,7 +145,7 @@ const App = () => {