forked from wdonet/react-certification-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Mini challenge 3 #2
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
Open
roberto-wl
wants to merge
9
commits into
master
Choose a base branch
from
Mini-Challenge-3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,140
−2,773
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d3f1dc
Add header and list components
roberto-wl 7dc3011
Fix lint errors
roberto-wl ca1564f
Fix build errors
roberto-wl b0f529c
Fix build errors
roberto-wl 7669469
Search videos in YouTube
roberto-wl d1a7a4c
Search videos in YouTube
roberto-wl fabc45e
Remove vscode file
roberto-wl 8f5f0af
Fix lint errors
roberto-wl bc70d65
Add video viewer
roberto-wl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,4 @@ | |
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Launch Chrome", | ||
| "request": "launch", | ||
| "type": "pwa-chrome", | ||
| "url": "http://localhost:3000", | ||
| "webRoot": "${workspaceFolder}" | ||
| }, | ||
| { | ||
| "command": "npm start", | ||
| "name": "Run npm start", | ||
| "request": "launch", | ||
| "type": "node-terminal" | ||
| }, | ||
| { | ||
| "type": "browser-preview", | ||
| "name": "Browser Preview: Attach", | ||
| "request": "attach" | ||
| }, | ||
| { | ||
| "type": "browser-preview", | ||
| "request": "launch", | ||
| "name": "Browser Preview: Launch", | ||
| "url": "http://localhost:3000" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* global gapi */ | ||
|
|
||
| /** | ||
| * Sample JavaScript code for youtube.search.list | ||
| * See instructions for running APIs Explorer code samples locally: | ||
| * https://developers.google.com/explorer-help/guides/code_samples#javascript | ||
| */ | ||
|
|
||
| function loadClient(key) { | ||
| gapi.client.setApiKey(key); | ||
| return gapi.client | ||
| .load('https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest') | ||
| .then( | ||
| function () { | ||
| console.log('GAPI client loaded for API'); | ||
| }, | ||
| function (err) { | ||
| console.error('Error loading GAPI client for API', err); | ||
| } | ||
| ); | ||
| } | ||
| // Make sure the client is loaded before calling this method. | ||
| function execute(search) { | ||
| return gapi.client.youtube.search | ||
| .list({ | ||
| part: ['snippet', 'id'], | ||
| maxResults: 25, | ||
| q: search, | ||
| type: ['video'], | ||
| }) | ||
| .then( | ||
| function (response) { | ||
| // Handle the results here (response.result has the parsed body). | ||
| console.log('Response', response); | ||
| return response.result; | ||
| }, | ||
| function (err) { | ||
| console.error('Execute error', err); | ||
| } | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
| import { useVideo } from '../../state'; | ||
| import useImportScript from '../../utils/hooks/useImportScrip'; | ||
|
|
||
| const Header = styled.header` | ||
| color: #fff; | ||
| background-color: #1c5476; | ||
| position: static; | ||
| width: 100%; | ||
| display: flex; | ||
| z-index: 1100; | ||
| box-sizing: border-box; | ||
| flex-shrink: 0; | ||
| flex-direction: column; | ||
| `; | ||
|
|
||
| const NavBar = styled.div` | ||
| min-height: 64px; | ||
| color: white; | ||
| padding-left: 24px; | ||
| padding-right: 24px; | ||
| display: flex; | ||
| align-items: center; | ||
| position: relative; | ||
| `; | ||
|
|
||
| const SvgIcon = styled.svg` | ||
| font-size: 1.5rem; | ||
| width: 1em; | ||
| height: 1em; | ||
| display: inline-block; | ||
| fill: currentColor; | ||
| user-select: none; | ||
| `; | ||
|
|
||
| const Button = styled.button` | ||
| padding: 12px; | ||
| font-size: 1.5rem; | ||
| color: inherit; | ||
| background-color: transparent; | ||
| border: 0; | ||
| user-select: none; | ||
| margin-right: 16px; | ||
| `; | ||
|
|
||
| const SearchBox = styled.div` | ||
| width: auto; | ||
| margin-left: 24px; | ||
| position: relative; | ||
| margin-right: 16px; | ||
| border-radius: 4px; | ||
| background-color: rgba(255, 255, 255, 0.15); | ||
| `; | ||
|
|
||
| const SearchIconDiv = styled.div` | ||
| padding: 0px 16px; | ||
| position: absolute; | ||
| align-items: center; | ||
| pointer-events: none; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| const SearchInputDiv = styled.div` | ||
| cursor: text; | ||
| display: inline-flex; | ||
| position: relative; | ||
| font-size: 1rem; | ||
| box-sizing: border-box; | ||
| align-items: center; | ||
| font-family: 'Roboto', 'Helvetica', 'Arial', sans-serif; | ||
| font-weight: 400; | ||
| line-height: 1.1876em; | ||
| letter-spacing: 0.00938em; | ||
| `; | ||
|
|
||
| const SearchInput = styled.input` | ||
| width: 20ch; | ||
| font-size: inherit; | ||
| padding: 8px 8px 8px 0px; | ||
| transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; | ||
| padding-left: calc(1em + 32px); | ||
| color: currentColor; | ||
| height: 1.1876em; | ||
| margin: 0; | ||
| display: block; | ||
| min-width: 0; | ||
| background: none; | ||
| box-sizing: content-box; | ||
| letter-spacing: inherit; | ||
| animation-duration: 10ms; | ||
| -webkit-tap-highlight-color: transparent; | ||
|
|
||
| &:focus { | ||
| outline: 0; | ||
| } | ||
| `; | ||
|
|
||
| const ToggleDiv = styled.div` | ||
| display: flex; | ||
| `; | ||
|
|
||
| const ToggleLabel = styled.div` | ||
| display: flex; | ||
| width: 100%; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| const ToggleButton = styled.span` | ||
| width: 20px; | ||
| height: 20px; | ||
| box-shadow: 0px 2px 1px -1px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%), | ||
| 0px 1px 3px 0px rgb(0 0 0 / 12%); | ||
| border-radius: 50%; | ||
| background-color: currentColor; | ||
| `; | ||
|
|
||
| const Client = () => { | ||
| useImportScript('https://apis.google.com/js/api.js'); | ||
| useImportScript('youtube-request.js'); | ||
| return null; | ||
| }; | ||
|
|
||
| function HeaderComponent() { | ||
| const { state, dispatch } = useVideo(); | ||
| const { search } = state; | ||
|
|
||
| async function submitHandler(event) { | ||
| event.preventDefault(); | ||
| await window.loadClient(process.env.REACT_APP_KEY); | ||
| const result = await window.execute(search); | ||
| dispatch({ type: 'SUBMIT', payload: result.items }); | ||
| } | ||
|
|
||
| return ( | ||
| <Header> | ||
| <Client /> | ||
| <NavBar> | ||
| <Button> | ||
| <span> | ||
| <SvgIcon viewBox="0 0 24 24"> | ||
| <path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" /> | ||
| </SvgIcon> | ||
| </span> | ||
| </Button> | ||
| <SearchBox> | ||
| <SearchIconDiv> | ||
| <SvgIcon> | ||
| <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" /> | ||
| </SvgIcon> | ||
| </SearchIconDiv> | ||
| <SearchInputDiv> | ||
| <form onSubmit={submitHandler}> | ||
| <SearchInput | ||
| type="text" | ||
| placeholder="Search..." | ||
| value={search} | ||
| onChange={(e) => dispatch({ type: 'EDIT', payload: e.target.value })} | ||
| /> | ||
| </form> | ||
| </SearchInputDiv> | ||
| </SearchBox> | ||
| <ToggleDiv> | ||
| <ToggleLabel> | ||
| <ToggleButton /> | ||
| </ToggleLabel> | ||
| </ToggleDiv> | ||
| <span>Dark mode</span> | ||
| </NavBar> | ||
| </Header> | ||
| ); | ||
| } | ||
|
|
||
| export default HeaderComponent; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './Header.component'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import React from 'react'; | ||
| import uuid from 'react-uuid'; | ||
|
|
||
| import { useVideo } from '../../state'; | ||
|
|
||
| function History() { | ||
| const { state } = useVideo(); | ||
| const { history } = state; | ||
|
|
||
| return ( | ||
| <div> | ||
| <h3>Search History</h3> | ||
| <ul> | ||
| {history.map((item) => ( | ||
| <li key={uuid()}>{item}</li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default History; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './History.component'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What if gapi is not loaded yet by the time your components needs to use it? You might want to use youtube API inside a hook in react.