remade frontend
This commit is contained in:
parent
02281120dc
commit
36d99b1e35
45 changed files with 1290 additions and 4979 deletions
5
frontend/src/Components/Navbar/Navbar.module.scss
Normal file
5
frontend/src/Components/Navbar/Navbar.module.scss
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.navbar {
|
||||
display: grid;
|
||||
grid-template-columns: 10% 80% 10%;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
33
frontend/src/Components/Navbar/Navbar.tsx
Normal file
33
frontend/src/Components/Navbar/Navbar.tsx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { Navbar as BsNavbar, Container } from "react-bootstrap";
|
||||
// import styles from "./Navbar.module.scss";
|
||||
import Searchbar from "../Searchbar/Searchbar";
|
||||
import { useState } from "react";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
|
||||
const Navbar = () => {
|
||||
const [searchText, setSearchText] = useState<string>("");
|
||||
const navigate = useNavigate();
|
||||
|
||||
function onSearch() {
|
||||
navigate(`/search?search=${searchText}`);
|
||||
setSearchText("");
|
||||
}
|
||||
|
||||
return (
|
||||
<BsNavbar expand="lg" className={"bg-light "}>
|
||||
<Container>
|
||||
<Link to={"/"} style={{ textDecoration: "none" }}>
|
||||
<BsNavbar.Brand>JellyGlass</BsNavbar.Brand>
|
||||
</Link>
|
||||
<BsNavbar.Toggle />
|
||||
<BsNavbar.Collapse>
|
||||
<Container className="justify-content-center d-flex">
|
||||
<Searchbar text={searchText} setText={setSearchText} onSearch={onSearch} />
|
||||
</Container>
|
||||
</BsNavbar.Collapse>
|
||||
</Container>
|
||||
</BsNavbar>
|
||||
)
|
||||
}
|
||||
|
||||
export default Navbar;
|
||||
5
frontend/src/Components/Searchbar/Searchbar.module.scss
Normal file
5
frontend/src/Components/Searchbar/Searchbar.module.scss
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.searchbar {
|
||||
border-radius: 10px;
|
||||
padding: 5px;
|
||||
width: 100%;
|
||||
}
|
||||
27
frontend/src/Components/Searchbar/Searchbar.tsx
Normal file
27
frontend/src/Components/Searchbar/Searchbar.tsx
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import type React from "react";
|
||||
import styles from "./Searchbar.module.scss";
|
||||
|
||||
interface SearchbarProps {
|
||||
text: string,
|
||||
setText: (text: string) => void;
|
||||
onSearch?: () => void;
|
||||
}
|
||||
|
||||
const Searchbar = ({ text, setText, onSearch }: SearchbarProps) => {
|
||||
|
||||
function onKeyPressed(event: React.KeyboardEvent<HTMLInputElement>) {
|
||||
if (onSearch === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.key === "Enter") {
|
||||
onSearch();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<input className={styles.searchbar} type="text" placeholder="Search" value={text} onChange={e => setText(e.target.value)} onKeyUp={onKeyPressed} />
|
||||
)
|
||||
}
|
||||
|
||||
export default Searchbar;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
.serverCard {
|
||||
max-width: 400px;
|
||||
width: 400px;
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
margin: 25px;
|
||||
}
|
||||
26
frontend/src/Components/ServerList/ServerCard/ServerCard.tsx
Normal file
26
frontend/src/Components/ServerList/ServerCard/ServerCard.tsx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { Card } from "react-bootstrap";
|
||||
import { Link } from "react-router-dom";
|
||||
import styles from "./ServerCard.module.scss";
|
||||
|
||||
interface ServerCardProps {
|
||||
name: string;
|
||||
online: boolean;
|
||||
linkTo: string;
|
||||
}
|
||||
|
||||
const ServerCard = ({ name, online, linkTo }: ServerCardProps) => {
|
||||
return (
|
||||
<Link to={linkTo} className={styles.serverCard}>
|
||||
<Card>
|
||||
<Card.Header>
|
||||
<Card.Title>{name}</Card.Title>
|
||||
</Card.Header>
|
||||
<Card.Body>
|
||||
<h3>{online ? "Online" : "Offline"}</h3>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
export default ServerCard;
|
||||
23
frontend/src/Components/ServerList/ServerList.tsx
Normal file
23
frontend/src/Components/ServerList/ServerList.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import ServerCard from "./ServerCard/ServerCard";
|
||||
|
||||
interface ServerListProps {
|
||||
servers: Array<Server>;
|
||||
}
|
||||
|
||||
interface Server {
|
||||
name: string;
|
||||
online: boolean;
|
||||
linkTo: string;
|
||||
}
|
||||
|
||||
const ServerList = ({ servers }: ServerListProps) => {
|
||||
return (
|
||||
<div style={{ display: "flex", flexDirection: "row", flexWrap: "wrap" }}>
|
||||
{servers.map(server => {
|
||||
return (<ServerCard name={server.name} online={server.online} linkTo={server.linkTo} key={server.name} />)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ServerList;
|
||||
62
frontend/src/Components/ServerSearch/ServerSearch.tsx
Normal file
62
frontend/src/Components/ServerSearch/ServerSearch.tsx
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { Spinner, Table } from "react-bootstrap";
|
||||
import ServerSearchResult from "./ServerSearchResult/ServerSearchResult";
|
||||
import type { Server } from "../../Lib/Servers";
|
||||
import { search, type SearchResult } from "../../Lib/Search";
|
||||
|
||||
interface ServerSearchProps {
|
||||
searchTerm: string;
|
||||
server: Server;
|
||||
}
|
||||
|
||||
const ServerSearch = ({ searchTerm, server }: ServerSearchProps) => {
|
||||
const [searchResults, setSearchResults] = useState<Array<SearchResult>>([]);
|
||||
|
||||
useEffect(() => {
|
||||
search(searchTerm, server.id).then(results => {
|
||||
setSearchResults(results);
|
||||
})
|
||||
}, [searchTerm]);
|
||||
|
||||
return (
|
||||
<Table striped bordered >
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{server.name}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{searchResults.length > 0 ?
|
||||
searchResults.map(result => {
|
||||
return (
|
||||
<tr>
|
||||
<td>
|
||||
<ServerSearchResult key={result.id} searchResult={result} server={server} />
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})
|
||||
:
|
||||
<Spinner />
|
||||
}
|
||||
</tbody>
|
||||
</Table >
|
||||
|
||||
// <div>
|
||||
// <div>
|
||||
// <h1>{server.name}</h1>
|
||||
// </div>
|
||||
// <div>
|
||||
// {searchResults.length > 0 ?
|
||||
// searchResults.map(result => {
|
||||
// return <ServerSearchResult key={result.id} searchResult={result} server={server} />
|
||||
// })
|
||||
// :
|
||||
// <Spinner />
|
||||
// }
|
||||
// </div>
|
||||
// </div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ServerSearch;
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import { Link } from "react-router-dom";
|
||||
import { getUrlForSearchResult, type SearchResult } from "../../../Lib/Search";
|
||||
import type { Server } from "../../../Lib/Servers";
|
||||
|
||||
interface ServerSearchResultProps {
|
||||
searchResult: SearchResult;
|
||||
server: Server;
|
||||
}
|
||||
|
||||
const ServerSearchResult = ({ searchResult, server }: ServerSearchResultProps) => {
|
||||
const resultUrl = getUrlForSearchResult(searchResult, server);
|
||||
|
||||
return (
|
||||
<Link to={resultUrl}>
|
||||
<h3>{searchResult.name}</h3>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
export default ServerSearchResult;
|
||||
Loading…
Add table
Add a link
Reference in a new issue