Skip to content

Commit

Permalink
correct profilepage
Browse files Browse the repository at this point in the history
  • Loading branch information
Peppisparrow committed Feb 4, 2024
1 parent dc16bdd commit fd15d21
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 79 deletions.
8 changes: 4 additions & 4 deletions IT/codekatabattle-frontend/src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export const NavBar= () => {
className="drawer-overlay"></label>
<ul className="menu p-4 w-80 min-h-full bg-base-200 text-base-content">
<li><Link to={"/all/tournaments/view/0"}>All Tournaments</Link></li>
<li><Link to={"/joined/tournaments/view/0"}>Joined Tournaments</Link></li>
<li><Link to={"/created/tournaments/view/0"}>Created Tournaments</Link></li>
<li><Link to={"/coordinated/tournaments/view/0"}>Coordinated Tournaments</Link></li>
<li><Link to={"/joined/tournaments/view/"+user?.login+"/0"}>Joined Tournaments</Link></li>
<li><Link to={"/created/tournaments/view/"+user?.login+"/0"}>Created Tournaments</Link></li>
<li><Link to={"/coordinated/tournaments/view/"+user?.login+"/0"}>Coordinated Tournaments</Link></li>
<li><Link to="/tournament/create">Create Tournaments</Link></li>
<li><Link to={"/profile/" + user?.login?.toString()}>My Profile</Link></li>

Expand Down Expand Up @@ -68,7 +68,7 @@ export const NavBar= () => {
<ul className="menu menu-vertical lg:menu-horizontal">
<input type="text" placeholder="Type here..." style={{height:"5%",paddingTop:"4%"}} className="bg-base-100 "
onChange={event => setUsername(event.target.value)}/>
<button className="btm btn-sm btn-ghost btn-circle" style={{right:"70%"}} onClick={()=>navigate("/"+username)}>
<button className="btm btn-sm btn-ghost btn-circle" style={{right:"70%"}} onClick={()=>navigate("/profile/"+username)}>
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
Expand Down
30 changes: 15 additions & 15 deletions IT/codekatabattle-frontend/src/components/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {NavBar} from "./NavBar.tsx";
import {useEffect, useState} from "react";
import educator from "../assets/educator.png";
import student from "../assets/reading.png";
import avatar from "../assets/avatar2.png";
import {ImageCreator} from "./ImageCreator.tsx";



export const ProfilePage= () => {
const params = useParams();
const [error, setError] = useState<Error | null>(null);
const [user, setUser]=useState<GHUser|null>(null)
const [user, setUser]=useState<GHUser|null>(null);
const [createdTournaments, setCreatedTournaments]=useState<PageTournament|null>(null)
const [coordinatedTournaments, setCoordinatedTournaments]=useState<PageTournament|null>(null)
const [joinedTournaments, setJoinedTournaments]=useState<PageTournament|null>(null)
Expand All @@ -28,16 +28,16 @@ export const ProfilePage= () => {
try {
if(!params.username)
return;
const user =await AuthService.getUserInfo(params.username);
setUser(user);
if(!user.login)
const tuser =await AuthService.getUserInfo(params.username);
setUser(tuser);
if(!tuser?.login)
return;
const createdTournaments =await TournamentService.findAllCreatedByUser(user.login.toString(),0, 4);
setCreatedTournaments(createdTournaments);
const coordinatedTournaments =await TournamentService.findAllCoordinatedByUser(user.login.toString(),0, 4);
setCoordinatedTournaments(coordinatedTournaments);
const joinedTournaments =await TournamentService.findAllJoinedByUser(user.login.toString(),0, 4);
setJoinedTournaments(joinedTournaments);
const tcreatedTournaments =await TournamentService.findAllCreatedByUser(tuser.login.toString(),0, 4);
setCreatedTournaments(tcreatedTournaments);
const tcoordinatedTournaments =await TournamentService.findAllCoordinatedByUser(tuser.login.toString(),0, 4);
setCoordinatedTournaments(tcoordinatedTournaments);
const tjoinedTournaments =await TournamentService.findAllJoinedByUser(tuser.login.toString(),0, 4);
setJoinedTournaments(tjoinedTournaments);
}catch (error1) {
setError(error1 as Error);
if (error?.message) alert(error?.message);
Expand Down Expand Up @@ -130,7 +130,7 @@ export const ProfilePage= () => {
<div className="stat-figure text-secondary">
<div className="avatar online">
<div className="w-16 rounded-full">
<img src={avatar}/>
<ImageCreator username={t.creator}/>
</div>
</div>
</div>
Expand Down Expand Up @@ -194,7 +194,7 @@ export const ProfilePage= () => {
<input type="radio" name="my_tabs_2" role="tab" className="tab" aria-label="Created tournaments" checked/>
<div role="tabpanel" className="tab-content bg-base-100 border-base-300 rounded-box p-6">
<CreatedTournaments/>
<div onClick={() => navigate("/created/tournaments/view/0")} className="badge badge-info gap-2 font-bold">
<div onClick={() => navigate("/created/tournaments/view/"+user?.login+"/0")} className="badge badge-info gap-2 font-bold">
{"See more >>"}
</div>
</div>
Expand All @@ -203,15 +203,15 @@ export const ProfilePage= () => {
aria-label="Coordinated tournaments"/>
<div role="tabpanel" className="tab-content bg-base-100 border-base-300 rounded-box p-6">
<CoordinatedTournaments/>
<div onClick={() => navigate("/coordinated/tournaments/view/0")} className="badge badge-info gap-2 font-bold">
<div onClick={() => navigate("/coordinated/tournaments/view/"+user?.login+"/0")} className="badge badge-info gap-2 font-bold">
{"See more >>"}
</div>
</div>

<input type="radio" name="my_tabs_2" role="tab" className="tab" aria-label="Joined tournaments"/>
<div role="tabpanel" className="tab-content bg-base-100 border-base-300 rounded-box p-6">
<JoinedTournaments/>
<div onClick={() => navigate("/joined/tournaments/view/0")} className="badge badge-info gap-2 font-bold">
<div onClick={() => navigate("/joined/tournaments/view/"+user?.login+"/0")} className="badge badge-info gap-2 font-bold">
{"See more >>"}
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageTournament, Tournament, TournamentService} from "../services/openapi";
import {AuthService, PageTournament, Tournament, TournamentService} from "../services/openapi";
import {useContext, useEffect, useState} from "react";
import {NavBar} from "./NavBar.tsx";
import five from "../assets/high-five.png"
Expand All @@ -16,12 +16,17 @@ export const VisualizeCoordinatedTournaments= () => {

useEffect(() => {
fetchTournaments();
}, [params,user]);
}, []);

async function fetchTournaments() {
try {
if(user?.login) {
const tournaments = await TournamentService.findAllCoordinatedByUser(user.login, +params.page!, 5);
let tuser;
if(!params.username) tuser=user;
else {
tuser = await AuthService.getUserInfo(params.username);
}
if(tuser?.login) {
const tournaments = await TournamentService.findAllCoordinatedByUser(tuser.login, +params.page!, 5);
setTournaments(tournaments);
}

Expand All @@ -33,7 +38,7 @@ export const VisualizeCoordinatedTournaments= () => {

function to(id: string | undefined) {
if (id != undefined) {
const s = "/coordinated/tournaments/" + id;
const s = "/coordinated/tournaments/view/"+params.username+"/"+id;
navigate(s);
location.reload();
}
Expand All @@ -54,15 +59,15 @@ export const VisualizeCoordinatedTournaments= () => {
<input className="join-item btn " type="radio" name="options" aria-label="1"
checked/>
<input className="join-item btn " type="radio" name="options" aria-label="2"
onClick={() => (to("view/1"))}/>
onClick={() => (to("1"))}/>
</div>
)
}
if (tournaments.totalPages <= 2 && params.page == "1") {
return (
<div className="join">
<input className="join-item btn " type="radio" name="options" aria-label="1"
onClick={() => (to("view/0"))}/>
onClick={() => (to("0"))}/>
<input className="join-item btn " type="radio" name="options" aria-label="2"
checked/>
</div>
Expand All @@ -75,26 +80,26 @@ export const VisualizeCoordinatedTournaments= () => {
aria-label={"Page " + (+params.page! + 1).toString()}
checked/>
<input className="join-item btn " type="radio" name="options" aria-label="»"
onClick={() => (to("view/" + (+params.page! + 1).toString()))}/>
onClick={() => (to((+params.page! + 1).toString()))}/>
<input className="join-item btn " type="radio" name="options"
aria-label={(tournaments.totalPages - 1).toString()}
onClick={() => (to("view/" + ((tournaments?.totalPages ?? 2) - 2).toString()))}/>
onClick={() => (to(((tournaments?.totalPages ?? 2) - 2).toString()))}/>
<input className="join-item btn " type="radio" name="options"
aria-label={tournaments.totalPages.toString()}
onClick={() => (to("view/" + ((tournaments?.totalPages ?? 1) - 1).toString()))}/>
onClick={() => (to(((tournaments?.totalPages ?? 1) - 1).toString()))}/>
</div>
)
}
if (params.page == (tournaments.totalPages - 1).toString()) {
return (
<div className="join">
<input className="join-item btn " type="radio" name="options" aria-label="1"
onClick={() => (to("view/0"))}
onClick={() => (to("0"))}
/>
<input className="join-item btn " type="radio" name="options" aria-label="2"
onClick={() => (to("view/1"))}/>
onClick={() => (to("1"))}/>
<input className="join-item btn " type="radio" name="options" aria-label="«"
onClick={() => (to("view/" + (+params.page! - 1).toString()))}
onClick={() => (to( (+params.page! - 1).toString()))}
/>
<input className="join-item btn " type="radio" name="options"
aria-label={"Page " + (+params.page! + 1).toString()}
Expand All @@ -104,23 +109,23 @@ export const VisualizeCoordinatedTournaments= () => {
}
return (<div className="join">
<input className="join-item btn " type="radio" name="options" aria-label="1"
onClick={() => (to("view/0"))}
onClick={() => (to("0"))}
/>
<input className="join-item btn " type="radio" name="options" aria-label="2"
onClick={() => (to("view/1"))}/>
onClick={() => (to("1"))}/>
<input className="join-item btn " type="radio" name="options" aria-label="«"
onClick={() => (to("view/" + (+params.page! - 1).toString()))}
onClick={() => (to( (+params.page! - 1).toString()))}
/>
<input className="join-item btn " type="radio" name="options" aria-label={"Page " + (+params.page! + 1).toString()}
checked/>
<input className="join-item btn " type="radio" name="options" aria-label="»"
onClick={() => (to("view/" + (+params.page! + 1).toString()))}
onClick={() => (to( (+params.page! + 1).toString()))}
/>
<input className="join-item btn " type="radio" name="options"
aria-label={(tournaments.totalPages - 1).toString()}
onClick={() => (to("view/" + ((tournaments?.totalPages ?? 2) - 2).toString()))}/>
onClick={() => (to( ((tournaments?.totalPages ?? 2) - 2).toString()))}/>
<input className="join-item btn " type="radio" name="options" aria-label={tournaments.totalPages.toString()}
onClick={() => (to("view/" + ((tournaments?.totalPages ?? 1) - 1).toString()))}/>
onClick={() => (to( ((tournaments?.totalPages ?? 1) - 1).toString()))}/>
</div>)
}

Expand Down
Loading

0 comments on commit fd15d21

Please sign in to comment.