Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test task #2

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Anton Romankov
17,388 changes: 17,388 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "zyfra-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"react": "next",
"react-dom": "next",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.3",
"styled-components": "^4.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Binary file added public/favicon.ico
Binary file not shown.
Binary file added public/img/25.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>React App</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>

</html>
68 changes: 68 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from 'react';
import Activity from './components/activities';
EvgenyOrekhov marked this conversation as resolved.
Show resolved Hide resolved
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
import styled from 'styled-components';
import FilteredActivites from './components/filteredActivites';
import GlobalStyle, {Container} from './components/commonData';

const Nav = styled.nav`
background-color: #3F4045;
`
const Ul = styled.ul`
display: flex;
justify-content: center;
`
const Li = styled.li`
padding: 0 20px;
&:first-child{
padding-left: 0;
}
&:last-child{
padding-right: 0;
}
&:not(:last-child){
border-right: 1px dotted #F4F4F8;
}
a{
color: #F4F4F8;
transition: all .3s;
font-weight: 700;

&:hover{
color: #5BC0BE;
}
}
`
const Centered = styled.div`
text-align: center;
`

const App = () => (
<Router>
<>
<GlobalStyle />
<Nav>
<Container>
<Ul>
<Li>
<Link to="/">Random activity</Link>
</Li>
<Li>
<Link to="/filter/">Filtered activity</Link>
</Li>
</Ul>
</Container>
</Nav>
<main>
<Container>
<Centered>
<Route path="/" exact render={() => <Activity />} />
<Route path="/filter/" component={FilteredActivites} />
</Centered>
</Container>
</main>
</>
</Router>
);

export default App;
97 changes: 97 additions & 0 deletions src/components/Activities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { useState } from 'react';
import axios from 'axios';
import styled from 'styled-components';
import { Button, Headline, ContainerInnerWrap, ActivityContent } from './commonData';
import { BrowserRouter as Link } from "react-router-dom";

const PreambulaText = styled.div`
line-height: 26px;
margin-bottom: 20px;
margin: 0 auto;
margin-bottom: 20px;
`
const Modal = styled.div`
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0,0,0,0.75);
position: absolute;
top: 0;
left: 0;
z-index: 10;

.modal{
padding: 20px;
background-color: #F4F4F8;
width: 335px;
height: 300px;
display: flex;
flex-direction: column;
justify-content: space-between;
border-radius: 10px;

h3{
font-size: 20px;
font-weight: 700;
}

p{
line-height: 24px;
}

&-buttons{
display: flex;
justify-content: center;
}
}
`
function Activity() {
const [data, setData] = useState({});
let [clickCount, setClickCount] = useState(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему let, а не const?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно копипаст... Исправил.

let [modalOpened, setModalOpened] = useState(false);

async function getRandomActivity() {
const result = await axios(
'http://www.boredapi.com/api/activity/'
);
setData(result.data);
setClickCount(clickCount + 1);
if ((clickCount % 5) === 0) {
setModalOpened(true);
}
}
function modalClose() {
setModalOpened(false);

}

return (
<>
<ContainerInnerWrap>
<Headline>WhattodoApp</Headline>
<PreambulaText>{Object.keys(data).length === 0 ? `Don't know what to do? We'll help you! Just click the button and you'll see the possible variant for your vocation...` : `Don't like that? Click... ;-)`}</PreambulaText>
<Button onClick={getRandomActivity} style={{ marginBottom: '20px' }}>Random</Button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для стилизации лучше использовать какой-то один способ. Если это styled-components, то все стили должны объявляться с помощью styled-components.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ОК, учту. Но как быть в том случае, если в одном месте одному элементу нужно задать отступ? Делать новый компонент по аналогии с этим?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да.


<ActivityContent data={data} />
</ContainerInnerWrap>
<Modal className={modalOpened ? null : 'display-none'} id='modal' >
<div className="modal">
<h3>You found {clickCount-1} activities</h3>
<p>Still don't know what to choose? Maybe filters help you...</p>
<div className="modal-buttons">
<div className='col-1-of-2'>
<button className='btn btn-small' onClick={modalClose}>Cancel</button>
</div>
<div className="col-1-of-2">
<Link to="/filter/" className='btn btn-small'>Try!</Link>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно обойтись без глобальных CSS-классов, воспользовавшись свойством as у styled-components: https://www.styled-components.com/docs/basics#extending-styles (второй пример).

В случае с Button и Link можно сделать так:

const Button = styled.button`
    /* ...styles... */
`;
const SmallButton = styled(Button)`
    /* ...more styles... */
`;

<SmallButton>Cancel</SmallButton>
<SmallButton as={Link} to="/filter/">Try!</SmallButton>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Окей, учту на будущее.

</div>
</div>
</div>
</Modal>
</>
)
}

export default Activity;
Loading