Skip to content

Commit

Permalink
error for spot, also css fix for nav mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmst committed Jun 6, 2024
1 parent a59f0fc commit 50b833c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/app/components/HeroSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,35 @@ import { fetchSpotData } from '../../data/fetchSpotData';

const HeroSection = ({ path, interviews, isError }) => {
const [text, setText] = useState('');
const [saveData, setSaveData] = useState(false);
const [saveData, setSaveData] = useState(true);
const [results, setResults] = useState(null);
const [error, setError] = useState('');
const [validationError, setValidationError] = useState('');

const handleInputChange = (event) => {
setText(event.target.value);
if (validationError) setValidationError('');
};

const handleCheckboxChange = () => {
setSaveData(!saveData);
};

const handleFindHelpClick = async () => {
if (text.length < 6) {
setValidationError(
'Please enter at least 6 characters to perform a search.'
);
return;
}

try {
const data = { text: text, save_data: saveData ? 1 : 0 };
const fetchedResults = await fetchSpotData(data);
setResults(fetchedResults);
setError('');
// Manage display of topic cards when spot search is used. dom manipulation is used to keep Page components server components
const topicCards = document.querySelectorAll('.topic-card-parent');
console.log(topicCards);
topicCards.forEach((card) => {
card.classList.add('hidden');
});
Expand Down Expand Up @@ -74,11 +82,13 @@ const HeroSection = ({ path, interviews, isError }) => {
Use my reply to help others
</label>
</div>

<Button onClick={handleFindHelpClick} className="hero-button">
Find help
</Button>
</div>
{validationError && (
<p className="text-danger">{validationError}</p>
)}
{error && (
<p className="text-danger">Error. Please try again later.</p>
)}
Expand Down
5 changes: 4 additions & 1 deletion src/app/components/SpotResultsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const SpotResultsContainer = ({ data, interviews, path }) => {
...label,
topic: legalTopics.find((t) => t.codes.includes(label.id)),
}))
.filter(({ topic }) => topic) // Ensure the topic exists
.filter(
({ topic }) =>
topic && interviews[topic.name] && interviews[topic.name].length > 0
) // Ensure the topic exists and has available interviews
.sort((a, b) => b.pred - a.pred) // Sort by confidence score
.map(({ topic }) => topic); // Extract sorted topics

Expand Down
2 changes: 2 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ footer {
}

.courtformsonline-navbar .nav-link {
padding: 1rem;
background-color: #002e60;
color: white;
margin-right: 2em;
}
Expand Down

0 comments on commit 50b833c

Please sign in to comment.