Skip to content

Bonus iteration using query string #104

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1,557 changes: 1,460 additions & 97 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"test": "vitest --ui"
},
"dependencies": {
"express": "^4.21.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^7.1.1"
},
"devDependencies": {
"@types/react": "^18.0.37",
Expand Down
47 changes: 44 additions & 3 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
width: 6em;
object-fit: contain;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
Expand All @@ -17,6 +16,11 @@
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
.logo-small {
height: 3rem;
width: 3rem;
object-fit: contain;
}

@keyframes logo-spin {
from {
Expand All @@ -40,3 +44,40 @@
.read-the-docs {
color: #888;
}

nav {
height: 4rem;
background-color: #646cffaa;
display: flex;
justify-content: space-between;
align-items: center;
}
nav a {
color: white;
text-decoration: none;
font-size: 1.25rem;
font-weight: 700;
margin: 0 2rem;
}

#homePage {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.company-card {
/* margin: 2rem;
border: 2px rgba(187, 187, 187, 0.356) solid;
border-radius: 5rem; */
}

.company-stack-container {
display: flex;
flex-direction: row;
}

.company-stack-container {
display: grid;
grid-template-rows: repeat(2, 1fr);
grid-auto-flow: column;
}

12 changes: 11 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { Routes, Route } from "react-router-dom"; // <== IMPORT
import "./App.css";
import Navbar from "./components/Navbar";
import HomePage from "./pages/HomePage";
import CompanyPage from "./pages/CompanyPage";
import TechnologyPage from "./pages/TechnologyPage";

function App() {
return (
<div className="App">
<h1>LAB | React Stack Tracker</h1>
<Navbar />
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/company" element={<CompanyPage />} />
<Route path="/tech" element={<TechnologyPage />} />
</Routes>
</div>
);
}
Expand Down
15 changes: 15 additions & 0 deletions src/components/CompanyCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable react/prop-types */
import { Link } from "react-router";

function CompanyCard({ company }) {
return (
<div className="company-card">
<Link to={`/company?company=${company.slug}`}>
<h4>{company.name}</h4>
<img className="logo" src={company.logo} alt="Company logo" />
</Link>
</div>
);
}

export default CompanyCard;
28 changes: 28 additions & 0 deletions src/components/CompanyDetails.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable react/prop-types */
import { Link } from "react-router";

function CompanyDetails({ company }) {
return (
<div className="company-details">
<div className="company-info">
<img className="logo" src={company.logo} alt="Company logo" />
<h2>{company.name}</h2>
<h5>About</h5>
<p>{company.description}</p>
</div>

<div className="company-stack-container">
{company.techStack.map((stack) => (
<div key={stack.slug} className="company-stack">
<Link to={`/tech?company=${company.slug}&tech=${stack.slug}`}>
<img className="logo logo-small" src={stack.image} alt="Stack image" />
<p>{stack.name}</p>
</Link>
</div>
))}
</div>
</div>
);
}

export default CompanyDetails;
8 changes: 7 additions & 1 deletion src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { NavLink } from "react-router";

function Navbar() {
return <nav>Navbar</nav>;
return (
<nav>
<NavLink to="/">StackTracker</NavLink>
</nav>
);
}

export default Navbar;
23 changes: 23 additions & 0 deletions src/components/TechDetails.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Link } from "react-router";
import { useSearchParams } from "react-router-dom";

function TechDetails({ techStack }) {
const [searchParams, setSearchParams] = useSearchParams();
const companySlug = searchParams.get("company");

return (
<div className="tech-details">
<img className="logo" src={techStack.image} alt="Company logo" />
<div className="tech-info">
<h2>{techStack.name}</h2>
<h5>About</h5>
<p>{techStack.description}</p>
</div>
<Link to={`/company?company=${companySlug}`}>
<button>Back</button>
</Link>
</div>
);
}

export default TechDetails;
4 changes: 0 additions & 4 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ a:hover {

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
Expand Down
19 changes: 11 additions & 8 deletions src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import "./index.css";
import { BrowserRouter as Router } from "react-router-dom";

ReactDOM.createRoot(document.getElementById('root')).render(
ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
<Router>
<App />
</Router>
</React.StrictMode>
);
14 changes: 12 additions & 2 deletions src/pages/CompanyPage.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import companiesData from "../companies.json";
import CompanyDetails from "../components/CompanyDetails";
import { useSearchParams } from "react-router-dom";

function CompanyPage() {
const [searchParams, setSearchParams] = useSearchParams();
const companySlug = searchParams.get("company");

const foundCompany = companiesData.find((oneCompany) => oneCompany.slug === companySlug);
return (
<div>
<h1>CompanyPage</h1>
<div className="company-details-container">
<h2>Company Profile</h2>
{!foundCompany && <h3>Error 404: the page not found!</h3>}
{foundCompany && <CompanyDetails company={foundCompany} />}
</div>
);
}
Expand Down
14 changes: 11 additions & 3 deletions src/pages/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import CompanyCard from "../components/CompanyCard";
import companiesData from "../companies.json";

function HomePage() {
return (
<div>
<h1>HomePage</h1>
</div>
<>
<h1>StackTracker: Discover Tech Stacks Used by Top Companies</h1>
<div id="homePage">
{companiesData.map((element) => (
<CompanyCard key={element.id} company={element} />
))}
</div>
</>
);
}

Expand Down
21 changes: 20 additions & 1 deletion src/pages/TechnologyPage.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import technologiesData from "../technologies.json";
import TechDetails from "../components/TechDetails";
import { Link, useSearchParams } from "react-router-dom";

function TechnologyPage() {
const [searchParams, setSearchParams] = useSearchParams();
const companySlug = searchParams.get("company");
const techSlug = searchParams.get("tech");

const foundTech = technologiesData.find((oneTech) => oneTech.slug === techSlug);

return (
<div>
<h1>TechnologyPage</h1>
<h2>Technology Details</h2>
{!foundTech && (
<>
<h3>Error 404: the page not found!</h3>
<Link to={`/company?company=${companySlug}`}>
<button>Back</button>
</Link>
</>
)}
{foundTech && <TechDetails techStack={foundTech} />}
</div>
);
}
Expand Down