-
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.
created main page and filtering of countries
- Loading branch information
Michal Bartosik
committed
May 15, 2021
1 parent
33d9fbb
commit 849409a
Showing
28 changed files
with
5,309 additions
and
1,112 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest", | ||
"plugin:prettier/recommended", | ||
"prettier" | ||
], | ||
"plugins": ["prettier"], | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"es6": true | ||
}, | ||
"parser": "babel-eslint" | ||
} |
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,7 @@ | ||
{ | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true, | ||
"endOfLine": "auto", | ||
"arrowParens": "avoid" | ||
} |
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 @@ | ||
module.exports = { | ||
"stories": [ | ||
"../src/**/*.stories.mdx", | ||
"../src/**/*.stories.@(js|jsx|ts|tsx)" | ||
], | ||
"addons": [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/preset-create-react-app" | ||
] | ||
} |
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,10 @@ | ||
|
||
export const parameters = { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,24 @@ | ||
import styled from 'styled-components'; | ||
import { breakpoints } from 'styles/Breakpoints'; | ||
|
||
export const Wrapper = styled.div` | ||
background-color: var(--color-bg); | ||
min-height: 100vh; | ||
main { | ||
padding: 0 1rem; | ||
@media (min-width: ${breakpoints.desktop}) { | ||
max-width: 80rem; | ||
margin: 0 auto; | ||
} | ||
} | ||
`; | ||
|
||
export const Filters = styled.div` | ||
@media (min-width: ${breakpoints.desktop}) { | ||
display: flex; | ||
align-items: flex-start; | ||
justify-content: space-between; | ||
} | ||
`; |
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,5 +1,60 @@ | ||
import { GlobalStyles } from 'styles/GlobalStyles'; | ||
import { useState, useEffect } from 'react'; | ||
import Header from 'components/Header/Header'; | ||
import Search from 'components/Search/Search'; | ||
import Select from 'components/Select/Select'; | ||
import CountriesList from 'components/CountriesList/CountriesList'; | ||
import getCountries from './helpers/api'; | ||
import Country from 'models/Country'; | ||
import { Wrapper, Filters } from './App.styles'; | ||
|
||
function App() { | ||
return <h1>Hello</h1>; | ||
const [countries, setCountries] = useState<Country[]>([]); | ||
const [searchQuery, setSearchQuery] = useState<string>(''); | ||
const [selectedRegion, setSelectedRegion] = useState<string>('All'); | ||
const [filteredCountries, setFilteredCountries] = useState<Country[]>([]); | ||
|
||
useEffect(() => { | ||
getCountries().then(data => setCountries(data)); | ||
}, []); | ||
|
||
const handleSelectedItem = (target: any) => { | ||
setSelectedRegion(target.selectedItem); | ||
}; | ||
|
||
useEffect(() => { | ||
if (selectedRegion === 'All') { | ||
setFilteredCountries(countries); | ||
} else { | ||
setFilteredCountries( | ||
countries.filter(country => country.region === selectedRegion) | ||
); | ||
} | ||
}, [countries, selectedRegion]); | ||
|
||
return ( | ||
<Wrapper> | ||
<GlobalStyles /> | ||
<Header /> | ||
<main> | ||
<Filters> | ||
<Search | ||
setSearchQuery={setSearchQuery} | ||
placeholder="Search for a country..." | ||
/> | ||
<Select | ||
selectedRegion={selectedRegion} | ||
handleSelectedItem={handleSelectedItem} | ||
/> | ||
</Filters> | ||
<CountriesList | ||
searchQuery={searchQuery} | ||
selectedRegion={selectedRegion} | ||
countries={filteredCountries} | ||
/> | ||
</main> | ||
</Wrapper> | ||
); | ||
} | ||
|
||
export default App; |
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,9 @@ | ||
import styled from 'styled-components'; | ||
|
||
const CardWrapper = styled.div` | ||
background-color: var(--color-elements); | ||
border-radius: var(--border-radius); | ||
box-shadow: var(--card-box-shadow); | ||
`; | ||
|
||
export default CardWrapper; |
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,13 @@ | ||
import styled from 'styled-components'; | ||
import { breakpoints } from 'styles/Breakpoints'; | ||
|
||
const Container = styled.div` | ||
padding: 0 1rem; | ||
@media (min-width: ${breakpoints.desktop}) { | ||
max-width: 80rem; | ||
margin: 0 auto; | ||
} | ||
`; | ||
|
||
export default Container; |
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,28 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Wrapper = styled.div` | ||
padding: 3rem 1.5rem 0; | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
justify-content: center; | ||
gap: 2.5rem; | ||
@media (min-width: 42.375rem) { | ||
padding: 3rem 0; | ||
grid-template-columns: repeat(2, minmax(16.5rem, 1fr)); | ||
} | ||
@media (min-width: 62.5rem) { | ||
grid-template-columns: repeat(3, minmax(16.5rem, 1fr)); | ||
} | ||
@media (min-width: 80rem) { | ||
grid-template-columns: repeat(4, minmax(16.5rem, 1fr)); | ||
} | ||
`; | ||
|
||
export const NoResults = styled.p` | ||
text-align: center; | ||
font-size: 2rem; | ||
padding-top: 2rem; | ||
`; |
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,28 @@ | ||
import { Wrapper, NoResults } from './CountriesList.styles'; | ||
import CountryCard from 'components/CountryCard/CountryCard'; | ||
import Country from 'models/Country'; | ||
|
||
const CountriesList: React.FC<{ | ||
countries: Country[]; | ||
searchQuery: string; | ||
selectedRegion: string; | ||
}> = ({ countries, searchQuery }) => { | ||
if (searchQuery) { | ||
countries = countries.filter(country => | ||
country.name.toLowerCase().includes(searchQuery.toLowerCase()) | ||
); | ||
} | ||
if (!countries.length) { | ||
return <NoResults>No results found</NoResults>; | ||
} | ||
|
||
return ( | ||
<Wrapper> | ||
{countries.map((country: Country) => { | ||
return <CountryCard key={country.alpha3Code} {...country} />; | ||
})} | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default CountriesList; |
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,44 @@ | ||
import styled from 'styled-components'; | ||
import CardWrapper from 'components/CardWrapper/CardWrapper'; | ||
|
||
export const Container = styled(CardWrapper)` | ||
display: flex; | ||
flex-direction: column; | ||
box-shadow: 0 0 0.4375rem 0.125rem rgba(0, 0, 0, 0.03); | ||
`; | ||
export const FlagWrapper = styled.div` | ||
border-top-left-radius: var(--border-radius); | ||
border-top-right-radius: var(--border-radius); | ||
overflow: auto; | ||
flex-basis: 50%; | ||
overflow-y: hidden; | ||
img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
} | ||
`; | ||
|
||
export const CountryInfo = styled.div` | ||
background-color: var(--color-elements); | ||
padding: 1.5rem; | ||
border-bottom-left-radius: var(--border-radius); | ||
border-bottom-right-radius: var(--border-radius); | ||
color: var(--color-text); | ||
flex-basis: 50%; | ||
h2 { | ||
margin-bottom: 1rem; | ||
font-size: 1.125rem; | ||
font-weight: var(--fw-extra-bold); | ||
} | ||
ul { | ||
font-size: 0.875rem; | ||
padding: 0; | ||
} | ||
span { | ||
font-weight: var(--fw-semi-bold); | ||
} | ||
`; |
Oops, something went wrong.