Skip to content

Commit

Permalink
created main page and filtering of countries
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Bartosik committed May 15, 2021
1 parent 33d9fbb commit 849409a
Show file tree
Hide file tree
Showing 28 changed files with 5,309 additions and 1,112 deletions.
15 changes: 15 additions & 0 deletions .eslintrc
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"
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"endOfLine": "auto",
"arrowParens": "avoid"
}
11 changes: 11 additions & 0 deletions .storybook/main.js
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"
]
}
10 changes: 10 additions & 0 deletions .storybook/preview.js
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$/,
},
},
}
48 changes: 47 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,57 @@
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/styled-components": "^5.1.9",
"axios": "^0.21.1",
"downshift": "^6.1.3",
"prettier": "^2.3.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"styled-components": "^5.3.0",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"lint": "eslint --fix --ext .jsx,.js,.ts,.tsx .",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public"
},
"resolutions": {
"babel-loader": "8.1.0"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"overrides": [
{
"files": [
"**/*.stories.*"
],
"rules": {
"import/no-anonymous-default-export": "off"
}
}
]
},
"lint-staged": {
"src/**/*.{ts,tsx,js,jsx,json}": [
"prettier --write"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"browserslist": {
"production": [
">0.2%",
Expand All @@ -39,5 +72,18 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@storybook/addon-actions": "^6.2.9",
"@storybook/addon-essentials": "^6.2.9",
"@storybook/addon-links": "^6.2.9",
"@storybook/node-logger": "^6.2.9",
"@storybook/preset-create-react-app": "^3.1.7",
"@storybook/react": "^6.2.9",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^6.0.0",
"lint-staged": "^11.0.0"
}
}
Binary file added public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/favicon.ico
Binary file not shown.
22 changes: 11 additions & 11 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link
rel="icon"
type="image/png"
sizes="32x32"
href="./favicon-32x32.png"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
Expand All @@ -24,20 +29,15 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@300;600;800&display=swap"
rel="stylesheet"
/>
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
24 changes: 24 additions & 0 deletions src/App.styles.ts
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;
}
`;
57 changes: 56 additions & 1 deletion src/App.tsx
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;
9 changes: 9 additions & 0 deletions src/components/CardWrapper/CardWrapper.tsx
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;
13 changes: 13 additions & 0 deletions src/components/Container/Container.tsx
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;
28 changes: 28 additions & 0 deletions src/components/CountriesList/CountriesList.styles.ts
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;
`;
28 changes: 28 additions & 0 deletions src/components/CountriesList/CountriesList.tsx
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;
44 changes: 44 additions & 0 deletions src/components/CountryCard/CountryCard.styles.ts
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);
}
`;
Loading

0 comments on commit 849409a

Please sign in to comment.