Skip to content

Commit

Permalink
feat: rebuild Location page
Browse files Browse the repository at this point in the history
Resolves #414

- chore: ignore declaration-block-no-redundant-longhand-properties
  Stylelint rule due to low-priority issue.
- refactor: restructure components
- test: add basic LocationPage tests
- fix: correct static asset paths
- refactor: rename LocationOverview and review-overview to LocationDetails
- fix: pass location id only state to LocationPage and load locations data
  on LocationPage
- refactor: use map for initial locations data structure for easy lookups
  on LocationPage
- refactor: alias Window Location `WindowLocation` to prevent conclicts with
  Sparkeats `Location`
- refactor: update imageURL logic to differentiate Review and Location image placeholders.
- refactor: use useLocations hook
  • Loading branch information
yosevu committed Nov 5, 2022
1 parent d4cfe8f commit 8f46062
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 66 deletions.
5 changes: 4 additions & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"extends": [
"stylelint-config-standard-scss",
"stylelint-config-prettier-scss"
]
],
"rules": {
"declaration-block-no-redundant-longhand-properties": null
}
}
File renamed without changes.
32 changes: 32 additions & 0 deletions cypress/e2e/LocationPage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference types="cypress" />

export {};

context('Given a user is on the Location page', () => {
const baseUrl = Cypress.config('baseUrl');
context('When the user clicks the "Back to home" link', () => {
specify('Then the user is directed to the Home page', () => {
cy.visit('/');
cy.findByRole('heading', {
name: /Basil's on Market/,
}).click();
cy.findByRole('link', {
name: /Back to home/,
}).click();
cy.url().should('eq', baseUrl);
});
});

context('When the user clicks the "Add a review" link', () => {
specify('Then the user is directed to the Home page', () => {
cy.visit('/');
cy.findByRole('heading', {
name: /Basil's on Market/,
}).click();
cy.findByRole('link', {
name: /Add a review/,
}).click();
cy.url().should('eq', `${baseUrl}reviews/new`);
});
});
});
28 changes: 14 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,63 @@
<link
rel="apple-touch-icon-precomposed"
sizes="57x57"
href="apple-touch-icon-57x57.png"
href="/apple-touch-icon-57x57.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="60x60"
href="apple-touch-icon-60x60.png"
href="/apple-touch-icon-60x60.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="72x72"
href="apple-touch-icon-72x72.png"
href="/apple-touch-icon-72x72.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="76x76"
href="apple-touch-icon-76x76.png"
href="/apple-touch-icon-76x76.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="114x114"
href="apple-touch-icon-114x114.png"
href="/apple-touch-icon-114x114.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="120x120"
href="apple-touch-icon-120x120.png"
href="/apple-touch-icon-120x120.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="144x144"
href="apple-touch-icon-144x144.png"
href="/apple-touch-icon-144x144.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="152x152"
href="apple-touch-icon-152x152.png"
href="/apple-touch-icon-152x152.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="180x180"
href="apple-touch-icon-180x180.png"
href="/apple-touch-icon-180x180.png"
/>
<link
rel="icon"
type="image/png"
sizes="196x196"
href="favicon-196x196.png"
href="/favicon-196x196.png"
/>
<link
rel="icon"
type="image/png"
sizes="128x128"
href="favicon-128x128.png"
href="/favicon-128x128.png"
/>
<link rel="icon" type="image/png" sizes="96x96" href="favicon-96x96.png" />
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png" />
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Oswald:400,700|Roboto+Condensed:300,400,700|Roboto:400,700,900&amp;display=swap"
Expand Down
2 changes: 1 addition & 1 deletion src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
@import 'scss/components/location-card';
@import 'scss/components/stars';
@import 'scss/components/footer';
@import 'scss/components/review-overview';
@import 'scss/components/review-details';
@import 'scss/components/review-header';
@import 'scss/components/review-nav';
@import 'scss/components/review-submission';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const LocationCardImage = ({ location }: { location: Location }) => {
<Link
to={location.locationURL}
aria-label={`review page for ${location.name}`}
state={{ id: location.id }}
>
<img
className="location-card__image"
Expand All @@ -25,7 +26,7 @@ const LocationHeading = ({ location }: { location: Location }) => {
<Link
className="location-card__name-link"
to={location.locationURL}
state={{ location }}
state={{ id: location.id }}
>
{location.name}
</Link>
Expand All @@ -39,11 +40,11 @@ const LocationHeading = ({ location }: { location: Location }) => {

const LocationAddress = ({ location }: { location: Location }) => {
return (
<address className="review-overview__address">
<address className="review-details__address">
<p>{location.address}</p>
{location.phone && (
<p>
<a className="review-overview__phone" href={`tel:${location.phone}`}>
<a className="review-details__phone" href={`tel:${location.phone}`}>
{location.phone}
</a>
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { LocationCard } from './LocationCard';
import type { Location } from '../../types/sparkeats';
import type { Locations } from '../../types/sparkeats';

export function LocationCards({ locations }: { locations: Location[] }) {
export function LocationCards({ locations }: { locations: Locations }) {
return (
<section className="homepage__cards">
<ul className="location-card__list">
{locations.map((location) => (
{Object.values(locations).map((location) => (
<LocationCard key={location.id} location={location} />
))}
</ul>
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions src/components/LocationPage/LocationDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Location } from '../../types/sparkeats';

function LocationAddress({ location }: { location: Location }) {
return (
<>
<address className="review-details__address">
<p>{location?.address}</p>
</address>
{location?.phone && (
<p>
<a className="review-details__phone" href={`tel:${location?.phone}`}>
{location?.phone}
</a>
</p>
)}
{location?.url && (
<p>
<a className="location-card__url" href={`${location?.url}`}>
Visit Site
</a>
</p>
)}
</>
);
}

export function LocationDetails({ location }: { location: Location }) {
return (
<section className="review-details">
<header>
<h1 className="review-details__title">{location.reviewCountText}</h1>
<div className="review-details__stars">Average Stars</div>
</header>
<LocationAddress location={location} />
</section>
);
}
15 changes: 15 additions & 0 deletions src/components/LocationPage/LocationHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Location } from '../../types/sparkeats';

export function LocationHeader({ location }: { location: Location }) {
return (
<div className="review-header">
<div className="review-header__title">
<h2 className="review-header__name">{location.name}</h2>
<p className="review-header__city">
{location.city}, {location.region}
</p>
</div>
<div className="review-header__backdrop"></div>
</div>
);
}
48 changes: 48 additions & 0 deletions src/components/LocationPage/LocationReviews.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Link } from 'react-router-dom';
import { Location, Review } from '../../types/sparkeats';

export function LocationReviews({
location,
reviews = [],
}: {
location: Location;
reviews: Review[];
}) {
return (
<div className="review-container">
<Link
className="button__full-width"
to={'/reviews/new'}
state={{ location }}
>
Add a review
</Link>

{reviews.map((review: Review) => (
<article key={review.id} className="review-submission">
<h3 className="review-submission__reviewer">{review.reviewerName}</h3>
<div className="review-submission__date">
{/* Created year/month/day*/}
</div>
<div
className="location-card__star-rating"
aria-label={`${review.starRating}`}
>
Stars
</div>
<h4 className="review-submission__title">Comments</h4>
<p className="review-submission__review">{review.text}</p>
{review.imageURL && (
<div className="review-submission__image-container">
<img
className="review-submission__image"
src={review.imageURL}
alt={review.imageDescription}
/>
</div>
)}
</article>
))}
</div>
);
}
30 changes: 30 additions & 0 deletions src/components/LocationPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useLocation as useWindowLocation } from 'react-router-dom';
import { Link } from 'react-router-dom';
import { LocationHeader } from './LocationHeader';
import { LocationDetails } from './LocationDetails';
import { LocationReviews } from './LocationReviews';
import { useLocations } from '../../useLocations';

export function LocationPage() {
const {
state: { id },
} = useWindowLocation();

const locations = useLocations();

const location = locations[id];

return (
<main className="review-page">
<div className="review-nav">
<Link className="review-nav__link" to={'/'}>
<span className="review-nav__svg"></span>
Back to home
</Link>
</div>
<LocationHeader location={location} />
<LocationReviews location={location} reviews={location.reviews} />
<LocationDetails location={location} />
</main>
);
}
Loading

0 comments on commit 8f46062

Please sign in to comment.