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

Video Details View - Mini Challenge 3 #47

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Video Details View - Mini Challenge 3 #47

wants to merge 5 commits into from

Conversation

racostae
Copy link

@racostae racostae commented Mar 6, 2021

No description provided.

@racostae racostae changed the title Video Details View Video Details View - Mini Challenge 3 Mar 6, 2021
Copy link
Owner

@wdonet wdonet left a comment

Choose a reason for hiding this comment

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

I made a few suggestions, I would love to see more styled-components even though you use Material UI. Let me know if you need help with this.

Also, I see a high coverage but not real unit tests. That's not ideal bc they are not helping you out to understand the code.

There are various files deleted, just make sure you are not removing main components for other functionalities.

I saw it working in a stable manner but you should think in support your code with good unit tests.

------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------------------------|----------|----------|----------|----------|-------------------|
All files | 84.21 | 50 | 88.89 | 82.35 | |
Copy link
Owner

Choose a reason for hiding this comment

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

😎 good coverage so far


describe('App', () => {
it('renders App component', () => {
render(<App />);
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm 🤔 , this test is expecting nothing, this would increase your coverage but not really testing anything else than it is rendering with no errors


describe('Navbar', () => {
it('renders Navbar component', () => {
render(<Navbar />);
Copy link
Owner

Choose a reason for hiding this comment

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

same 😢


console.log(videoInfo);

const classes = useStyles();
Copy link
Owner

Choose a reason for hiding this comment

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

you are not passing a theme object, so I think that's the reason you are missing more than several styles at your components. Do not want to try styled-components instead?


const classes = useStyles();
const { title, channelTitle, thumbnails } = videoInfo.snippet;
const { videoId } = videoInfo.id;
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
const { videoId } = videoInfo.id;
const { id: videoId } = videoInfo; // looks better in my opinion

Copy link
Owner

Choose a reason for hiding this comment

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

even better if you integrate it with the previous line

}
}

export default withStyles(useStyles)(CardVideo);
Copy link
Owner

Choose a reason for hiding this comment

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

it is a good practice to leave an empty line at EOF


this.classes = props.classes;
this.videoInfo = props.videoInfo;
this.videoId = (typeof this.videoInfo.id === 'object') ? this.videoInfo.id.videoId : this.videoInfo.id;
Copy link
Owner

Choose a reason for hiding this comment

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

This comparison is not secure due to the variants of results of typeof. Instead you could try:

Suggested change
this.videoId = (typeof this.videoInfo.id === 'object') ? this.videoInfo.id.videoId : this.videoInfo.id;
const { id = {} } = props.videInfo; // provide a default value - could be numeric too
this.videoId = id.videoId || id; // if not an object with that videoId property, it takes the value provided for id or the default in your code

Comment on lines +36 to +46
const response = await axios.get(
'https://www.googleapis.com/youtube/v3/search', {
params: {
part: 'snippet',
q: search,
maxResults: 20,
type: 'video',
key: process.env.REACT_APP_YOUTUBE_API_KEY,
}
}
)
Copy link
Owner

Choose a reason for hiding this comment

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

Don't you think this could be refactored into a single fn that then is called at the two fetch.. functions?

Also, the code is not error handling for HTTP errors nor for wrong expected data

<Container maxWidth={false}>
<Grid container justify="center" spacing={3}>
{videos.map((video) => {
let videoId = (typeof video.id === 'object') ? video.id.videoId : video.id;
Copy link
Owner

Choose a reason for hiding this comment

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

if you're executing the same validation every time, this could be extracted to an external utility

import { Link, useHistory } from 'react-router-dom';

export default function Navbar(props){
const classes = useStyles();
Copy link
Owner

Choose a reason for hiding this comment

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

you could destructure the properties and use them directly at the JSX code

Suggested change
const classes = useStyles();
const { root, menuButton, navbarTitle, ... etc } = useStyles();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants