-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/mini challenge4 #3
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: master
Are you sure you want to change the base?
Changes from all commits
fb7f23b
71cbcfc
7c4e9e7
2079dfe
34f9972
79f14bb
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 @@ | ||
| REACT_APP_API_KEY=AIzaSyCbnwRIBvWCoQGaLIOFUx4rhLHg-Sb1a8s | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| ------------------------------|----------|----------|----------|----------|-------------------| | ||
| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | | ||
| ------------------------------|----------|----------|----------|----------|-------------------| | ||
| All files | 61.61 | 50 | 50 | 62.16 | | | ||
| components/Account | 78.57 | 50 | 40 | 84.62 | | | ||
| index.jsx | 70 | 50 | 25 | 77.78 | 23,26 | | ||
| styled.js | 100 | 50 | 100 | 100 | 14 | | ||
| components/App | 0 | 100 | 0 | 0 | | | ||
| App.component.jsx | 0 | 100 | 0 | 0 | 14,15,17,18,19,23 | | ||
| components/Layout | 100 | 100 | 100 | 100 | | | ||
| index.jsx | 100 | 100 | 100 | 100 | | | ||
| styled.js | 100 | 100 | 100 | 100 | | | ||
| components/NavBar | 90.91 | 100 | 50 | 90.91 | | | ||
| index.jsx | 75 | 100 | 50 | 75 | 22 | | ||
| styled.js | 100 | 100 | 100 | 100 | | | ||
| components/SearchInput | 92.31 | 100 | 75 | 92.31 | | | ||
| index.jsx | 91.67 | 100 | 75 | 91.67 | 21 | | ||
| styled.js | 100 | 100 | 100 | 100 | | | ||
| components/SideMenu | 92.31 | 50 | 75 | 92.31 | | | ||
| index.jsx | 80 | 50 | 50 | 80 | 22 | | ||
| styled.js | 100 | 50 | 100 | 100 | 9,26 | | ||
| components/VideoCard | 100 | 100 | 100 | 100 | | | ||
| index.jsx | 100 | 100 | 100 | 100 | | | ||
| styled.js | 100 | 100 | 100 | 100 | | | ||
| components/VideoGrid | 100 | 100 | 100 | 100 | | | ||
| index.jsx | 100 | 100 | 100 | 100 | | | ||
| styled.js | 100 | 100 | 100 | 100 | | | ||
| components/VideosList | 0 | 0 | 0 | 0 | | | ||
| index.jsx | 0 | 0 | 0 | 0 | 5,6,9,13 | | ||
| components/VideosListElement | 0 | 100 | 0 | 0 | | | ||
| index.jsx | 0 | 100 | 0 | 0 | 4,5 | | ||
| styled.js | 0 | 100 | 0 | 0 | 3,9,10,20,26 | | ||
| lib | 100 | 50 | 100 | 100 | | | ||
| youTubeApi.js | 100 | 50 | 100 | 100 | 7,9 | | ||
| pages/Home | 100 | 100 | 100 | 100 | | | ||
| Home.page.jsx | 100 | 100 | 100 | 100 | | | ||
| styled.js | 100 | 100 | 100 | 100 | | | ||
| pages/Login | 0 | 100 | 0 | 0 | | | ||
| Login.page.jsx | 0 | 100 | 0 | 0 | 8,9,12,13,14,17 | | ||
| pages/VideoDetail | 0 | 0 | 0 | 0 | | | ||
| VideoDetail.page.jsx | 0 | 0 | 0 | 0 |... 20,21,23,24,27 | | ||
| index.js | 0 | 0 | 0 | 0 | | | ||
| styled.js | 0 | 100 | 100 | 0 | 3,7,18,27,31,38 | | ||
| ------------------------------|----------|----------|----------|----------|-------------------| |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import React from 'react'; | ||
| import { Link } from 'react-router-dom'; | ||
| import { AccountIcon, Dropdown, Button } from './styled'; | ||
| import { AUTH_STORAGE_KEY } from '../../utils/constants'; | ||
| import { storage } from '../../utils/storage'; | ||
| import { useAuth } from '../../providers/Auth'; | ||
|
|
||
| const Account = () => { | ||
| const { logout } = useAuth(); | ||
| const [openDrop, setOpenDrop] = React.useState(false); | ||
| const isLogged = storage.get(AUTH_STORAGE_KEY); | ||
| const logIn = ( | ||
| <Link to="/login"> | ||
| <span>LogIn</span> | ||
| </Link> | ||
| ); | ||
| const logOut = <Button onClick={() => logout()}>LogOut</Button>; | ||
|
Comment on lines
+11
to
+17
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. ❤️ cool - you can also move the JSX for logIn/out components to their own file and just import them here. |
||
|
|
||
| return ( | ||
| <div> | ||
| <AccountIcon | ||
| onClick={() => { | ||
| setOpenDrop(!openDrop); | ||
| }} | ||
| /> | ||
| <Dropdown openDrop={openDrop} onClick={() => setOpenDrop(!openDrop)}> | ||
| {isLogged ? logOut : logIn} | ||
| </Dropdown> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Account; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import styled from 'styled-components'; | ||
| import { AccountCircle } from '@styled-icons/material-outlined/AccountCircle'; | ||
|
|
||
| const AccountIcon = styled(AccountCircle)` | ||
| color: white; | ||
| width: 50px; | ||
| height: 50px; | ||
| float: right; | ||
| margin-left: 30px; | ||
| `; | ||
|
|
||
| const Dropdown = styled.ul` | ||
| position: absolute; | ||
| display: ${({ openDrop }) => (openDrop ? 'block' : 'none')}; | ||
| padding-inline-start: 0px; | ||
| background-color: lightgray; | ||
| padding: 8px; | ||
| margin-top: 40px; | ||
| `; | ||
|
|
||
| const Button = styled.button` | ||
| box-sizing: inherit; | ||
| background-color: transparent; | ||
| font-size: 19px; | ||
| color: white; | ||
| font-weight: bold; | ||
| border: none; | ||
| `; | ||
|
|
||
| export { AccountIcon, Dropdown, Button }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,56 @@ | ||
| import React, { useLayoutEffect } from 'react'; | ||
| import React, { useReducer } from 'react'; | ||
| import { BrowserRouter, Switch, Route } from 'react-router-dom'; | ||
|
|
||
| import AuthProvider from '../../providers/Auth'; | ||
| import NavBar from '../NavBar'; | ||
| import Layout from '../Layout'; | ||
| import HomePage from '../../pages/Home'; | ||
| import LoginPage from '../../pages/Login'; | ||
| import VideoDetailPage from '../../pages/VideoDetail'; | ||
| import NotFound from '../../pages/NotFound'; | ||
| import SecretPage from '../../pages/Secret'; | ||
| import Private from '../Private'; | ||
| import Fortune from '../Fortune'; | ||
| import Layout from '../Layout'; | ||
| import { random } from '../../utils/fns'; | ||
|
|
||
| function App() { | ||
| useLayoutEffect(() => { | ||
| const { body } = document; | ||
| import SearchWordContext from '../../state/SearchWordContext'; | ||
| import SearchWordReducer from '../../state/SearchWordReducer'; | ||
| import ThemeContext from '../../state/ThemeContext'; | ||
| import ThemeReducer from '../../state/ThemeReducer'; | ||
|
|
||
| function rotateBackground() { | ||
| const xPercent = random(100); | ||
| const yPercent = random(100); | ||
| body.style.setProperty('--bg-position', `${xPercent}% ${yPercent}%`); | ||
| } | ||
|
|
||
| const intervalId = setInterval(rotateBackground, 3000); | ||
| body.addEventListener('click', rotateBackground); | ||
|
|
||
| return () => { | ||
| clearInterval(intervalId); | ||
| body.removeEventListener('click', rotateBackground); | ||
| }; | ||
| }, []); | ||
| export default function App() { | ||
| const [videos, setVideos] = React.useState([]); | ||
| const [state, dispatch] = useReducer(SearchWordReducer, { | ||
| word: 'Wizeline', | ||
| }); | ||
| const [stateTheme, dispatchTheme] = useReducer(ThemeReducer, { | ||
| theme: { | ||
| navBar: '#3fc7cb', | ||
| content: 'white', | ||
| text: 'black', | ||
| }, | ||
| }); | ||
|
|
||
| return ( | ||
| <BrowserRouter> | ||
| <AuthProvider> | ||
| <Layout> | ||
| <Switch> | ||
| <Route exact path="/"> | ||
| <HomePage /> | ||
| </Route> | ||
| <Route exact path="/login"> | ||
| <LoginPage /> | ||
| </Route> | ||
| <Private exact path="/secret"> | ||
| <SecretPage /> | ||
| </Private> | ||
| <Route path="*"> | ||
| <NotFound /> | ||
| </Route> | ||
| </Switch> | ||
| <Fortune /> | ||
| </Layout> | ||
| <ThemeContext.Provider value={{ stateTheme, dispatchTheme }}> | ||
| <SearchWordContext.Provider value={{ state, dispatch }}> | ||
|
Comment on lines
+32
to
+33
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. It seems correctly coded but have a few questions for you to think about:
|
||
| <NavBar setVideos={setVideos} /> | ||
| <Layout> | ||
| <Switch> | ||
| <Route exact path="/login"> | ||
| <LoginPage /> | ||
| </Route> | ||
| <Route exact path="/"> | ||
| <HomePage videos={videos} /> | ||
| </Route> | ||
| <Route exact path="/:id"> | ||
| <VideoDetailPage videos={videos} /> | ||
| </Route> | ||
| <Route path="*"> | ||
| <NotFound /> | ||
| </Route> | ||
| </Switch> | ||
| </Layout> | ||
| </SearchWordContext.Provider> | ||
| </ThemeContext.Provider> | ||
| </AuthProvider> | ||
| </BrowserRouter> | ||
| ); | ||
| } | ||
|
|
||
| export default App; | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import Layout from '.'; | ||
|
|
||
| describe('Layout', () => { | ||
| const children = <h1>hello</h1>; | ||
|
|
||
| beforeEach(() => { | ||
| render(<Layout>{children}</Layout>); | ||
| }); | ||
|
|
||
| it('renders all children', () => { | ||
| const layout = screen.getByTestId('layout'); | ||
| expect(layout.children.length).toEqual(1); | ||
| expect(screen.getByText('hello').tagName).toBe('H1'); | ||
| }); | ||
| }); |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import React from 'react'; | ||
| import { Container } from './styled'; | ||
|
|
||
| function Layout({ children }) { | ||
| return ( | ||
| <Container className="container" data-testid="layout"> | ||
| {children} | ||
| </Container> | ||
| ); | ||
| } | ||
|
|
||
| export default Layout; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import styled from 'styled-components'; | ||
|
|
||
| const Container = styled.main` | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| align-items: center; | ||
| `; | ||
|
|
||
| export { Container }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React from 'react'; | ||
| import { BrowserRouter } from 'react-router-dom'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import NavBar from '.'; | ||
| import AuthProvider from '../../providers/Auth'; | ||
|
|
||
| describe('NavBar', () => { | ||
| beforeEach(() => { | ||
| render( | ||
| <BrowserRouter> | ||
| <AuthProvider> | ||
| <NavBar /> | ||
| </AuthProvider> | ||
| </BrowserRouter> | ||
| ); | ||
| }); | ||
|
|
||
| it('renders NavBar and its elements', () => { | ||
| const navBar = screen.getByTestId('navBar'); | ||
| expect(navBar.children.length).toEqual(1); | ||
| const navContent = screen.getByTestId('navContent'); | ||
| expect(navContent.children.length).toEqual(4); | ||
| }); | ||
| }); |
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.
Now that you're using dotenv, this
.envfile is not intended to be uploaded into your repo. Otherwise the API key is still public and we want to avoid it.You can, for example, have a
.env.examplefile with the variables but not values like:Then keep
.envfile locally for you only. You can have it listed at the.gitignorefor not allowing anyone in the team to push it into the repository accidentally.