diff --git a/app/AuthWrapper.js b/app/AuthWrapper.js index 5089b1e..7cb1a87 100644 --- a/app/AuthWrapper.js +++ b/app/AuthWrapper.js @@ -11,7 +11,7 @@ import { onAuthStateChanged, signOut } from 'firebase/auth' import { auth } from '@/app/services/initializeFirebase' import { getUserProfile } from '@/app/services/userInfo' import LandingPage from '@/app/components/LandingPage' - +import Loading from './components/Loading' const AuthContext = createContext() export const AuthProvider = ({ children }) => { @@ -37,7 +37,11 @@ export const AuthProvider = ({ children }) => { const memoizedUserProfile = useMemo(() => userProfile, [userProfile]) if (loading) { - return
Loading...
+ return ( +
+ +
+ ) } const handleSignOut = () => { diff --git a/app/DataProvider.js b/app/DataProvider.js index 6bd7204..1b2be2b 100644 --- a/app/DataProvider.js +++ b/app/DataProvider.js @@ -7,8 +7,9 @@ import React, { useContext } from 'react' import { collection, getDocs, doc, updateDoc, addDoc } from 'firebase/firestore' +import { ref, uploadBytes, getDownloadURL } from 'firebase/storage' -import { db } from '@/app/services/initializeFirebase.js' +import { db, storage } from '@/app/services/initializeFirebase.js' import { useAuth } from '@/app/AuthWrapper.js' import getTeams from '@/app/services/getTeams.js' @@ -92,6 +93,23 @@ export const DataProvider = ({ children }) => { const createMatch = useCallback(async (collectionName, newMatchData) => { try { + let pdfUrl = null + if (newMatchData.pdfFile) { + const pdfRef = ref(storage, `match-pdfs/${newMatchData.pdfFile.name}`) + const metadata = { + contentType: 'application/pdf' + } + + const snapshot = await uploadBytes( + pdfRef, + newMatchData.pdfFile.blob, + metadata + ) + pdfUrl = await getDownloadURL(snapshot.ref) + } + console.log(pdfUrl) + newMatchData.pdfFile = pdfUrl + const newMatch = { id: 'temp-id', collection: collectionName, diff --git a/app/components/Dashboard.js b/app/components/Dashboard.js index d55c06e..8708242 100644 --- a/app/components/Dashboard.js +++ b/app/components/Dashboard.js @@ -10,6 +10,7 @@ import styles from '@/app/styles/Dashboard.module.css' import DashTileContainer from '@/app/components/DashTileContainer' // import getTeams from '@/app/services/getTeams.js' import RosterList from '@/app/components/RosterList.js' +import Loading from './Loading' import { searchableProperties } from '@/app/services/searchableProperties.js' import SearchIcon from '@/public/search' @@ -25,18 +26,12 @@ const Dashboard = () => { const { matches, logos } = useData() const [searchTerm, setSearchTerm] = useState('') const [selectedMatchSets, setSelectedMatchSets] = useState([]) - console.log(matches) + + console.log('matches', matches) + console.log(matches.length) const formattedMatches = formatMatches(matches) console.log(formattedMatches) - // default show latest match: TODO BUG causes infinite re-rendering - // useEffect(() => { - // if (formattedMatches.length > 0) { - // const latestMatchKey = `${formattedMatches[0].matchDate}#${formattedMatches[0].teams.opponentTeam}` - // setSelectedMatchSets([latestMatchKey]) - // } - // }, [formattedMatches]) - // Fuzzy search const fuse = useMemo(() => { if (!formattedMatches.length) return null @@ -75,7 +70,24 @@ const Dashboard = () => { ) } - const displayMatchSets = searchTerm ? filteredMatchSets : selectedMatchSets + // A: Search Results + // B: Carousel Results + // Default: All + const displayMatchSets = useMemo(() => { + if (searchTerm) return filteredMatchSets + if (selectedMatchSets.length > 0) return selectedMatchSets + + // fetch all, arr(set(matches)) + return [ + ...new Set( + formattedMatches.map((match) => + match.matchDetails.duel + ? `${match.matchDate}#${match.teams.opponentTeam}` + : `_#${match.matchDetails.event}` + ) + ) + ] + }, [searchTerm, filteredMatchSets, selectedMatchSets, formattedMatches]) return (
@@ -111,7 +123,11 @@ const Dashboard = () => {
{formattedMatches.map((match, index) => { - const matchKey = `${match.matchDate}#${match.teams.opponentTeam}` + let matchKey = `${match.matchDate}#${match.teams.opponentTeam}` + if (!match.matchDetails.duel) { + console.log('EVENT') + matchKey = `_#${match.matchDetails.event}` + } return (
{
- {displayMatchSets.map((matchKey, index) => { - const singlesMatches = formattedMatches.filter( - (match) => - match.singles && - matchKey === `${match.matchDate}#${match.teams.opponentTeam}` - ) - const doublesMatches = formattedMatches.filter( - (match) => - !match.singles && - matchKey === `${match.matchDate}#${match.teams.opponentTeam}` - ) - const [matchDate, matchName] = matchKey.split('#') - return ( -
-
-
-

{`v ${matchName}`}

- {matchDate} + {matches.length === 0 ? ( + + ) : ( + displayMatchSets.map((matchKey, index) => { + const singlesMatches = formattedMatches.filter( + (match) => + match.singles && + ((match.matchDetails.duel && + matchKey === + `${match.matchDate}#${match.teams.opponentTeam}`) || + (!match.matchDetails.duel && + matchKey === `_#${match.matchDetails.event}`)) + ) + const doublesMatches = formattedMatches.filter( + (match) => + !match.singles && + ((match.matchDetails.duel && + matchKey === + `${match.matchDate}#${match.teams.opponentTeam}`) || + (!match.matchDetails.duel && + matchKey === `_#${match.matchDetails.event}`)) + ) + const [matchDate, matchName] = matchKey.split('#') + + return ( +
+
+
+

{matchName}

+ {matchDate} +
+ +
- -
-
- ) - })} + ) + }) + )}
diff --git a/app/components/Loading.js b/app/components/Loading.js new file mode 100644 index 0000000..17fa887 --- /dev/null +++ b/app/components/Loading.js @@ -0,0 +1,30 @@ +import styles from '@/app/styles/Loading.module.css' + +export default function Loading({ prompt }) { + return ( +
+ + + + {prompt} + + +
+ ) +} diff --git a/app/matches/[slug]/page.js b/app/matches/[slug]/page.js index deb8421..d50751a 100644 --- a/app/matches/[slug]/page.js +++ b/app/matches/[slug]/page.js @@ -215,7 +215,7 @@ const MatchPage = () => { player2TieScores={matchData.pointsJson.map( (point) => point.player2TiebreakScore )} - isUnfinished={matchData.matchDetails.status === 'unfinished'} + isUnfinished={matchData.matchDetails.unfinished} displaySections={{ score: true, info: true, matchup: true }} />
@@ -399,7 +399,7 @@ const MatchPage = () => { player2TieScores={matchData.pointsJson.map( (point) => point.player2TiebreakScore )} - isUnfinished={matchData.matchDetails.status === 'unfinished'} + isUnfinished={matchData.matchDetails.unfinished} displaySections={{ score: true, info: true, matchup: true }} />
@@ -429,7 +429,7 @@ const MatchPage = () => { {showPDF ? (