Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_API_YOUTUBE_KEY = AIzaSyAOsyZMq5msH04OZ9W7Y_fQX--TictP_v8

Choose a reason for hiding this comment

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

I recommend to not keep track of this file, it is a good practice to create a .env file but also not keeping track of this file.

35,710 changes: 35,710 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^10.4.9",
"@testing-library/user-event": "^12.1.3",
"axios": "^0.21.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^4.2.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3"
"react-scripts": "3.4.3",
"styled-components": "^5.2.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
58 changes: 0 additions & 58 deletions src/components/App/App.component.jsx

This file was deleted.

36 changes: 36 additions & 0 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useReducer } from 'react';
import NavBar from '../NavBar';
import HomePage from '../../pages/Home';
import SearchContext from '../../state/SearchContext';
import SearchReducer from '../../state/SearchReducer';
import LocalThemeProvider from '../../state/ThemeContext.provider';

function App() {
// const [search, setSearch] = useState('Wizeline');

Choose a reason for hiding this comment

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

I recommend removing all commented code so it won't be kept commented in the future.

const [state, dispatch] = useReducer(SearchReducer, {
search: 'Wizeline',
});

const handleSearch = (e) => {
const searchValue = e.target.value;
dispatch({
type: 'SEARCH_VIDEOS',
payload: {
search: searchValue,
},
});
};

return (
<div>
<LocalThemeProvider>
<SearchContext.Provider value={{ state, dispatch }}>
<NavBar search={handleSearch} />

Choose a reason for hiding this comment

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

I would use the context inside the NavBar itself instead of creating a function and then send it to the component. The prop drilling is not being removed even with the usage of a Context. One of the usages of the context is to remove prop drilling

<HomePage />
</SearchContext.Provider>
</LocalThemeProvider>
</div>
);
}

export default App;
2 changes: 1 addition & 1 deletion src/components/App/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './App.component';
export { default } from './App';
12 changes: 0 additions & 12 deletions src/components/Fortune/Fortune.component.jsx

This file was deleted.

5 changes: 0 additions & 5 deletions src/components/Fortune/Fortune.styles.css

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Fortune/index.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/components/InputSearch/InputSearch.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import styled from 'styled-components';

const InputSearchStyled = styled.div`
margin-left: 50px;
`;

export default function InputSearch({ search }) {
return (
<InputSearchStyled>
<input type="text" placeholder="Search" onChange={search} />
</InputSearchStyled>
);
}
Empty file.
1 change: 1 addition & 0 deletions src/components/InputSearch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './InputSearch';
9 changes: 0 additions & 9 deletions src/components/Layout/Layout.component.jsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/Layout/Layout.styles.css

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Layout/index.js

This file was deleted.

24 changes: 24 additions & 0 deletions src/components/NavBar/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { FcManager } from 'react-icons/fc';
import styled from 'styled-components';
import InputSearch from '../InputSearch';

const NavBarStyled = styled.div`
background-color: ${(props) => props.theme.primary};
display: flex;
align-items: center;
justify-content: space-between;
`;
Comment on lines +6 to +11

Choose a reason for hiding this comment

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

I recommend taking out the style from the logic of the components


function NavBar({ search }) {

Choose a reason for hiding this comment

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

I also recommend using the context hook to obtain the search value instead of using prop drilling to obtain the value.

return (
<NavBarStyled>
<InputSearch search={search} />
<div>
<FcManager size="60" />
</div>
</NavBarStyled>
);
}

export default NavBar;
1 change: 1 addition & 0 deletions src/components/NavBar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './NavBar';
14 changes: 0 additions & 14 deletions src/components/Private/Private.component.jsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Private/index.js

This file was deleted.

21 changes: 21 additions & 0 deletions src/components/VideoCard/VideoCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { Container, Title } from './VideoCard.styles';

const VideoCard = ({ video, handleVideoSelected }) => {

Choose a reason for hiding this comment

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

handleVideoSelected could be abstracted into the context and be used inside the component using a hook.

console.log(`Hello;${video}`);
return (
<Container>
<div role="button">
<img alt={video.snippet.description} src={video.snippet.thumbnails.default.url} />
<div>
<Title>{video.snippet.title}</Title>
</div>
</div>
<button type="button" onClick={() => handleVideoSelected(video)}>
View details
</button>
</Container>
);
};

export default VideoCard;
16 changes: 16 additions & 0 deletions src/components/VideoCard/VideoCard.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import styled from 'styled-components';

export const Container = styled.div`
border-bottom: 1px solid #cccccc;
border-radius: 5px;
padding: 20px;
text-align: left;
:hover {
background-color: ${(props) => props.theme.primary};
color: ${(props) => props.theme.text};
}
`;

export const Title = styled.div`
color: ${(props) => props.theme.textcolor};
`;
1 change: 1 addition & 0 deletions src/components/VideoCard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './VideoCard';
36 changes: 36 additions & 0 deletions src/components/VideoDetail/VideoDetail.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import styled from 'styled-components';

const VideoStyled = styled.div`
.video {
margin-top: 50px;
width: 100%;
height: 300px;
}
`;
const Title = styled.h4`
color: ${(props) => props.theme.textcolor};
`;
Comment on lines +4 to +13

Choose a reason for hiding this comment

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

I recommend to abstract always the CSS styles from the components


const VideoDetail = ({ video }) => {
if (!video) {
return (
<div>
<Title>Select a video</Title>
</div>
);
}
const videoSrc = `https://www.youtube.com/embed/${video.id.videoId}`;
return (
<VideoStyled>
<iframe className="video" src={videoSrc} title="Video" />

<div>
<Title>{video.snippet.title}</Title>
<Title>{video.snippet.description}</Title>
</div>
</VideoStyled>
);
};

export default VideoDetail;
1 change: 1 addition & 0 deletions src/components/VideoDetail/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './VideoDetail';
24 changes: 24 additions & 0 deletions src/components/VideoList/VideoList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import styled from 'styled-components';
import VideoCard from '../VideoCard';

const VideoListContainer = styled.div`
text-align: center;
`;
Comment on lines +5 to +7

Choose a reason for hiding this comment

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

Removing CSS styling from components


export default function VideoList({ videos, handleVideoSelected }) {

Choose a reason for hiding this comment

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

Instead of using prop drilling with handleVideoSelected use the context API from react

if (!videos) {
return <div />;
}

const renderedVideos = videos.map((video) => {
return (
<VideoCard
key={Math.random()}

Choose a reason for hiding this comment

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

And instead of using a Math.random() you could use something unique from the video. i.e. the etag from the video or the title itself. It is not a good practice because every re-render the Math.random() would change and the key performance won't work.

video={video}
handleVideoSelected={handleVideoSelected}
/>
);
});
return <VideoListContainer>{renderedVideos}</VideoListContainer>;

Choose a reason for hiding this comment

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

I also recommend putting the map itself inside the video.map(...)

}
1 change: 1 addition & 0 deletions src/components/VideoList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './VideoList';
Loading