Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

import { useEffect, useState } from "react";

interface Advocate {
id: number;
firstName: string;
lastName: string;
city: string;
degree: string;
specialties: string[];
yearsOfExperience: number;
phoneNumber: number;
createdAt?: string;
}

export default function Home() {
const [advocates, setAdvocates] = useState([]);
const [filteredAdvocates, setFilteredAdvocates] = useState([]);
const [advocates, setAdvocates] = useState<Advocate[]>([]);
const [filteredAdvocates, setFilteredAdvocates] = useState<Advocate[]>([]);

useEffect(() => {
console.log("fetching advocates...");
Expand All @@ -16,10 +28,13 @@ export default function Home() {
});
}, []);

const onChange = (e) => {
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const searchTerm = e.target.value;

document.getElementById("search-term").innerHTML = searchTerm;
const searchTermElement = document.getElementById("search-term");
if (searchTermElement) {
searchTermElement.innerHTML = searchTerm;
}

console.log("filtering advocates...");
const filteredAdvocates = advocates.filter((advocate) => {
Expand All @@ -28,8 +43,8 @@ export default function Home() {
advocate.lastName.includes(searchTerm) ||
advocate.city.includes(searchTerm) ||
advocate.degree.includes(searchTerm) ||
advocate.specialties.includes(searchTerm) ||
advocate.yearsOfExperience.includes(searchTerm)
advocate.specialties.some(specialty => specialty.includes(searchTerm)) ||
advocate.yearsOfExperience.toString().includes(searchTerm)
);
});

Expand All @@ -43,11 +58,11 @@ export default function Home() {

return (
<main style={{ margin: "24px" }}>
<h1>Solace Advocates</h1>
<h1 className="text-xl md:text-3xl text-white font-bold bg-green-700 px-4 py-5 rounded-md">Solace Advocates</h1>
<br />
<br />
<div>
<p>Search</p>
<p className="text-lg font-bold">Search</p>
<p>
Searching for: <span id="search-term"></span>
</p>
Expand All @@ -58,13 +73,15 @@ export default function Home() {
<br />
<table>
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>Degree</th>
<th>Specialties</th>
<th>Years of Experience</th>
<th>Phone Number</th>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>Degree</th>
<th>Specialties</th>
<th>Years of Experience</th>
<th>Phone Number</th>
</tr>
</thead>
<tbody>
{filteredAdvocates.map((advocate) => {
Expand All @@ -75,8 +92,8 @@ export default function Home() {
<td>{advocate.city}</td>
<td>{advocate.degree}</td>
<td>
{advocate.specialties.map((s) => (
<div>{s}</div>
{advocate.specialties.map((s: string, index: number) => (
<div key={index}>{s}</div>
))}
</td>
<td>{advocate.yearsOfExperience}</td>
Expand Down