Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend redesign #11

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script src="https://cdn.jsdelivr.net/npm/react-bootstrap@next/dist/react-bootstrap.min.js" crossorigin></script>
<script>var Alert = ReactBootstrap.Alert;</script>

<title>RoboList</title>
<title>robolist</title>
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import App from "./App";

test("renders stompy urdf link", () => {
render(<App />);
const linkElement = screen.getByText(/robolist.xyz/i);
const linkElement = screen.getByText(/Listings/i);
expect(linkElement).toBeInTheDocument();
});
45 changes: 30 additions & 15 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import "bootstrap/dist/css/bootstrap.min.css";
import { BrowserRouter, Link, Route, Routes } from "react-router-dom";
import "./App.css";

import Authentication from "components/Authentication";
import Listings from "components/Listings";
import Home from "pages/Home";
import RobotDetails from "pages/Robot";
import { Container } from "react-bootstrap";
import { Container, Nav, Navbar } from "react-bootstrap";
import { BrowserRouter, Link, Route, Routes } from "react-router-dom";
import "./App.css";

const App = () => {
return (
<BrowserRouter>
<Container style={{ marginTop: 20 }}>
<h1>
<Link to="/">robolist.xyz</Link>
</h1>
<p>Buy and sell robots</p>
<Authentication />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/robots/" element={<Listings />} />
<Route path="/robots/:id" element={<RobotDetails />} />
</Routes>
<Container>
<Navbar className="bg-body-tertiary">
<Container>
<Navbar.Brand as={Link} to="/">
robolist
</Navbar.Brand>
<Navbar.Toggle />
<Navbar.Collapse className="justify-content-end">
<Nav>
<Nav.Link as={Link} to="/robots/">
Listings
</Nav.Link>
</Nav>
<Navbar.Text>
<Authentication />
</Navbar.Text>
</Navbar.Collapse>
</Container>
</Navbar>

<Container className="mt-3">
<Routes>
<Route path="/" element={<Home />} />
<Route path="/robots/" element={<Listings />} />
<Route path="/robots/:id" element={<RobotDetails />} />
</Routes>
</Container>
</Container>
</BrowserRouter>
);
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Authentication = () => {
return (
<div style={{ maxWidth: 400 }}>
{authenticated ? (
<InputGroup className="mb-3">
<InputGroup>
<InputGroup.Text>{email}</InputGroup.Text>
<Button
variant="outline-secondary"
Expand All @@ -25,7 +25,7 @@ const Authentication = () => {
</Button>
</InputGroup>
) : (
<InputGroup className="mb-3">
<InputGroup>
<InputGroup.Text>✉️</InputGroup.Text>
<Form.Control
placeholder="Email"
Expand All @@ -44,8 +44,8 @@ const Authentication = () => {
Log In
</Button>
<Overlay
placement="right"
show={email !== null && !isValidEmail(email)}
placement="bottom-end"
show={email !== null && email.length > 3 && !isValidEmail(email)}
target={target.current}
>
{(props) => <Tooltip {...props}>Invalid email</Tooltip>}
Expand Down
111 changes: 39 additions & 72 deletions frontend/src/components/Listings.tsx
Original file line number Diff line number Diff line change
@@ -1,97 +1,64 @@
import { Carousel } from "react-bootstrap";
import Col from "react-bootstrap/Col";
import Container from "react-bootstrap/Container";
import Row from "react-bootstrap/Row";
import { Breadcrumb, Card, Col, Container, Row } from "react-bootstrap";
import { useNavigate } from "react-router-dom";

interface ListingsResponseItem {
name: string;
owner: string;
links: { name: string; url: string }[];
images: { url: string; caption: string }[];
description: string;
id: string;
photo?: string;
}

interface ListingsResponse {
listings: ListingsResponseItem[];
}

const Listing = ({ name, owner, links, images }: ListingsResponseItem) => {
return (
<Col>
<Row>
<h3>{name}</h3>
<p>{owner}</p>
</Row>
{links && (
<Row>
<ul>
{links.map((link, key) => (
<li key={key}>
<a href={link.url}>{link.name}</a>
</li>
))}
</ul>
</Row>
)}
{images && (
<Carousel indicators data-bs-theme="dark">
{images.map((image, key) => (
<Carousel.Item key={key}>
<img src={image.url} alt={image.caption} />
<Carousel.Caption>
<h3>{image.caption}</h3>
</Carousel.Caption>
</Carousel.Item>
))}
</Carousel>
)}
</Col>
);
};

const Listings = () => {
const response: ListingsResponse = {
listings: [
{
name: "Stompy",
owner: "K-Scale Labs",
links: [
{
name: "URDF (with STLs)",
url: "https://media.kscale.dev/stompy/latest_stl_urdf.tar.gz",
},
{
name: "URDF (with OBJs)",
url: "https://media.kscale.dev/stompy/latest_obj_urdf.tar.gz",
},
{
name: "MJCF",
url: "https://media.kscale.dev/stompy/latest_mjcf.tar.gz",
},
],
images: [
{
url: "https://media.robolist.xyz/logo.png",
caption: "Image 1",
},
{
url: "https://media.robolist.xyz/logo.png",
caption: "Image 2",
},
{
url: "https://media.robolist.xyz/logo.png",
caption: "Image 3",
},
],
description: "An open-source humanoid robot costing less than $10k",
id: "1",
photo: "https://media.robolist.xyz/stompy.png",
},
],
};

const navigate = useNavigate();

return (
<Container>
<h2>Listings</h2>
{response.listings.map((item, key) => (
<Listing key={key} {...item} />
))}
<Breadcrumb>
<Breadcrumb.Item onClick={() => navigate("/")}>Home</Breadcrumb.Item>
<Breadcrumb.Item active>Listings</Breadcrumb.Item>
</Breadcrumb>

<Row className="mt-5">
{response.listings.map(
({ name, owner, description, id, photo }, key) => (
<Col key={key} md={3} xs={6}>
<Card onClick={() => navigate(`/robots/${id}`)}>
{photo && (
<Card.Img
style={{ aspectRatio: "1/1" }}
variant="top"
src={photo}
/>
)}
<Card.Body>
<Card.Title>{name}</Card.Title>
<Card.Subtitle className="mb-2 text-muted">
{owner}
</Card.Subtitle>
<Card.Text>{description}</Card.Text>
</Card.Body>
</Card>
</Col>
),
)}
</Row>
</Container>
);
};
Expand Down
22 changes: 10 additions & 12 deletions frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Link } from "react-router-dom";
import { Col, Row } from "react-bootstrap";

const RobotDetails = () => {
return (
<div>
<h2>Home</h2>
<p>Welcome to RoboList!</p>
<ul>
<li>
<Link to="/robots/">Robots</Link>
</li>
<li>
<Link to="/robots/1">Robot 1</Link>
</li>
</ul>
<div className="p-5 rounded-lg">
<Row>
<Col>
<h1 className="display-4">robolist</h1>
<p className="lead">
Buy, sell and build robot hardware and software
</p>
</Col>
</Row>
</div>
);
};
Expand Down
Loading
Loading