Skip to content

Commit

Permalink
fix: update location data
Browse files Browse the repository at this point in the history
  • Loading branch information
yosevu committed Dec 5, 2022
1 parent 9714272 commit 9b6294b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/components/HomeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Link } from 'react-router-dom';
import SiteSubtitle from './SiteSubtitle';
import LocationMenu from './LocationMenu';

function HomeHeader({ uniqueCities }: { uniqueCities: string[] }) {
function HomeHeader() {
return (
<div className="home-header">
<SiteSubtitle />

<LocationMenu uniqueCities={uniqueCities} />
<LocationMenu />

<div className="home-header__button">
<Link className="button__header-primary" to="/locations/new">
Expand Down
5 changes: 2 additions & 3 deletions src/components/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import HomeHeader from '../HomeHeader';
import { LocationCards } from './LocationCards';
import { useLocations } from '../../useLocations';

export function HomePage({ uniqueCities }: { uniqueCities: string[] }) {

export function HomePage() {
const locations = useLocations();

return (
<div className="homepage">
<HomeHeader uniqueCities={uniqueCities} />
<HomeHeader />
<LocationCards locations={locations} />
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/LocationMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function LocationMenu({ uniqueCities }: { uniqueCities: string[] }) {
import { uniqueCities } from '../locations';

function LocationMenu() {
return (
<div className="location-select">
<h2 className="location-select__title">
Expand Down
6 changes: 4 additions & 2 deletions src/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ function transformLocations(legacyPlaces: LegacyPlace[]): Locations {
.reduce(mapLocation, {});
}

function getUniqueCities(locations: Location[]): string[] {
return Array.from(new Set(locations.map((location) => location.city)));
function getUniqueCities(locations: Locations): string[] {
return Array.from(
new Set(Object.values(locations).map((location) => location.city))
);
}

const locations = transformLocations(legacyPlaces);
Expand Down
15 changes: 4 additions & 11 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BrowserRouter, Routes, Route } from 'react-router-dom';
import { App } from './App';
import { HomePage } from './components/HomePage';
import { LocationPage } from './components/LocationPage';
import { locations, uniqueCities } from './locations';

window.__SPARKEATS_VERSION__ = import.meta.env['VITE_SPARKEATS_VERSION'];

Expand All @@ -14,17 +13,11 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<Routes>
<Route path="/" element={<App />}>
<Route path="/" element={<HomePage />} />
<Route
path="/"
element={
<HomePage locations={locations} uniqueCities={uniqueCities} />
}
/>
<Route path="/locations/:id" element={<LocationPage />} />
<Route path="/locations/new" element={<div>New Location Page</div>} />
<Route path="/reviews/new" element={<div>New Review Page</div>} />
</Route >
</Routes >
</BrowserRouter >
</React.StrictMode >
</Route>
</Routes>
</BrowserRouter>
</React.StrictMode>
);

0 comments on commit 9b6294b

Please sign in to comment.