diff --git a/.gitignore b/.gitignore index 8989e62..a0a1afe 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,6 @@ yarn-error.log* .env.production.local # Firebase cache -.firebase/ \ No newline at end of file +.firebase/ + +.vscode/launch.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index cdd89c6..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "chrome", - "request": "launch", - "name": "Launch Chrome against localhost", - "url": "http://localhost:3000", - "webRoot": "${workspaceFolder}" - - } - ] -} \ No newline at end of file diff --git a/app/components/Dashboard.js b/app/components/Dashboard.js index f3303b0..2d4f82f 100644 --- a/app/components/Dashboard.js +++ b/app/components/Dashboard.js @@ -40,17 +40,16 @@ const Dashboard = () => { // }, [formattedMatches]) // Fuzzy search - const fuse = useMemo( - () => - new Fuse(formattedMatches, { - keys: searchableProperties, - threshold: 0.3 - }), - [formattedMatches] - ) + const fuse = useMemo(() => { + if (!formattedMatches.length) return null + return new Fuse(formattedMatches, { + keys: searchableProperties, + threshold: 0.3 + }) + }, [formattedMatches]) const filteredMatchSets = useMemo(() => { - if (!searchTerm) return [] + if (!searchTerm || !fuse) return [] const result = fuse.search(searchTerm).map((result) => { const match = result.item return `${match.matchDate}#${match.teams.opponentTeam}` diff --git a/app/components/DataProvider.js b/app/components/DataProvider.js index a1bea67..f08e08f 100644 --- a/app/components/DataProvider.js +++ b/app/components/DataProvider.js @@ -89,28 +89,24 @@ export const DataProvider = ({ children }) => { [fetchMatches, matches] ) - const createMatch = useCallback( - async (collectionName, newMatchData) => { - try { - const newMatch = { - id: 'temp-id', - collection: collectionName, - ...newMatchData - } - - setMatches((prevMatches) => [...prevMatches, newMatch]) - - const colRef = collection(db, collectionName) - await addDoc(colRef, newMatchData) - - await fetchMatches() - } catch (err) { - setError(err) - console.error('Error creating new match:', err) + const createMatch = useCallback(async (collectionName, newMatchData) => { + try { + const newMatch = { + id: 'temp-id', + collection: collectionName, + ...newMatchData } - }, - [fetchMatches] - ) + setMatches((prevMatches) => [...prevMatches, newMatch]) + + // Actual Firestore addition + const colRef = collection(db, collectionName) + await addDoc(colRef, newMatchData) + await fetchMatches() + } catch (err) { + setError(err) + console.error('Error creating new match:', err) + } + }, []) const fetchLogos = useCallback(async () => { const storedLogos = localStorage.getItem('teamLogos') @@ -172,9 +168,6 @@ export const useData = () => { const { matches, logos, loading, error, refresh, updateMatch, createMatch } = context - useEffect(() => { - refresh() - }, [refresh]) - + // Optionally keep `refresh` available for manual use in components return { matches, logos, loading, error, refresh, updateMatch, createMatch } }