aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/Sidebar/Content.tsx
diff options
context:
space:
mode:
authorWolfboy248 <georgejvindkarlsen@gmail.com>2025-08-21 10:33:27 +0200
committerWolfboy248 <georgejvindkarlsen@gmail.com>2025-08-21 10:33:27 +0200
commitda1fd74f9387149b2b94d62853587a8afdb74ddd (patch)
tree57f13021890b6d27848a3379d0869790fd1d7c97 /frontend/src/components/Sidebar/Content.tsx
parentorganised pages, started work on theme (diff)
downloadlphub-da1fd74f9387149b2b94d62853587a8afdb74ddd.tar.gz
lphub-da1fd74f9387149b2b94d62853587a8afdb74ddd.tar.bz2
lphub-da1fd74f9387149b2b94d62853587a8afdb74ddd.zip
Reorganised Maplist and Sidebar
Diffstat (limited to 'frontend/src/components/Sidebar/Content.tsx')
-rw-r--r--frontend/src/components/Sidebar/Content.tsx133
1 files changed, 133 insertions, 0 deletions
diff --git a/frontend/src/components/Sidebar/Content.tsx b/frontend/src/components/Sidebar/Content.tsx
new file mode 100644
index 0000000..4051b08
--- /dev/null
+++ b/frontend/src/components/Sidebar/Content.tsx
@@ -0,0 +1,133 @@
1import React, { useRef } from "react";
2import { Link } from "react-router-dom";
3import { UserProfile } from "@customTypes/Profile";
4import { Search } from "@customTypes/Search";
5import { API } from "@api/Api";
6
7import styles from "./Sidebar.module.css";
8
9import {
10 FlagIcon,
11 HomeIcon,
12 PortalIcon,
13 SearchIcon,
14} from "../../images/Images";
15
16interface ContentProps {
17 profile?: UserProfile;
18 isSidebarOpen: boolean;
19 sidebarButtonRefs: React.RefObject<(HTMLButtonElement | null)[]>;
20 getButtonClasses: (buttonIndex: number) => string;
21 handle_sidebar_click: (clicked_sidebar_idx: number) => void;
22};
23
24const Content: React.FC<ContentProps> = ({ profile, isSidebarOpen, sidebarButtonRefs, getButtonClasses, handle_sidebar_click }) => {
25 const [searchData, setSearchData] = React.useState<Search | undefined>(
26 undefined
27 );
28
29 const searchbarRef = useRef<HTMLInputElement>(null);
30
31 const _handle_search_change = async (q: string) => {
32 const searchResponse = await API.get_search(q);
33 setSearchData(searchResponse);
34 };
35
36 const iconClasses = "";
37
38 return (
39 <div className="h-full">
40
41 <div className="px-2">
42 <div className={`${styles.button}`}>
43 <img src={SearchIcon} alt="Search" className={iconClasses} />
44 <span className="text-white font-[--font-barlow-semicondensed-regular] truncate">Search</span>
45 </div>
46
47 <div className="min-w-0">
48 <input
49 ref={searchbarRef}
50 type="text"
51 id="searchbar"
52 placeholder="Search for map or a player..."
53 onChange={e => _handle_search_change(e.target.value)}
54 className="w-full p-2 bg-input text-foreground border border-border rounded-lg text-sm min-w-0"
55 />
56
57 {searchData && (
58 <div className="mt-2 max-h-40 overflow-y-auto min-w-0">
59 {searchData?.maps.map((q, index) => (
60 <Link to={`/maps/${q.id}`} className="block p-2 mb-1 bg-surface1 rounded hover:bg-surface2 transition-colors min-w-0" key={index}>
61 <span className="block text-xs text-subtext1 truncate">{q.game}</span>
62 <span className="block text-xs text-subtext1 truncate">{q.chapter}</span>
63 <span className="block text-sm text-foreground truncate">{q.map}</span>
64 </Link>
65 ))}
66 {searchData?.players.map((q, index) => (
67 <Link
68 to={
69 profile && q.steam_id === profile.steam_id
70 ? `/profile`
71 : `/users/${q.steam_id}`
72 }
73 className="flex items-center p-2 mb-1 bg-surface1 rounded hover:bg-surface2 transition-colors min-w-0"
74 key={index}
75 >
76 <img src={q.avatar_link} alt="pfp" className="w-6 h-6 rounded-full mr-2 flex-shrink-0" />
77 <span className="text-sm text-foreground truncate">
78 {q.user_name}
79 </span>
80 </Link>
81 ))}
82 </div>
83 )}
84 </div>
85 </div>
86
87 <div className="flex-1 min-w-0">
88 <nav className="px-2 flex flex-col gap-2">
89 {[
90 {
91 to: "/",
92 refIndex: 1,
93 icon: HomeIcon,
94 alt: "Home",
95 label: "Home Page",
96 },
97 {
98 to: "/games",
99 refIndex: 2,
100 icon: PortalIcon,
101 alt: "Games",
102 label: "Games",
103 },
104 {
105 to: "/rankings",
106 refIndex: 3,
107 icon: FlagIcon,
108 alt: "Rankings",
109 label: "Rankings",
110 },
111 ].map(({ to, refIndex, icon, alt, label }) => (
112 <Link to={to} tabIndex={-1} key={refIndex}>
113 <button
114 ref={el => {
115 sidebarButtonRefs.current[refIndex] = el
116 }}
117 className={`${styles.button}`}
118 onClick={() => handle_sidebar_click(refIndex)}
119 >
120 <img src={icon} alt={alt} className={iconClasses} />
121 <span className="">
122 {label}
123 </span>
124 </button>
125 </Link>
126 ))}
127 </nav>
128 </div>
129 </div>
130 );
131}
132
133export default Content;