Changeset ebdd3d4 for frontend


Ignore:
Timestamp:
02/07/26 15:15:12 (5 months ago)
Author:
Filip Gavrilovski <filipgavrilovski28@…>
Branches:
main
Children:
dc30259
Parents:
5938bc9
Message:

add route for viewing own profile

Location:
frontend/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/App.tsx

    r5938bc9 rebdd3d4  
    9090                                element: <MusicalCollection />,
    9191                        },
     92                        {
     93                                path: "/me",
     94                                element: <UserDetail />,
     95                        },
    9296                ],
    9397        },
  • frontend/src/pages/Nav.tsx

    r5938bc9 rebdd3d4  
    105105                                                                        <div className="absolute right-0 mt-2 w-48 bg-gray-700 rounded-lg shadow-lg py-1 z-50">
    106106                                                                                <Link
    107                                                                                         to="#"
     107                                                                                        to="/me"
    108108                                                                                        className="block px-4 py-2 text-sm text-white hover:bg-gray-600 transition-colors"
    109109                                                                                        onClick={() => setIsDropdownOpen(false)}
  • frontend/src/pages/UserDetail.tsx

    r5938bc9 rebdd3d4  
    55import ListenerView from "../components/userProfile/ListenerView";
    66import UserListModal from "../components/userProfile/UserListModal";
     7import { useAuth } from "../context/authContext";
    78import { handleError } from "../utils/error";
    89import type {
     
    3536        // user refers to the selected user NOT to the user from context
    3637        const baseURL = import.meta.env.VITE_API_BASE_URL;
    37         const { username } = useParams();
     38        const { username: usernameParam } = useParams();
     39        // sintaksava dole znaci zemi go user od auth context i preimenuvaj go vo currentUser, za da ne se izmesa so user-ot dole
     40        const { user: currentUser } = useAuth();
    3841        const navigate = useNavigate();
    3942        const [user, setUser] = useState<UserProfile | null>(null);
     
    4447        const [isLoadingModal, setIsLoadingModal] = useState(false);
    4548        const [isFollowing, setIsFollowing] = useState(false);
     49
     50        // determine which username to use: URL param or current user's username
     51        const username = usernameParam || currentUser?.username;
     52
     53        // if we're on /me route and no user is logged in, show error
     54        if (!usernameParam && !currentUser) {
     55                return (
     56                        <div className="p-6 bg-red-50 border border-red-200 text-red-700 rounded-lg">
     57                                <h2 className="font-bold">Authentication Required</h2>
     58                                <p>You must be logged in to view your profile.</p>
     59                                <button
     60                                        onClick={() => navigate("/login")}
     61                                        className="mt-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors duration-200 cursor-pointer"
     62                                >
     63                                        Go to Login
     64                                </button>
     65                        </div>
     66                );
     67        }
    4668
    4769        const handleFollow = async () => {
Note: See TracChangeset for help on using the changeset viewer.