-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor fetches and create a reusable fetch method * Refactor fetching data for filters and getting unique cities values * Debounce window resizing on list page * Add .idea directory to gitignore * Fetch cities and locations data together and resolve the promise after both promises has been returned * Extract Helmet metadata component to a separate one * Move setting loading indicators after the promise has been resolved * Add .env.example file
- Loading branch information
1 parent
0b1f0f7
commit d5fda0b
Showing
14 changed files
with
164 additions
and
199 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
secrets.txt | ||
*.env | ||
.idea/ |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
REACT_APP_GEOAPIFY_API_KEY= | ||
REACT_APP_API_URL= | ||
REACT_APP_NAME= | ||
REACT_APP_CONTACT_MAIL= | ||
REACT_APP_GOOGLE_ANALYTICS_TRACKING_ID= | ||
REACT_APP_DATA_SOURCE_UPDATE_DATE= |
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,19 +1,16 @@ | ||
import axios from "axios"; | ||
import { fetchFromApi } from './fetcher'; | ||
|
||
export interface getCitiesResponse { | ||
city: string; | ||
voivodeship: string; | ||
} | ||
|
||
const API_URL = process.env.REACT_APP_API_URL; | ||
|
||
export const getCities = async (): Promise<getCitiesResponse[]> => { | ||
const url = `${process.env.REACT_APP_API_URL}/cities`; | ||
const res = await axios.get(url); | ||
if (res.status !== 200) { | ||
throw new Error('Failed to fetch cities'); | ||
} | ||
const url = `${API_URL}/cities`; | ||
|
||
const data = res.data as getCitiesResponse[]; | ||
return data; | ||
return fetchFromApi<getCitiesResponse[]>(url); | ||
} | ||
|
||
export { } | ||
export { } |
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,15 +1,12 @@ | ||
import axios from "axios"; | ||
import { fetchFromApi } from './fetcher'; | ||
import { LocationResponse } from "../shared/nursery.interface"; | ||
|
||
const API_URL = process.env.REACT_APP_API_URL; | ||
|
||
export const getLocations = async (): Promise<LocationResponse[]> => { | ||
const url = `${process.env.REACT_APP_API_URL}/locations`; | ||
const res = await axios.get(url); | ||
if (res.status !== 200) { | ||
throw new Error('Failed to fetch locations'); | ||
} | ||
|
||
const data = res.data as LocationResponse[]; | ||
return data; | ||
const url = `${API_URL}/locations`; | ||
|
||
return fetchFromApi<LocationResponse[]>(url); | ||
} | ||
|
||
export { } |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import axios from "axios"; | ||
|
||
export const fetchFromApi = async <T>(url: string, params?: object): Promise<T> => { | ||
const { data, status } = await axios.get<T>(url, { params }); | ||
|
||
if (status !== 200) { | ||
throw new Error(`Failed to fetch data from ${url}. Status: ${status}`); | ||
} | ||
|
||
return data; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Helmet } from "react-helmet-async"; | ||
|
||
interface MetadataProps { | ||
title: string; | ||
description?: string; | ||
image: string; | ||
url?: string; | ||
} | ||
|
||
export default function Metadata({ title, description, image, url }: MetadataProps) { | ||
return ( | ||
<Helmet> | ||
<title>{title}</title> | ||
<meta name="description" content={description} /> | ||
<meta property="og:title" content={title} /> | ||
<meta property="og:description" content={description} /> | ||
<meta property="og:image" content={image} /> | ||
<meta property="og:url" content={url} /> | ||
<meta name="twitter:title" content={title} /> | ||
<meta name="twitter:description" content={description} /> | ||
<meta name="twitter:image" content={image} /> | ||
<meta name="twitter:card" content="summary_large_image" /> | ||
</Helmet> | ||
) | ||
}; |
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
Oops, something went wrong.