- Timestamp:
- 01/26/26 20:19:20 (6 months ago)
- Branches:
- main
- Children:
- d47e225
- Parents:
- fd81a18
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/components/userProfile/AllUsersHelper.tsx
rfd81a18 ra3ae097 1 import { useEffect, useState } from "react";1 import React, { useEffect, useState } from "react"; 2 2 import { useNavigate } from "react-router-dom"; 3 3 … … 10 10 const AllUsers = () => { 11 11 const [users, setUsers] = useState<User[]>([]); 12 const [searchedUser, setSearchedUser] = useState<string>(""); 13 const [error, setError] = useState<string | null>(null); 12 14 const navigate = useNavigate(); 13 15 … … 25 27 }; 26 28 29 const handleSearch = async (e: React.FormEvent) => { 30 e.preventDefault(); 31 try { 32 const response = await fetch( 33 `http://localhost:8080/users/search?name=${searchedUser}`, 34 ); 35 if (!response.ok) throw new Error("Search failed"); 36 37 const data = await response.json(); 38 setUsers(data); 39 } catch (err: any) { 40 setError(err.message); 41 } 42 }; 43 44 if (users.length == 0) return <div className="p-6">Loading...</div>; 45 27 46 return ( 28 47 <div className="container mx-auto p-6"> 29 48 <h1 className="text-3xl font-bold mb-6">All Users</h1> 49 <form onSubmit={handleSearch} className="flex gap-2 mb-10"> 50 <input 51 type="text" 52 value={searchedUser} 53 onChange={(e) => setSearchedUser(e.target.value)} 54 className="border p-2 rounded w-full" 55 placeholder="Search for a user..." 56 /> 57 <button 58 type="submit" 59 className="bg-blue-600 text-white px-6 py-2 rounded hover:bg-blue-700 transition-colors" 60 > 61 Search 62 </button> 63 </form> 64 30 65 <div className="grid gap-4"> 31 66 {users.map((u) => (
Note:
See TracChangeset
for help on using the changeset viewer.
