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

Use typed routes #565

Merged
merged 4 commits into from
Nov 9, 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
31 changes: 31 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"react-markdown": "^9.0.1",
"react-masonry-css": "^1.0.16",
"react-router-dom": "6.25.1",
"react-router-typesafe-routes": "^1.2.2",
"react-use-websocket": "^4.8.1",
"remark-gfm": "^4.0.0",
"tailwind-merge": "^2.5.2",
Expand Down
146 changes: 102 additions & 44 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ import PendoInitializer from "@/components/PendoInitializer";
import { ScrollToTop } from "@/components/ScrollToTop";
import SprigInitializer from "@/components/SprigInitializer";
import Footer from "@/components/footer/Footer";
import GDPRBanner from "@/components/gdpr/gdprbanner";
import { FeaturedListingsProvider } from "@/components/listing/FeaturedListings";
import Navbar from "@/components/nav/Navbar";
import APIKeys from "@/components/pages/APIKeys";
import About from "@/components/pages/About";
import Account from "@/components/pages/Account";
import Browse from "@/components/pages/Browse";
import Create from "@/components/pages/Create";
import DeleteConnect from "@/components/pages/DeleteConnect";
import DownloadsPage from "@/components/pages/Download";
import EmailSignup from "@/components/pages/EmailSignup";
import FileBrowser from "@/components/pages/FileBrowser";
import Home from "@/components/pages/Home";
import Listing from "@/components/pages/Listing";
import Login from "@/components/pages/Login";
import Logout from "@/components/pages/Logout";
import NotFound from "@/components/pages/NotFound";
import OrderSuccess from "@/components/pages/OrderSuccess";
import OrdersPage from "@/components/pages/Orders";
import Playground from "@/components/pages/Playground";
import PrivacyPolicy from "@/components/pages/PrivacyPolicy";
import Profile from "@/components/pages/Profile";
import ResearchPage from "@/components/pages/ResearchPage";
import SellerDashboard from "@/components/pages/SellerDashboard";
import SellerOnboarding from "@/components/pages/SellerOnboarding";
import Signup from "@/components/pages/Signup";
import Terminal from "@/components/pages/Terminal";
import TermsOfService from "@/components/pages/TermsOfService";
import { AlertQueue, AlertQueueProvider } from "@/hooks/useAlertQueue";
import { AuthenticationProvider } from "@/hooks/useAuth";

import GDPRBanner from "./components/gdpr/gdprbanner";
import DeleteConnect from "./components/pages/DeleteConnect";
import DownloadsPage from "./components/pages/Download";
import OrderSuccess from "./components/pages/OrderSuccess";
import OrdersPage from "./components/pages/Orders";
import Playground from "./components/pages/Playground";
import PrivacyPolicy from "./components/pages/PrivacyPolicy";
import ResearchPage from "./components/pages/ResearchPage";
import SellerOnboarding from "./components/pages/SellerOnboarding";
import Terminal from "./components/pages/Terminal";
import TermsOfService from "./components/pages/TermsOfService";
import ROUTES from "@/lib/types/routes";

const App = () => {
return (
Expand All @@ -56,55 +56,113 @@ const App = () => {
<div className="flex-grow">
<Container>
<Routes>
<Route path="/" element={<Home />} />
<Route path={ROUTES.HOME.path} element={<Home />} />

<Route path="/playground" element={<Playground />} />
{/* Playground */}
<Route
path={ROUTES.PLAYGROUND.path}
element={<Playground />}
/>

<Route path="/about" element={<About />} />
<Route path="/downloads" element={<DownloadsPage />} />
<Route path="/research" element={<ResearchPage />} />
<Route path="/browse/:page?" element={<Browse />} />
{/* General pages */}
<Route path={ROUTES.ABOUT.path} element={<About />} />
<Route
path="/file/:artifactId"
element={<FileBrowser />}
path={ROUTES.DOWNLOADS.path}
element={<DownloadsPage />}
/>
<Route
path={ROUTES.RESEARCH.path}
element={<ResearchPage />}
/>
<Route
path={ROUTES.TOS.path}
element={<TermsOfService />}
/>
<Route
path={ROUTES.PRIVACY.path}
element={<PrivacyPolicy />}
/>

{/* Account */}
<Route
path={ROUTES.ACCOUNT.path}
element={<Account />}
/>
<Route path={ROUTES.LOGIN.path} element={<Login />} />
<Route path={ROUTES.LOGOUT.path} element={<Logout />} />
<Route path={ROUTES.SIGNUP.path} element={<Signup />} />
<Route
path={ROUTES.SIGNUP.EMAIL.path}
element={<EmailSignup />}
/>
<Route path={ROUTES.KEYS.path} element={<APIKeys />} />
<Route
path={ROUTES.PROFILE.path}
element={<Profile />}
/>
<Route path="/account" element={<Account />} />
<Route path="/login" element={<Login />} />
<Route path="/logout" element={<Logout />} />
<Route path="/signup/" element={<Signup />} />
<Route path="/signup/:id" element={<EmailSignup />} />

<Route path="/create" element={<Create />} />
{/* Listings */}
<Route path={ROUTES.LISTINGS.path}>
<Route
path={ROUTES.LISTINGS.$.BROWSE.relativePath}
element={<Browse />}
/>
<Route
path={ROUTES.LISTINGS.$.CREATE.relativePath}
element={<Create />}
/>
</Route>
<Route
path="/item/:username/:slug"
path={ROUTES.LISTING.path}
element={<Listing />}
/>
<Route path="/keys" element={<APIKeys />} />
<Route path="/profile/:id?" element={<Profile />} />
<Route
path={ROUTES.FILE.path}
element={<FileBrowser />}
/>

<Route path="/tos" element={<TermsOfService />} />
<Route path="/privacy" element={<PrivacyPolicy />} />
{/* Seller */}
<Route
path={ROUTES.SELL.path}
element={<SellerDashboard />}
>
<Route
path={ROUTES.SELL.$.ONBOARDING.relativePath}
element={<SellerOnboarding />}
/>
<Route
path={ROUTES.SELL.$.DELETE.relativePath}
element={<DeleteConnect />}
/>
</Route>

{/* Orders */}
<Route path={ROUTES.ORDER.path}>
<Route
path={ROUTES.ORDER.$.SUCCESS.relativePath}
element={<OrderSuccess />}
/>
</Route>
<Route
path="/sell/onboarding"
element={<SellerOnboarding />}
path={ROUTES.ORDERS.path}
element={<OrdersPage />}
/>

{/* Terminal */}
<Route
path="/sell/dashboard"
element={<SellerDashboard />}
path={ROUTES.TERMINAL.path}
element={<Terminal />}
/>
<Route
path="/delete-connect"
element={<DeleteConnect />}
path={ROUTES.TERMINAL.WITH_ID.path}
element={<Terminal />}
/>

<Route path="/success" element={<OrderSuccess />} />
<Route path="/orders" element={<OrdersPage />} />

<Route path="/terminal" element={<Terminal />} />
<Route path="/terminal/:id" element={<Terminal />} />

<Route path="/404" element={<NotFound />} />
{/* Not found */}
<Route
path={ROUTES.NOT_FOUND.path}
element={<NotFound />}
/>
<Route path="*" element={<NotFoundRedirect />} />
</Routes>
</Container>
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/auth/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button";
import { useAlertQueue } from "@/hooks/useAlertQueue";
import { useAuthentication } from "@/hooks/useAuth";
import { SignUpSchema, SignupType } from "@/lib/types";
import ROUTES from "@/lib/types/routes";
import { zodResolver } from "@hookform/resolvers/zod";
import zxcvbn from "zxcvbn";

Expand Down Expand Up @@ -56,7 +57,7 @@ const SignupForm: React.FC<SignupFormProps> = ({ signupTokenId }) => {
addErrorAlert(error);
} else {
addAlert("Registration successful! You can now log in.", "success");
navigate("/login");
navigate(ROUTES.LOGIN.path);
// Sign user in automatically?
}
} catch (err) {
Expand Down Expand Up @@ -93,11 +94,11 @@ const SignupForm: React.FC<SignupFormProps> = ({ signupTokenId }) => {
{/* TOS Text */}
<div className="text-xs text-center text-gray-11">
By signing up, you agree to our <br />
<Link to="/tos" className="text-accent underline">
<Link to={ROUTES.TOS.path} className="text-accent underline">
terms and conditions
</Link>{" "}
and{" "}
<Link to="/privacy" className="text-accent underline">
<Link to={ROUTES.PRIVACY.path} className="text-accent underline">
privacy policy
</Link>
.
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/components/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link, useLocation } from "react-router-dom";

import Logo from "@/components/Logo";
import SocialLink from "@/components/footer/SocialLink";
import ROUTES from "@/lib/types/routes";

const Footer = () => {
const location = useLocation();
Expand Down Expand Up @@ -64,19 +65,19 @@ const Footer = () => {
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-4">
<div className="flex flex-col items-start gap-2">
<h2 className="text-base font-bold mb-1">Company</h2>
<Link to={"/about"} className="hover:text-primary-9">
<Link to={ROUTES.ABOUT.path} className="hover:text-primary-9">
About
</Link>
<Link to={"/research"} className="hover:text-primary-9">
<Link to={ROUTES.RESEARCH.path} className="hover:text-primary-9">
Blog
</Link>
</div>
<div className="flex flex-col items-start gap-2">
<h2 className="text-base font-bold mb-1">Legal</h2>
<Link to={"/tos"} className="hover:text-primary-9">
<Link to={ROUTES.TOS.path} className="hover:text-primary-9">
Terms of Service
</Link>
<Link to={"/privacy"} className="hover:text-primary-9">
<Link to={ROUTES.PRIVACY.path} className="hover:text-primary-9">
Privacy Policy
</Link>
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/listing/ListingArtifactRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link } from "react-router-dom";

import placeholder from "@/components/listing/pics/placeholder.jpg";
import { Artifact } from "@/components/listing/types";
import ROUTES from "@/lib/types/routes";

interface Props {
artifact: Artifact;
Expand All @@ -22,7 +23,7 @@ const ListingArtifactRenderer = ({ artifact }: Props) => {
return (
<div className="w-full h-full bg-gray-3 flex flex-col items-center justify-center gap-2">
<Link
to={`/file/${artifact.artifact_id}`}
to={ROUTES.FILE.buildPath({ artifactId: artifact.artifact_id })}
className="p-4 hover:bg-gray-4 rounded-lg transition-colors"
>
<FaFileArchive className="w-16 h-16" />
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/listing/ListingDeleteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Modal from "@/components/ui/Modal";
import { Button } from "@/components/ui/button";
import { useAlertQueue } from "@/hooks/useAlertQueue";
import { useAuthentication } from "@/hooks/useAuth";
import ROUTES from "@/lib/types/routes";

interface Props {
listingId: string;
Expand Down Expand Up @@ -37,7 +38,7 @@ const ListingDeleteButton = (props: Props) => {
setDeleting(false);
} else {
addAlert("Listing was deleted successfully", "success");
navigate("/browse");
navigate(ROUTES.LISTINGS.BROWSE.path);
}
};

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/listing/ListingMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useNavigate } from "react-router-dom";

import { useAlertQueue } from "@/hooks/useAlertQueue";
import { useAuthentication } from "@/hooks/useAuth";
import ROUTES from "@/lib/types/routes";

interface Props {
listingId: string;
Expand Down Expand Up @@ -110,7 +111,7 @@ const ListingMetadata = ({
<div className="flex items-center gap-2">
<button
onClick={() => {
navigate(`/profile/${creatorId}`);
navigate(ROUTES.PROFILE.buildPath({ id: creatorId }));
}}
className="text-blue-500 hover:bg-gray-100 rounded px-1 flex items-center gap-1"
>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/listing/artifacts/TgzArtifact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Link, useNavigate } from "react-router-dom";

import { Button } from "@/components/ui/button";
import { components } from "@/gen/api";
import ROUTES from "@/lib/types/routes";
import { cx } from "class-variance-authority";

type SingleArtifactResponse = components["schemas"]["SingleArtifactResponse"];
Expand Down Expand Up @@ -59,7 +60,7 @@ const UrdfViewerButton = ({ artifact }: Props) => {
<Button
className="p-3 w-full mt-2"
onClick={() => {
navigate(`/file/${artifact.artifact_id}`);
navigate(ROUTES.FILE.buildPath({ artifactId: artifact.artifact_id }));
}}
variant="secondary"
>
Expand All @@ -84,7 +85,7 @@ const CodeInstructions = ({ artifactId }: { artifactId: string }) => {
</li>
<li>
Configure your{" "}
<Link to="/keys" className="link">
<Link to={ROUTES.KEYS.path} className="link">
API key
</Link>
</li>
Expand Down
Loading
Loading