-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#38 - Removed the hard coded companies list and added a fetch request…
… to dynamically render all companies from server. When companies clicked should now navigate to specific company based on ID. - Made one small change to company controller getCompany function Co-authored-by: Angel Morris <angel.morris920@gmail.com>
- Loading branch information
1 parent
21a1880
commit cc4e037
Showing
4 changed files
with
58 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,36 @@ | ||
import { useState, useEffect } from 'react' | ||
import './companyListing.css' | ||
import { Link } from 'react-router' | ||
|
||
const CompanyListing = () => { | ||
return ( | ||
<section className="company-grid"> | ||
<div className="company-card"><a href='/company'>Amazon</a></div> | ||
<div className="company-card"><a href='/company'>Microsoft</a></div> | ||
<div className="company-card"><a href='/company'>Google</a></div> | ||
<div className="company-card"><a href='/company'>Meta</a></div> | ||
<div className="company-card"><a href='/company'>Apple</a></div> | ||
<div className="company-card"><a href='/company'>Salesforce</a></div> | ||
<div className="company-card"><a href='/company'>Intel</a></div> | ||
<div className="company-card"><a href='/company'>Uber</a></div> | ||
<div className="company-card"><a href='/company'>Capital One</a></div> | ||
<div className="company-card"><a href='/company'>LinkedIn</a></div> | ||
<div className="company-card"><a href='/company'>JPMorgan Chase</a></div> | ||
<div className="company-card"><a href='/company'>Walmart</a></div> | ||
<div className="company-card"><a href='/company'>Goldman Sachs</a></div> | ||
<div className="company-card"><a href='/company'>Deloitte</a></div> | ||
<div className="company-card"><a href='/company'>KPMG</a></div> | ||
<div className="company-card"><a href='/company'>Tesla</a></div> | ||
<div className="company-card"><a href='/company'>Netflix</a></div> | ||
<div className="company-card"><a href='/company'>Bank of America</a></div> | ||
<div className="company-card"><a href='/company'>EY</a></div> | ||
<div className="company-card"><a href='/company'>Morgan Stanley</a></div> | ||
</section> | ||
const [companies, setCompanies] = useState([]) | ||
|
||
useEffect(() => { | ||
const fetchCompanies = async () => { | ||
try { | ||
const response = await fetch('/api/company') | ||
console.log({ response }) | ||
if (!response.ok) throw new Error('Failed to fetch companies.') | ||
|
||
const data = await response.json() | ||
console.log(data.companies) | ||
setCompanies(data.companies) | ||
} catch (error) { | ||
console.error('Error fetching companies:', error) | ||
} | ||
} | ||
|
||
fetchCompanies() | ||
}, []) | ||
return ( | ||
<section className="company-grid"> | ||
{companies.map((company) => ( | ||
<div className="company-card" key={company._id}> | ||
<Link to={`/company/${company._id}`}>{company.name}</Link> | ||
</div> | ||
))} | ||
</section> | ||
) | ||
} | ||
|
||
export default CompanyListing | ||
export default CompanyListing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters