export default Home; in theses i want to make two types of seraces in the sidebar...one for issues serach and other for judgments serach ....in issues we have to give only folder path
Assistant
It looks like you want to enhance the sidebar in your React application to handle two distinct types of searches: Issues and Judgments. The Issues search will only require a folder path, while the Judgments search will require a search term and optional exclude words.
In your case, you'll need to set up a separate form for each type of search, and accordingly modify the state and submission logic for each search to reflect the user input.
Here’s how you can structure your updates:
Step 1: Modify the Sidebar for Dual Search Fields
You can separate the sidebar into two sections: one for each search type.
Step 2: Update the Home.js component
Make the following changes in your Home component to incorporate searches for both Issues and Judgments:
jsx
User
i want one saerch box in the sidebar ....chnge the funtionality using the two rado buttons one issues one hudgments
Assistant
To simplify your sidebar and keep only one search box with the ability to switch between Issues and Judgments, you'll need to implement a single input field that adjusts its behavior based on which radio button is selected.
Here's how you can achieve this:
Update the Search State: Use a single state for the search term and conditionally format the request based on the selected search type.
Modify the Form Submission: Handle the submission based on the selected search type, adjusting the logic accordingly.
Here's how you can implement this in your Home.js component:
javascript
User
compltee udpadted code
Assistant
Certainly! Below is the complete updated code for the Home.js component that incorporates a single search box in the sidebar to accommodate both Issues and Judgments search types, utilizing radio buttons to switch between them.
javascript
User
no the right part has to be the same ....jus chnges the text serach box fuctionlity in right for issues and judgments .......to diff fuctions for one serach box
Assistant
I understand now that you want to keep the existing right-hand structure intact and modify the functionality of a single search box based on whether the user is searching for "Issues" or "Judgments." The right part of your component will display the results using existing functionality without disruption, while the sidebar only manages the input and search type.
Here's the updated code:
javascript
User
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import './Home.css';
To modify the sidebar in your React component while keeping the right-side content intact, you can create two separate input fields: one for searching with a folder path for "Issues" and another for a filename for "Judgments." The radio buttons will allow users to select which type of search they want to perform, and the search box will dynamically change based on that selection.
Below is the updated code that reflects these changes:
javascript
User
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import './Home.css';
To achieve the desired functionality where the sidebar remains unchanged, but the input box displays different files or handles different data types based on the selected radio button—"Issues" or "Judgments"—we'll adjust the logic responsible for filtering the results displayed in the dropdown based on the selected search type.
Here's your complete code with unchanged sidebar UI but adjusted functions for handling file searches based on the selection:
javascript
User
i wanted when i choose judgement...dispaly ...TYPE A filename to serach ....but if i choose issue ...i want ...Type a iissue to serach
Assistant
To modify your React component so that the placeholder text in the input field changes based on whether the user selects "Issues" or "Judgments," you can simply adjust the placeholder dynamically in the input element based on the searchType state.
Here's how to implement this in the existing code:
javascript
User
in issues i wanted file://192.168.13.30/c$/GGN%20Office%20Repository/001.%20Miscellaneous/ tis kind of path diff from the prev one for judgemnets......so uske liye same wo rhne do ...iske liye path m m ye putra path de dungi kuch append ni krana issues k liye name and path m dungi bs click p open krna h browesr m
Assistant
To accommodate your requirement where the "Issues" search uses a specific file path format (like file://192.168.13.30/...) while keeping the previous structure intact for "Judgments," we'll make the following adjustments:
Change the Expected Format for Issues: For "Issues", the browsing of files will operate directly using paths you provide in the issueFiles array.
Retain Current Functionality for Judgments: "Judgments" will continue to use the existing paths as previously implemented.
Updated Code
Here's the revised code based on your specifications:
javascript
User
file://192.168.13.30/c$/GGN%20Office%20Repository/Administrative%20authority%20cannot%20exercise%20power%20when%20matter%20is%20sub%20judice,%20pending/ i wanted this link ...in issues....i will provde this in path ...dont append anything to it
Assistant
To fulfill your request to have the "Issues" paths directly reflect the links you provide without any modification or appending, we can structure the issueFiles array with your exact path specifications. When users select an issue, they will simply click on the provided filename and it will open directly in the browser using the specified file:// URL.
Here's the revised code, incorporating your direct file paths without any modifications:
Updated Code
javascript
User
wait listen i will give like {
name: 'Miscellaneous',
path: 'file://192.168.2.5/c$/GGN%20Office%20Repository/Administrative%20authority%20cannot%20exercise%20power%20when%20matter%20is%20sub%20judice,%20pending/',
}, this in issues ...so i want when i vjoose the name ..redirect to this link ....nothing need to be append
Assistant
Sure! To accommodate your requirement for the "Issues" section, where clicking an item in the list simply redirects to the exact link you provide without any modifications, we can set up the paths directly in the array without appending or modifying them in any way.
Here’s how you can update the code to reflect the specified structure and behavior for the "Issues" section:
Separate Search Forms: The sidebar now includes two forms based on the selected search type (Issues or Judgments).
handleSubmitIssues and handleSubmitJudgments: Each search type has its own submission function to handle the specific search operation.
State Management: The component dynamically changes inputs and resets related state values based on the selected search type.
Search Logic: Each search type interacts with the back-end accordingly and updates the search results displayed.
With these changes, your sidebar should now correctly allow for searching both issues and judgments as per your requirements!
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import './Home.css';
const ResultCard = ({ result, onAddToLibrary, cardNumber }) => {
// ResultCard remains as it is
};
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 [searchType, setSearchType] = useState('issues'); // State for search type
const navigate = useNavigate();
useEffect(() => {
// This simulates an API call to get filenames, you can adjust it as needed
// const filenames = [ ... ]; // Your filenames data.
}, []);
const handleSearchTypeChange = (event) => {
setSearchType(event.target.value);
setSearchTerm(''); // Clear the search term when toggling search types
setExcludeWords('');
};
const handleSearchSubmit = async (event) => {
event.preventDefault();
if (!searchTerm.trim()) {
setError('Please enter a search term.');
return;
}
setIsLoading(true);
setError(null);
try {
let url = '';
if (searchType === 'issues') {
// Assuming 'folderPath' is being provided for Issues
url = `http://192.168.2.5:3006/search/issues?folderPath=${encodeURIComponent(searchTerm)}`;
} else {
url = `http://192.168.2.5:3006/search/judgments?keyword=${encodeURIComponent(searchTerm)}&exclude=${encodeURIComponent(excludeWords || '')}`;
}
const response = await fetch(url);
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);
}
};
const handleAddToLibrary = async (pdf) => {
// Handle adding to library (unchanged)
};
return (
<div className="app-container">
{/* Sidebar */}
<div className="sidebar">
<div className="sidebar-header">
<h2>S&A Law Offices</h2>
</div>
<div className="sidebar-content">
<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>
<form onSubmit={handleSearchSubmit} className="search-form">
<input
type="text"
placeholder={searchType === 'issues' ? "Enter folder path" : "Enter search term"}
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="sidebar-input"
/>
{searchType === 'judgments' && (
<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 ${searchType.charAt(0).toUpperCase() + searchType.slice(1)}`}
</button>
</form>
{error && <div className="error-message">{error}</div>}
</div>
</div>
{/* Main Content */}
<div className="main-content">
<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}
onAddToLibrary={handleAddToLibrary}
cardNumber={index + 1}
/>
))}
</div>
</>
) : (
<div className="no-results">No results found</div>
)}
</div>
</div>
</div>
);
};
export default Home;
Key Changes in This Implementation
Single Input Box: There is now one input box that shows a placeholder based on the selected radio button (Issues or Judgments). If the user selects "Issues," it will prompt them to enter a folder path, and if "Judgments" is selected, it prompts for a search term.
Dynamic Submission Logic: The form submission handles the request differently based on which search type is selected. The URL and parameters adjust accordingly.
Conditional Exclude Words Input: The input for excluding words only appears when the Judgments search type is selected.
State Management: The state and error handling remain the same but now single out the logic for the input and relevant processing based on the search type.
By following this structure, you'll have a clean interface that allows users to toggle between Issues and Judgments with just one search input box, making the UI more user-friendly.
Search Type Toggle: Uses radio buttons to toggle between Issues and Judgments, dynamically adjusting the input placeholder accordingly.
Single Input Field: There is a single input field for the search term, and an additional input for excluding words that appears only when Judgments is selected.
Dynamic URL Construction: Depending on whether 'Issues' or 'Judgments' is selected, the appropriate API endpoint for fetching search results is constructed.
Result Handling: Displays loading states, results, and error messages appropriately based on the user's interactions.
Now, this code should meet your requirement for a unified search experience while maintaining the necessary logic to handle different types of searches.
Single Search Box: The sidebar contains a single input box that changes its placeholder text based on whether "Issues" or "Judgments" is selected.
Search Submission Logic: The handleSearchSubmit function determines what kind of search to perform based on the selected type. For "Issues," it expects a folder path, while for "Judgments" it expects a keyword and optional excluded words.
Result Display: The right part of the application (main content) remains unchanged and leverages the results fetched from either type of search.
By using this updated code, you maintain a consistent layout while ensuring that the search functionality adapts to the input from the user.
export default Home; make chnges in this in sidebar only not on right side...in sidebar make two fucntions for judments and issues as radio button ...and the serach ox to give diiff data for both...i willl add filename path ....for judgemnts and for issues.....folder ptah
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import './Home.css';
const ResultCard = ({ result, onAddToLibrary, cardNumber }) => {
return (
<div className="result-card">
<div className="result-header">
<h3>
<span className="result-number">{cardNumber}.</span>
<a
href={`http://192.168.2.5:3006/files/${result.relativePath}`}
target="_blank"
rel="noopener noreferrer"
>
{result.Filename.split('\\').pop()}
</a>
</h3>
<button onClick={() => onAddToLibrary(result)} className="add-button">
Add
</button>
</div>
{result.matches.length > 0 ? (
<div className="matches">
{result.matches.map((match, index) => (
<div key={index} className="match-item">
<div>Page {match.page}</div>
<div
className="snippet"
dangerouslySetInnerHTML={{
__html: match.snippet.replace(
new RegExp(`(${match.keyword})`, 'gi'),
'<mark>$1</mark>'
),
}}
/>
</div>
))}
</div>
) : (
<p className="no-matches">No matches found</p>
)}
</div>
);
};
const Home = () => {
const [searchTerm, setSearchTerm] = useState('');
const [folderPath, setFolderPath] = useState(''); // State for folder path input
const [excludeWords, setExcludeWords] = useState('');
const [searchResults, setSearchResults] = useState([]);
const [error, setError] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [searchType, setSearchType] = useState('issues'); // State for search type
const navigate = useNavigate();
// This array can contain your filename data for judgments
const filenames = [
{
name: 'Compilation of Judgments - Claimant',
path: '\\001. Miscellaneous\\51. Section 16 Arbitration Act\\Compilation of Judgments- Claimant.pdf',
},
{
name: 'Xerox Corporation and Ors vs PK Khansaheb and Ors',
path: '\\001. Miscellaneous\\57.Additional documents\\Xerox_Corporation_and_Ors_vs_PK_Khansaheb_and_Ors_DE201819121816353171COM57952.pdf',
},
// Add other filenames here in the same format...
];
const handleSearchTypeChange = (event) => {
setSearchType(event.target.value);
setSearchTerm(''); // Clear the search term when switching types
setFolderPath(''); // Clear folder path when switching to judgments
};
const handleSubmit = async (event) => {
event.preventDefault();
let url = '';
// Check which type of search to perform
if (searchType === 'issues') {
if (!folderPath.trim()) {
setError('Please enter a folder path for Issues.');
return;
}
url = `http://192.168.2.5:3006/search/issues?folderPath=${encodeURIComponent(folderPath)}`;
} else {
if (!searchTerm.trim()) {
setError('Please enter a search term for Judgments.');
return;
}
url = `http://192.168.2.5:3006/search/judgments?keyword=${encodeURIComponent(searchTerm)}&exclude=${encodeURIComponent(excludeWords || '')}`;
}
setIsLoading(true);
setError(null);
try {
const response = await fetch(url);
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);
}
};
const handleAddToLibrary = async (pdf) => {
const token = localStorage.getItem('token');
if (!token) {
navigate('/login', {
state: {
message: 'Please log in to add documents to your library',
redirectAfterLogin: '/home',
},
});
return;
}
try {
const response = await fetch(
'http://192.168.2.5:3006/api/lib/library/add',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
filename: pdf.relativePath,
originalFilePath: pdf.Filename,
}),
}
);
if (response.ok) {
alert('Document added to library');
} else {
const errorData = await response.json();
alert(errorData.message || 'Failed to add document to library');
}
} catch (error) {
console.error('Error adding to library:', error);
alert('Network error. Please try again.');
}
};
return (
<div className="app-container">
{/* Sidebar */}
<div className="sidebar">
<div className="sidebar-header">
<h2>S&A Law Offices</h2>
</div>
<div className="sidebar-content">
<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>
<form onSubmit={handleSubmit} className="search-form">
{searchType === 'issues' ? (
<input
type="text"
placeholder="Enter folder path"
value={folderPath}
onChange={(e) => setFolderPath(e.target.value)}
className="sidebar-input"
/>
) : (
<input
type="text"
placeholder="Enter search term"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="sidebar-input"
/>
)}
{searchType === 'judgments' && (
<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>
</div>
{/* Main Content */}
<div className="main-content">
<div className="search-container">
<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}
onAddToLibrary={handleAddToLibrary}
cardNumber={index + 1}
/>
))}
</div>
</>
) : (
<div className="no-results">No results found</div>
)}
</div>
</div>
</div>
</div>
);
};
export default Home;
Key Changes Made to the Sidebar
Radio Button Selection: You now have a radio button to choose between "Issues" and "Judgments." Switching these will clear existing input fields, ensuring a fresh start for new inputs.
Dynamic Input Fields:
When "Issues" is selected, an input box for the folder path is displayed.
When "Judgments" is selected, an input box for the search term is displayed alongside an optional input for excluding words.
Submission Logic: The handleSubmit method checks which search type is selected and builds the appropriate URL accordingly. It handles the input validation to ensure the necessary fields are filled out before making requests.
Error Handling: Each type of search provides appropriate error messages if the required input is not provided.
This approach maintains the right side of the application unchanged while adjusting the sidebar functionality to cater to your requirements.
export default Home; in this i dont want to chnge any box on left sidebar i just wanted thatthe box will have differnt files after chooosing each button ..issue and judgments...completet cide
The sidebar remains unchanged, but the filtering logic inside handleSearchTypeChange updates the options for file searches based on whether "Issues" or "Judgments" is selected.
I've added an example of issueFiles which you can extend with your specific issue documents. When "Issues" is selected, the dropdown will show these files; otherwise, it will show the general filenames for Judgments.
File Input Handling:
The file input now updates the filtered file list based on the selected radio button. When "Issues" is selected, the dropdown will show issueFiles, and when "Judgments" is selected, it will revert to filenames.
This structure should meet your requirement of having separate file filtering based on the selected search categories while keeping the sidebar's visual structure intact. You can replace the example issue files with your actual file paths and names as needed.
The placeholder text in the sidebar input has been modified to display "Type an issue to search..." when "Issues" is selected and "Type a filename to search..." when "Judgments" is selected.
Here's how the placeholder changes:
javascript
placeholder={searchType === 'issues' ? 'Type an issue to search...' : 'Type a filename to search...'}
Other Functionalities:
The logic for filtering filenames based on selected search parameters was retained.
The input fields’ and dropdown behaviors remain unchanged.
Now, when you choose "Issues," it will prompt you to type an issue, while selecting "Judgments" will prompt you to type a filename. This ensures that the sidebar's UX is aligned with user expectations based on their selection.
For "Issues," I've created an issueFiles array with example paths using the file:// protocol. You can fill this out by adding the files you want users to access when they select "Issues."
Dynamic Placeholders:
The placeholder in the input field changes based on whether "Issues" or "Judgments" is selected.
File Opening:
When a filename is clicked in the dropdown for "Issues," it will directly open the file path specified in the issueFiles array using the href attribute.
This setup should meet your requirements, allowing users to easily navigate both "Judgments" (with previously established paths) and "Issues" (with new specified file paths). Adjust the file paths as needed in the issueFiles array according to your exact directory structure.
Link Handling: In the dropdown for "Issues," clicking on any document now directly opens the specified file:// link in the browser as per your requirement, without any alterations to the paths.
Maintain Judgments Path: The paths for judgments remain unchanged and operate as intended.
This setup ensures that you can provide exact file paths for both Issues and Judgments, with "Issues" specifically formatted as you requested. You can populate the issueFiles array with additional paths or edit existing entries to meet your needs.
Direct Navigation: When a user clicks on an issue document in the dropdown, it will directly use this path as the href, opening it in the browser without any alteration.
Dynamic Messaging: The input field will display the appropriate placeholder message based on whether "Issues" or "Judgments" is selected.
This setup meets your requirement for directly opening the specified URLs when the relevant item is clicked under the "Issues" checkbox. You can add as many specific paths as needed in the issueFiles array following this structure.