-
Notifications
You must be signed in to change notification settings - Fork 0
Mini - Challenge 5 #4
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
base: Mini-Challenge-4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import React from 'react'; | ||
| import { useData } from '../../states/provider'; | ||
| import { ACTIONS } from '../../states/reducer'; | ||
| import Emoji from '../Emoji/Emoji'; | ||
| import Button from '../Button/Button'; | ||
| import Container, { Styled } from './Card.page.styled'; | ||
|
|
||
| function Card({ item }) { | ||
| const { videoId } = item.id; | ||
| const title = item?.snippet?.title ?? ''; | ||
| const description = item?.snippet?.description ?? ''; | ||
| const image = item?.snippet?.thumbnails?.default.url; | ||
| const width = item?.snippet?.thumbnails?.default?.width ?? 120; | ||
| const height = item?.snippet?.thumbnails?.default?.height ?? 90; | ||
| const { data, dispatch } = useData(); | ||
|
|
||
| function toggleFavoriteVideo() { | ||
| dispatch({ | ||
| type: data.favoriteVideoList.has(videoId) | ||
| ? ACTIONS.REMOVE_FROM_FAVORITES | ||
| : ACTIONS.ADD_TO_FAVORITES, | ||
| payload: { video: item }, | ||
| }); | ||
| } | ||
|
|
||
| function handleSelectVideo() { | ||
| const selectedVideo = item; | ||
|
|
||
| dispatch({ | ||
| type: ACTIONS.CHANGE_SELECTED_VIDEO, | ||
| payload: { | ||
| selectedVideo, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| return ( | ||
| <Container> | ||
| <center> | ||
| {' '} | ||
| <Button size="2em" onClick={toggleFavoriteVideo}> | ||
| <Emoji symbol={data.favoriteVideoList.has(videoId) ? '⭐' : '✰'} /> | ||
| </Button>{' '} | ||
| <Styled.Link to="/detailedVideo" onClick={handleSelectVideo}> | ||
| <h3>{title} </h3> | ||
| <img src={image} alt={title} width={width} height={height} /> | ||
| <p> {description}</p> | ||
| </Styled.Link> | ||
| </center> | ||
| </Container> | ||
| ); | ||
| } | ||
|
|
||
| export default Card; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import styled from 'styled-components'; | ||
| import { Link } from 'react-router-dom'; | ||
|
|
||
| const Container = styled.div` | ||
| width: 22%; | ||
| height: 20em; | ||
| border-style: solid; | ||
| margin: 1em; | ||
| border-radius: 1em; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| float: left; | ||
| background-color: #d47b7b; | ||
| text-overflow: ellipsis; | ||
| overflow: hidden; | ||
| `; | ||
|
|
||
| const StyledLink = styled(Link)` | ||
| text-decoration: 'none'; | ||
| `; | ||
|
|
||
| const Styled = { | ||
| Link: StyledLink, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can directly add this to the |
||
| }; | ||
|
|
||
| export { Styled }; | ||
| export default Container; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import React, { useState } from 'react'; | ||
| import Styled from './Login.styled'; | ||
| import { useData } from '../../states/provider'; | ||
| import { ACTIONS } from '../../states/reducer'; | ||
|
|
||
| function ModalLogin({ show }) { | ||
| const { data, dispatch } = useData(); | ||
| const [userName, setUserName] = useState(undefined); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving the |
||
| const [password, setPassword] = useState(undefined); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
| const [errorMessage, setErrorMessage] = useState(false); | ||
|
|
||
| function validateUserLogin() { | ||
| if (data.loginUser) { | ||
| show(false); | ||
| } else { | ||
| setErrorMessage('usuario Invalido'); | ||
| } | ||
| } | ||
|
|
||
| function handlerLogin() { | ||
| console.log(data); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to delete this for production or real-life scenarios 😝 . |
||
| if (userName && userName.trim().length > 0) { | ||
| if (password && password.trim().length > 0) { | ||
| dispatch({ | ||
| type: ACTIONS.LOGIN, | ||
| payload: { user: userName }, | ||
| }); | ||
|
|
||
| setTimeout(validateUserLogin, 300); | ||
| } else { | ||
| setErrorMessage('Please enter a password'); | ||
| } | ||
| } else { | ||
| setErrorMessage('Please enter a username'); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using an extra div here to suffice to React constraints of wrapping code in one container, you can use React Fragmens so that we don't necessarily add an extra node to the DOM. You can either say: <React.Fragment>
{your code here}
</React.Fragment>Or you can import Fragment from React: import { Fragment } from 'react';
...
<Fragment>
{your code here}
</Fragment>Or take advantage the syntactic sugar and use: <>
{your code here}
</> |
||
| {data.loginUser ? ( | ||
| '' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, instead of an empty string, it's better to use |
||
| ) : ( | ||
| <Styled.ModalBackground> | ||
| <Styled.ModalContent> | ||
| <Styled.CloseButton onClick={() => show(false)}> | ||
| × | ||
| </Styled.CloseButton> | ||
| <Styled.LoginForm> | ||
| <Styled.FormLabel htmlFor="uname"> | ||
| <b>Username</b> | ||
| </Styled.FormLabel> | ||
| <Styled.Input | ||
| type="text" | ||
| placeholder="Wizeline" | ||
| name="uname" | ||
| required | ||
| onChange={(event) => setUserName(event.target.value)} | ||
| /> | ||
|
|
||
| <Styled.FormLabel htmlFor="psw"> | ||
| <b>Password</b> | ||
| </Styled.FormLabel> | ||
| <Styled.Input | ||
| type="password" | ||
| placeholder="Not Empty Password" | ||
| name="psw" | ||
| required | ||
| onChange={(event) => setPassword(event.target.value)} | ||
| /> | ||
| <span>{errorMessage || ''}</span> | ||
|
|
||
| <Styled.LoginButton type="button" onClick={handlerLogin}> | ||
| Login | ||
| </Styled.LoginButton> | ||
| </Styled.LoginForm> | ||
| </Styled.ModalContent> | ||
| </Styled.ModalBackground> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default ModalLogin; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import styled from 'styled-components'; | ||
|
|
||
| const ModalBackground = styled.div` | ||
| display: block; | ||
| position: fixed; | ||
| z-index: 1; | ||
| left: 0; | ||
| top: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| overflow: auto; | ||
| background-color: rgb(0, 0, 0); | ||
| background-color: rgba(0, 0, 0, 0.4); | ||
| `; | ||
|
|
||
| const ModalContent = styled.div` | ||
| background-color: #2183d3; | ||
| margin: 15% auto; | ||
| padding: 20px; | ||
| border: 1px solid #888; | ||
| width: 30%; | ||
| border-radius: 1em; | ||
| border-style: solid 5px; | ||
| `; | ||
|
|
||
| const CloseButton = styled.span` | ||
| color: #aaa; | ||
| float: right; | ||
| font-size: 28px; | ||
| font-weight: bold; | ||
| &:hover, | ||
| &:focus { | ||
| color: black; | ||
| text-decoration: none; | ||
| cursor: pointer; | ||
| } | ||
| `; | ||
|
|
||
| const LoginForm = styled.div` | ||
| display: flex; | ||
| flex-direction: column; | ||
| `; | ||
|
|
||
| const FormLabel = styled.label` | ||
| margin: 10px 0; | ||
| `; | ||
|
|
||
| const Input = styled.input` | ||
| margin: 10px 0; | ||
| border-radius: 5px; | ||
| border: 1px solid black; | ||
| line-height: 1.5em; | ||
| padding: 5px; | ||
| `; | ||
|
|
||
| const LoginButton = styled.button` | ||
| border-radius: 5px; | ||
| border: 1px solid black; | ||
| padding: 10px; | ||
| margin: 10px 0; | ||
| cursor: pointer; | ||
| `; | ||
|
|
||
| const Styled = { | ||
| ModalBackground, | ||
| ModalContent, | ||
| CloseButton, | ||
| LoginForm, | ||
| FormLabel, | ||
| Input, | ||
| LoginButton, | ||
| }; | ||
|
|
||
| export default Styled; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './ModalLogin.component'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import React from 'react'; | ||
| import { Route, Switch } from 'react-router-dom'; | ||
|
|
||
| import HomePage from '../../pages/Home/Home.page'; | ||
| import FavoritePage from '../../pages/Favorites/Favorite.page'; | ||
| import ErrorPage from '../../pages/Error/Error.page'; | ||
| import VideoPage from '../../pages/Video/Video.page'; | ||
| import VideoListPage from '../../pages/VideoList/VideoList.page'; | ||
|
|
||
| export default function Routes() { | ||
| return ( | ||
| <> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A Fragment |
||
| <Switch> | ||
| <Route exact path="/" component={HomePage} /> | ||
| <Route path="/home" component={VideoListPage} /> | ||
| <Route path="/detailedVideo" component={VideoPage} /> | ||
| <Route path="/favorite" component={FavoritePage} /> | ||
| <Route path="/error" component={ErrorPage} /> | ||
| <Route path="*" component={ErrorPage} /> | ||
| </Switch> | ||
| </> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './Routes.component'; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good use of the extend styles feature from
styled-components!