CourseKitFrontend
useRoomSearch
Search for rooms by capacity, building, campus, and availability
Overview
useRoomSearch provides a search function for finding rooms that match specific criteria.
import { useRoomSearch } from '@hfu.digital/coursekit-react';Usage
function RoomFinder() {
const { rooms, loading, error, search } = useRoomSearch();
const handleSearch = async () => {
await search({
minCapacity: 50,
building: 'Main Building',
availableAt: { start: '2026-03-02T09:00:00', end: '2026-03-02T10:30:00' },
});
};
return (
<div>
<button onClick={handleSearch} disabled={loading}>Find Rooms</button>
{rooms.map(room => (
<div key={room.id}>
{room.name} — {room.building} (capacity: {room.capacity})
</div>
))}
</div>
);
}You can also pass an initial query to trigger a search on mount:
const { rooms, loading } = useRoomSearch({ minCapacity: 30 });RoomSearchQuery
interface RoomSearchQuery {
building?: string;
campus?: string;
minCapacity?: number;
availableAt?: { start: string; end: string };
}All fields are optional. When availableAt is provided, only rooms that are free during that time window are returned.
RoomResult
interface RoomResult {
id: string;
name: string;
building: string | null;
campus: string | null;
capacity: number;
tags: Record<string, unknown> | null;
}UseRoomSearchResult
interface UseRoomSearchResult {
rooms: RoomResult[];
loading: boolean;
error: Error | null;
search: (query: RoomSearchQuery) => Promise<void>;
}| Field | Type | Description |
|---|---|---|
rooms | RoomResult[] | Matching rooms (empty until search is called) |
loading | boolean | true while the search is in flight |
error | Error | null | The error if the search failed |
search | function | Trigger a new search |
API Endpoint
The hook calls:
GET {apiUrl}/rooms?building=...&campus=...&minCapacity=...&availableStart=...&availableEnd=...