shortening placeholder text
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 12s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 50s
Build and Push Docker Images / Build Pipeline (Meltano + dbt + Airflow) (push) Successful in 12s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 0s

This commit is contained in:
Tudor Sitaru
2026-04-07 16:17:56 +01:00
parent a562f408d2
commit ce46db7dbe
3 changed files with 148 additions and 83 deletions
+22 -19
View File
@@ -3,15 +3,15 @@
* Modal for searching and adding schools to comparison
*/
'use client';
"use client";
import { useState, useMemo } from 'react';
import { Modal } from './Modal';
import { useComparison } from '@/hooks/useComparison';
import { debounce } from '@/lib/utils';
import { fetchSchools } from '@/lib/api';
import type { School } from '@/lib/types';
import styles from './SchoolSearchModal.module.css';
import { useState, useMemo } from "react";
import { Modal } from "./Modal";
import { useComparison } from "@/hooks/useComparison";
import { debounce } from "@/lib/utils";
import { fetchSchools } from "@/lib/api";
import type { School } from "@/lib/types";
import styles from "./SchoolSearchModal.module.css";
interface SchoolSearchModalProps {
isOpen: boolean;
@@ -20,7 +20,7 @@ interface SchoolSearchModalProps {
export function SchoolSearchModal({ isOpen, onClose }: SchoolSearchModalProps) {
const { addSchool, selectedSchools, canAddMore } = useComparison();
const [searchTerm, setSearchTerm] = useState('');
const [searchTerm, setSearchTerm] = useState("");
const [results, setResults] = useState<School[]>([]);
const [isSearching, setIsSearching] = useState(false);
const [hasSearched, setHasSearched] = useState(false);
@@ -37,17 +37,20 @@ export function SchoolSearchModal({ isOpen, onClose }: SchoolSearchModalProps) {
setIsSearching(true);
try {
const data = await fetchSchools({ search: term, page_size: 10 }, { cache: 'no-store' });
const data = await fetchSchools(
{ search: term, page_size: 10 },
{ cache: "no-store" },
);
setResults(data.schools || []);
setHasSearched(true);
} catch (error) {
console.error('Search failed:', error);
console.error("Search failed:", error);
setResults([]);
} finally {
setIsSearching(false);
}
}, 300),
[]
[],
);
const handleSearchChange = (value: string) => {
@@ -65,7 +68,7 @@ export function SchoolSearchModal({ isOpen, onClose }: SchoolSearchModalProps) {
};
const handleClose = () => {
setSearchTerm('');
setSearchTerm("");
setResults([]);
setHasSearched(false);
onClose();
@@ -88,7 +91,7 @@ export function SchoolSearchModal({ isOpen, onClose }: SchoolSearchModalProps) {
type="text"
value={searchTerm}
onChange={(e) => handleSearchChange(e.target.value)}
placeholder="Search by school name or location..."
placeholder="Search by school or postcode ..."
className={styles.searchInput}
autoFocus
/>
@@ -114,17 +117,17 @@ export function SchoolSearchModal({ isOpen, onClose }: SchoolSearchModalProps) {
{school.local_authority && (
<span>{school.local_authority}</span>
)}
{school.school_type && (
<span>{school.school_type}</span>
)}
{school.school_type && <span>{school.school_type}</span>}
</div>
</div>
<button
onClick={() => handleAddSchool(school)}
disabled={alreadySelected || !canAddMore}
className={alreadySelected ? 'btn btn-active' : 'btn btn-secondary'}
className={
alreadySelected ? "btn btn-active" : "btn btn-secondary"
}
>
{alreadySelected ? '✓ Comparing' : '+ Compare'}
{alreadySelected ? "✓ Comparing" : "+ Compare"}
</button>
</div>
);