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

Mini challenge 4 #61

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

Conversation

alfredo-pacheco
Copy link

Hi,

This PR contains both mini-challenges: 3 and 4.

Thanks a lot.

Copy link

@PacoMojica PacoMojica left a comment

Choose a reason for hiding this comment

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

Hello Alfredo, I like what you have up to this point. One thing that is missing is some tests. I see a lot of 'should render{name} component correctly' but you can test some events, the custom hooks, or the providers, I'd like improvements in the next delivery. I left some comments, just minor things. Great work 👍

Comment on lines +1 to +19
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { useYouTube } from '../YouTube/YouTubeProvider';

const theme = {
dark: {
primary: '#4396f3',
secondary: '#4a4646',
color: '#f7f7f7',
},
};

function MyThemeProvider({ children }) {
const { state } = useYouTube();
const { theme: stateTheme } = state;
return <ThemeProvider theme={theme[stateTheme] || {}}>{children}</ThemeProvider>;
}

export default MyThemeProvider;

Choose a reason for hiding this comment

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

This theme provider looks good!

Comment on lines +14 to +17
const url = ['https://www.googleapis.com/youtube/v3/search?'];
url.push(`key=${process.env.REACT_APP_YOUTUBE_API_KEY}`);
url.push(`&part=snippet&maxResults=10&type=video`);
if (search) url.push(`&q=${search}`);

Choose a reason for hiding this comment

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

Took me a while to catch why this was an array, I think that concatenating strings by using the + operator is more expressive, at first sight you know that 'asdf' + 'ewer' = 'asdfqwer' and in this case you have an array of strings, you push items and at the end you do url.join('') which I think is somewhat convoluted, at the end of the day it is just preference

Comment on lines +6 to +8
const [videos, setVideos] = useState([]);
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState(null);

Choose a reason for hiding this comment

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

Great, I like that you are handling the data, the loading state and the possible errors

return { videos, isLoading, error };
}

export default useRelatedVideos;

Choose a reason for hiding this comment

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

Both of the hooks, the useReleatedVideos and useVideos, are well defined 👍

Comment on lines +7 to +26
case 'search':
return {
...state,
search: action.payload,
};
case 'currentVideo':
return {
...state,
currentVideo: action.payload,
};
case 'closeCurrentVideo':
return {
...state,
currentVideo: null,
};
case 'switchTheme':
return {
...state,
theme: state.theme === 'dark' ? 'default' : 'dark',
};

Choose a reason for hiding this comment

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

This actions seems really useful

theme: state.theme === 'dark' ? 'default' : 'dark',
};
default: {
return state;

Choose a reason for hiding this comment

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

I'd throw an error here, it can prevent some unwanted stuff to go unnoticed, for example you can pass CloseCurrentVideo and the state won't update but it will be hard to find that the bug is caused because the C should be lower case like closeCurrentVideo, I learned it the hard way 😆

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