import React, { useState, useEffect } from 'react'; import { useNavigate } from…
- User
import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import ResultCard from '../components/Resultcard'; // Ensure the path is correct import './Home.css';
const Home = () => { const [searchTerm, setSearchTerm] = useState(''); const [excludeWords, setExcludeWords] = useState(''); const [searchResults, setSearchResults] = useState([]); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const [filteredFilenames, setFilteredFilenames] = useState([]); const [fileInput, setFileInput] = useState(''); const [searchType, setSearchType] = useState('issues'); const navigate = useNavigate();
const filenames = [ { "name": "001. Miscellaneous", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/001. Miscellaneous" }, { "name": "19(4), arbitration act - Admissibility, relevancy, materiality", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/19(4), arbitration act - Admissibility, relevancy, materiality" }, { "name": "001. Miscellaneous", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/001. Miscellaneous" }, { "name": "19(4), arbitration act - Admissibility, relevancy, materiality", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/19(4), arbitration act - Admissibility, relevancy, materiality" }, { "name": "001. Miscellaneous", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/001. Miscellaneous" }, { "name": "19(4), arbitration act - Admissibility, relevancy, materiality", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/19(4), arbitration act - Admissibility, relevancy, materiality" }, ] const issueFiles = [ { "name": "001. Miscellaneous", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/001. Miscellaneous" }, { "name": "19(4), arbitration act - Admissibility, relevancy, materiality", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/19(4), arbitration act - Admissibility, relevancy, materiality" }, { "name": "001. Miscellaneous", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/001. Miscellaneous" }, { "name": "19(4), arbitration act - Admissibility, relevancy, materiality", "path": "file://192.168.13.30/c$//192.168.13.30/c$/GGN Office Repository/19(4), arbitration act - Admissibility, relevancy, materiality" }, ] useEffect(() => { setFilteredFilenames(searchType === 'issues' ? issueFiles : filenames); }, [searchType]); const handleSearchTypeChange = (event) => { const value = event.target.value; setSearchType(value); setFileInput(''); setFilteredFilenames(value === 'issues' ? issueFiles : filenames); }; const handleFileInputChange = (event) => { const value = event.target.value; setFileInput(value); if (value) { setFilteredFilenames( (searchType === 'issues' ? issueFiles : filenames).filter((file) => file.name.toLowerCase().includes(value.toLowerCase()) ) ); } else { setFilteredFilenames(searchType === 'issues' ? issueFiles : filenames); } }; const handleSubmit = async (event) => { event.preventDefault(); if (!searchTerm.trim()) { setError('Please enter a search term.'); return; } setIsLoading(true); setError(null); try { const response = await fetch( `http://192.168.2.5:3006/search?keyword=${encodeURIComponent(searchTerm)}&exclude=${encodeURIComponent( excludeWords || '' )}&type=${encodeURIComponent(searchType)}` ); if (!response.ok) throw new Error('Failed to fetch search results'); const data = await response.json(); setSearchResults(data); } catch (error) { console.error(error); setError('Error fetching search results.'); } finally { setIsLoading(false); } }; return ( <div className="app-container"> <div className="sidebar"> <div className="sidebar-header"> <h2>S&A Law Offices</h2> </div> <div className="sidebar-content"> <div className="dropdown"> <input type="text" placeholder={searchType === 'issues' ? 'Type an issue to search...' : 'Type a filename to search...'} value={fileInput} onChange={handleFileInputChange} className="sidebar-input" /> <div className="search-type"> <label> <input type="radio" value="issues" checked={searchType === 'issues'} onChange={handleSearchTypeChange} /> Issues </label> <label> <input type="radio" value="judgments" checked={searchType === 'judgments'} onChange={handleSearchTypeChange} /> Judgments </label> </div> {fileInput && ( <div className="dropdown-content show"> {filteredFilenames.length > 0 ? ( filteredFilenames.map((file, index) => ( <a key={index} href={file.path} target="_blank" rel="noopener noreferrer" className="suggestion-item" > {file.name} </a> )) ) : ( <div className="no-suggestions">No matches found</div> )} </div> )} </div> </div> </div> <div className="main-content"> <div className="search-container"> <form onSubmit={handleSubmit} className="search-form"> <input type="text" placeholder="Enter search term" value={searchTerm} onChange={(e) => setSearchTerm(e.target.value)} className="search-input" /> <input type="text" placeholder="Exclude words (optional)" value={excludeWords} onChange={(e) => setExcludeWords(e.target.value)} className="search-input" /> <button type="submit" disabled={isLoading} className="search-button"> {isLoading ? 'Searching...' : 'Search'} </button> </form> {error && <div className="error-message">{error}</div>} <div className="results-section"> {isLoading ? ( <div className="loading">Loading...</div> ) : searchResults.length > 0 ? ( <> <div className="results-count">Found {searchResults.length} documents</div> <div className="results-list"> {searchResults.map((result, index) => ( <ResultCard key={index} result={result} cardNumber={index + 1} searchType={searchType} /> ))} </div> </> ) : ( <div className="no-results">No results found</div> )} </div> </div> </div> </div> );};
export default Home;
in this in sidebar add some css to make tje dropdown lis look good and add scrol feature ..responsivr also
- Assistant
To enhance the visual appearance of your dropdown list in the sidebar and make it look good while also implementing a scroll feature, you can follow these guidelines.
We'll modify your CSS file (
Home.css) to add styles specifically for the dropdown. Here's how you can do it:Updated CSS for Dropdown
Below are some sample styles you can apply to your dropdown and other related elements. Modify these styles as necessary to fit your application's design:
/* Home.css */ /* Container styles */ .app-container { display: flex; height: 100vh; } /* Sidebar styles */ .sidebar { width: 250px; /* set a fixed width for the sidebar */ background-color: #f7f7f7; /* light background color */ border-right: 1px solid #ddd; /* border to separate from main content */ padding: 20px; position: relative; /* for positioning dropdown */ } /* Sidebar header styles */ .sidebar-header { margin-bottom: 20px; } /* Input styles */ .sidebar-input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; /* rounded corners */ margin-bottom: 10px; } /* Dropdown styles */ .dropdown { position: relative; /* positioning for absolute dropdown */ } /* Dropdown content styles */ .dropdown-content { position: absolute; left: 0; right: 0; max-height: 150px; /* limit dropdown height */ overflow-y: auto; /* enable vertical scrolling */ background-color: #fff; /* white background */ border: 1px solid #ccc; /* border around dropdown */ border-radius: 4px; /* rounded corners */ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* subtle shadow */ z-index: 1000; /* ensure it appears on top */ display: none; /* hide by default */ } /* Show dropdown content when there are matches */ .dropdown-content.show { display: block; /* show dropdown */ } /* Individual suggestion styles */ .suggestion-item { padding: 10px; /* padding inside suggestion item */ text-decoration: none; /* remove underline from links */ color: #333; /* text color */ display: block; /* display block for full width */ } /* Hover effect on suggestion items */ .suggestion-item:hover { background-color: #f0f0f0; /* light gray on hover */ } /* No suggestion message styles */ .no-suggestions { padding: 10px; /* padding for no suggestions */ color: #888; /* gray color */ } /* Main content styles */ .main-content { padding: 20px; /* padding around main content */ flex-grow: 1; /* take remaining space */ } /* Other styles you may already have... */Explanation of CSS Changes
- Max-height and Overflow: The
max-heightproperty limits how tall the dropdown can get, whileoverflow-y: autoallows for scrolling if the content exceeds that height. - Positioning: The dropdown content is positioned absolutely, allowing it to overlay other content when it is shown.
- Z-Index: A higher
z-indexensures that the dropdown stays above other elements. - Styling: Added some basic styling for the input and dropdown items to improve aesthetics. You can customize colors, shadows, and borders as needed.
- Hover Effect: A hover effect is added for the dropdown items to improve user experience.
Responsive Considerations
Remember to test the dropdown on various screen sizes. You may want to use media queries to adjust padding, font sizes, or other styles for mobile views. For example:
@media (max-width: 768px) { .sidebar { width: 100%; /* full width on smaller screens */ position: relative; /* for repositioning on small screens */ } .search-input, .sidebar-input { width: calc(100% - 20px); /* full width inputs */ } }With these styles, the dropdown in your sidebar should look more polished and functional. Adjust the styles as needed to perfectly fit your application design and user experience expectations.
- Max-height and Overflow: The
- User
Line 10210:39: 'handleFileInputChange' is not defined no-undef Line 10219:47: 'handleSearchTypeChange' is not defined no-undef Line 10228:47: 'handleSearchTypeChange' is not defined no-undef
- Assistant
The errors you are encountering indicate that the functions
handleFileInputChangeandhandleSearchTypeChangeare not being recognized in the current context of your JSX, specifically in theinputelements of your dropdown and radio buttons. This is commonly due to either a scoping issue or a misconfiguration in the component.Here's what you need to check and adjust in your code:
1. Ensure Proper Function Declaration
Make sure that
handleFileInputChangeandhandleSearchTypeChangeare defined within the same component where you're trying to use them. Based on your code snippet, they seem to already be correctly defined, so the problem might stem from where you are using them.2. Check for Typos
Ensure that you have not mistakenly altered the names of these functions when referencing them in your JSX. They should match exactly as defined:
<input type="text" placeholder={searchType === 'issues' ? 'Type an issue to search...' : 'Type a filename to search...'} value={fileInput} onChange={handleFileInputChange} // Make sure this matches the function name exactly className="sidebar-input" /> <div className="search-type"> <label> <input type="radio" value="issues" checked={searchType === 'issues'} onChange={handleSearchTypeChange} // Make sure this matches the function name exactly /> Issues </label> <label> <input type="radio" value="judgments" checked={searchType === 'judgments'} onChange={handleSearchTypeChange} // Make sure this matches the function name exactly /> Judgments </label> </div>3. Ensure No Conditional Rendering Is Preventing the Functions
If for any reason these function calls are wrapped in conditional rendering (like being displayed only when a certain condition is true), ensure that those conditions aren't preventing them from being recognized.
4. Linter Configuration
Sometimes, ESLint might not recognize the functions if the linter configuration is incorrect or if there's a caching issue. You can try restarting your development server, clearing any cache, or checking your linter setup.
Final Example
Just to show you how it should generally look, ensure your component is structured like this:
return ( <div className="sidebar-content"> <div className="dropdown"> <input type="text" placeholder={searchType === 'issues' ? 'Type an issue to search...' : 'Type a filename to search...'} value={fileInput} onChange={handleFileInputChange} // Make sure this references the right function className="sidebar-input" /> <div className="search-type"> <label> <input type="radio" value="issues" checked={searchType === 'issues'} onChange={handleSearchTypeChange} // Make sure this references the right function /> Issues </label> <label> <input type="radio" value="judgments" checked={searchType === 'judgments'} onChange={handleSearchTypeChange} // Make sure this references the right function /> Judgments </label> </div> {fileInput && ( <div className="dropdown-content show"> {filteredFilenames.length > 0 ? ( filteredFilenames.map((file, index) => ( <a key={index} href={file.path} target="_blank" rel="noopener noreferrer" className="suggestion-item" > {file.name} </a> )) ) : ( <div className="no-suggestions">No matches found</div> )} </div> )} </div> </div> );Summary
- Ensure the functions are defined within the correct scope.
- Check for any typos in function names in the
onChangeprops. - Make sure there aren't any conditional renders preventing access to those functions.
- Restart your development server or clear any linter cache if necessary.
If you've checked these and are still having issues, consider offering more context or additional code where the functions are defined and used. This will help identify the specific cause of the linting errors.