-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,719 additions
and
17,199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
// components/SearchDropdown.js | ||
import React, { useState, useEffect } from 'react'; | ||
import Select from 'react-select'; | ||
import { collection, getDocs } from 'firebase/firestore'; | ||
import db from '../services/initializeFirebase.js'; | ||
|
||
import React, { useState } from 'react'; | ||
|
||
const SearchDropdown = () => { | ||
const SearchDropdown = ({ setMatchData }) => { | ||
const [searchTerm, setSearchTerm] = useState(''); | ||
const [dropdownData, setDropdownData] = useState([]); | ||
|
||
// Fetch the matches from the database and format them for the dropdown | ||
useEffect(() => { | ||
const fetchMatches = async () => { | ||
const querySnapshot = await getDocs(collection(db, 'matches')); | ||
const matches = querySnapshot.docs.map((doc) => doc.data()); | ||
setDropdownData(formatOptions(matches)); | ||
}; | ||
|
||
fetchMatches(); | ||
}, []); | ||
|
||
const handleSearchChange = (newValue) => { | ||
if (newValue) { | ||
setSearchTerm(newValue); | ||
} | ||
}; | ||
|
||
const handleDropdownItemClick = (selectedOption) => { | ||
setMatchData(selectedOption.value); | ||
setSearchTerm(selectedOption); | ||
}; | ||
|
||
const handleSearchChange = (event) => { | ||
setSearchTerm(event.target.value); | ||
// You can add logic to fetch or filter videos based on the search term. | ||
const formatOptions = (data) => { | ||
return data.map((item) => ({ | ||
value: item, | ||
label: item.name | ||
})); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<input | ||
type="text" | ||
placeholder="Search for a tennis match..." | ||
value={searchTerm} | ||
onChange={handleSearchChange} | ||
<Select | ||
placeholder="Search for a tennis match..." | ||
value={searchTerm} | ||
onChange={handleDropdownItemClick} | ||
options={dropdownData} | ||
onInputChange={handleSearchChange} | ||
/> | ||
{/* Dropdown or suggestion list to show search results */} | ||
</div> | ||
); | ||
} | ||
|
||
export default SearchDropdown; | ||
export default SearchDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.