Skip to content

Solved fully using UseState #105

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 4 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
26 changes: 23 additions & 3 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

Expand Down Expand Up @@ -40,3 +37,26 @@
.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 {
}

.company-stack-container {
display: flex;
flex-direction: row;
}
18 changes: 17 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
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";
import companiesData from "./companies.json";
import technologiesData from "./technologies.json";
import { useState } from "react";

function App() {
const [companies] = useState(companiesData);
const [technologies] = useState(technologiesData);

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

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

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-dom";

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/${stack.slug}`}>
<img className="logo" 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;
19 changes: 19 additions & 0 deletions src/components/TechDetails.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable react/prop-types */
function TechDetails({ techStack }) {

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>
</div>
<button onClick={() => window.history.back()}>Back</button>
</>
);
}

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

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

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>
);
15 changes: 11 additions & 4 deletions src/pages/CompanyPage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
function CompanyPage() {
import CompanyDetails from "../components/CompanyDetails";
import { useParams } from "react-router-dom";

function CompanyPage({ companies }) {
const { companySlug } = useParams();
const foundCompany = companies.find((oneCompany) => oneCompany.slug === companySlug);
return (
<div>
<h1>CompanyPage</h1>
</div>
<li className="company-details-container">
<h2>Company Profile</h2>
{!foundCompany && <h3>Error 404: the page not found!</h3>}
{foundCompany && <CompanyDetails company={foundCompany} />}
</li>
);
}

Expand Down
13 changes: 10 additions & 3 deletions src/pages/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
function HomePage() {
import CompanyCard from "../components/CompanyCard";

function HomePage({ companies }) {
return (
<div>
<h1>HomePage</h1>
<div id="homePage">
<h2>StackTracker: Discover Tech Stacks Used by Top Companies</h2>
<ul>
{companies.map((element) => (
<CompanyCard key={element.id} company={element} />
))}
</ul>
</div>
);
}
Expand Down
17 changes: 15 additions & 2 deletions src/pages/TechnologyPage.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
function TechnologyPage() {
import TechDetails from "../components/TechDetails";
import { useParams } from "react-router-dom";

function TechnologyPage({ technologies }) {
const { techSlug } = useParams();
const foundTech = technologies.find((oneTech) => oneTech.slug === techSlug);

return (
<div>
<h1>TechnologyPage</h1>
<h2>Technology Details</h2>
{!foundTech && (
<>
<h3>Error 404: the page not found!</h3>
<button onClick={() => window.history.back()}>back</button>
</>
)}
{foundTech && <TechDetails techStack={foundTech} />}
</div>
);
}
Expand Down