Ignore:
Timestamp:
01/26/26 20:19:20 (6 months ago)
Author:
Dimitar Arsov <dimitararsov04@…>
Branches:
main
Children:
d47e225
Parents:
fd81a18
Message:

add Global exception handler

File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/components/userProfile/AllUsersHelper.tsx

    rfd81a18 ra3ae097  
    1 import { useEffect, useState } from "react";
     1import React, { useEffect, useState } from "react";
    22import { useNavigate } from "react-router-dom";
    33
     
    1010const AllUsers = () => {
    1111  const [users, setUsers] = useState<User[]>([]);
     12  const [searchedUser, setSearchedUser] = useState<string>("");
     13  const [error, setError] = useState<string | null>(null);
    1214  const navigate = useNavigate();
    1315
     
    2527  };
    2628
     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
    2746  return (
    2847    <div className="container mx-auto p-6">
    2948      <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
    3065      <div className="grid gap-4">
    3166        {users.map((u) => (
Note: See TracChangeset for help on using the changeset viewer.