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

React Certification first deliverable #1

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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 .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"react-hooks/exhaustive-deps": "warn",
"import/no-unresolved": ["off", { "ignore": [".css$"] }],
"import/prefer-default-export": "off",
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
"react/destructuring-assignment": "off",
"react/jsx-props-no-spreading": "off",
"react/prop-types": "off",
Expand Down
8 changes: 2 additions & 6 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"printWidth": 90,
"semi": true,
"singleQuote": true,
"jsxSingleQuote": false,
"arrowParens": "always"
"useTabs": false,
"editor.formatOnSave": true
}
18,349 changes: 18,349 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"react-dom": "^16.13.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3"
"react-scripts": "3.4.3",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^1.2.0",
"styled-components": "5.2.0",
"axios": "0.20.0"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -21,6 +25,8 @@
"lint:fix": "eslint ./src --ext .js,.jsx --fix"
},
"devDependencies": {
"@babel/core": "^7.11.6",
"babel-loader": "^8.1.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
Expand All @@ -31,8 +37,10 @@
"eslint-plugin-react-hooks": "^4.1.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.13",
"node-sass": "4.14.0",
"prettier": "^2.1.1",
"pretty-quick": "^3.0.0"
"pretty-quick": "^3.0.0",
"react-is": "^16.13.1"
},
"browserslist": {
"production": [
Expand All @@ -47,7 +55,7 @@
]
},
"lint-staged": {
"*.{js, jsx, css, json}": [
"*.{js, jsx, css, scss, json}": [
"yarn run lint:fix",
"pretty-quick --staged",
"git add"
Expand Down
6 changes: 5 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
Expand All @@ -22,6 +25,7 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<script src="https://apis.google.com/js/client.js"></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
12 changes: 12 additions & 0 deletions src/apis/youtube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from "axios";

const KEY = "AIzaSyDYJVu8aH3B6BcGJz3tJCCu-wgoTuQUE4k";

export default axios.create({
baseURL: "https://www.googleapis.com/youtube/v3/",
params: {
part: "snippet",
maxResults: 20,
key: KEY,
},
});
53 changes: 19 additions & 34 deletions src/components/App/App.component.jsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,43 @@
import React, { useLayoutEffect } from 'react';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import React, { useState } from "react";
import { BrowserRouter, Switch, Route } from "react-router-dom";

import AuthProvider from '../../providers/Auth';
import HomePage from '../../pages/Home';
import LoginPage from '../../pages/Login';
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';
import AuthProvider from "../../providers/Auth";
import HomePage from "../../pages/Home";
import LoginPage from "../../pages/Login";
import Video from "../../pages/Video";
import NotFound from "../../pages/NotFound";
import Favorites from "../../pages/Favorites";
import Private from "../Private";
import Layout from "../Layout";

function App() {
useLayoutEffect(() => {
const { body } = document;

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);
};
}, []);
const App = () => {
const [activeVideo, setActiveVideo] = useState(null);

return (
<BrowserRouter>
<AuthProvider>
<Layout>
<Switch>
<Route exact path="/">
<HomePage />
<HomePage onSetActiveVideo={(video) => setActiveVideo(video)} />
</Route>
<Route exact path="/login">
<LoginPage />
</Route>
<Private exact path="/secret">
<SecretPage />
<Route path="/videos/:id">
<Video video={activeVideo} />
</Route>
<Private exact path="/favorites">
<Favorites onSetActiveVideo={(video) => setActiveVideo(video)} />
</Private>
<Route path="*">
<NotFound />
</Route>
</Switch>
<Fortune />
</Layout>
</AuthProvider>
</BrowserRouter>
);
}
};

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.component";
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.

89 changes: 84 additions & 5 deletions src/components/Layout/Layout.component.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,88 @@
import React from 'react';
import React, { useContext, useMemo, useState } from "react";
import { ThemeProvider, createGlobalStyle } from "styled-components";

import './Layout.styles.css';
import MainMenu from "../MainMenu";

function Layout({ children }) {
return <main className="container">{children}</main>;
}
import "./Layout.styles.css";

const commontheme = {
fontFam: "monospace",
};

const lightTheme = {
...commontheme,
bg: "#e3dae7",
hover: "#d3b3b8",
link: "#714d69",
menuBg: "#a0849d",
text: "#aaa",
};

const darkTheme = {
...commontheme,
bg: "#43b5a0",
hover: "#fa448c",
link: "#491d88",
menuBg: "#fec859",
text: "#fff",
};

const GlobalStyles = createGlobalStyle`
body {
font-family: ${(props) => props.theme.fontFam};
color: ${(props) => props.theme.text};
background-color: ${(props) => props.theme.bg};

a {
color: ${(props) => props.theme.link};
}

a:hover {
color: ${(props) => props.theme.hover};
}

.component__main-menu {
background-color: ${(props) => props.theme.menuBg}
}
}
`;

const QueryContext = React.createContext([{}, () => {}]);

export const useQueryContext = () => {
const context = useContext(QueryContext);

if (!context) {
throw new Error("useQueryContext is not present");
}

return context;
};

const Layout = ({ children }) => {
const [mode, setMode] = useState("light");
const [queryString, setQueryString] = useState("Wizeline");

const contextValue = useMemo(() => ({ queryString, setQueryString }), [
queryString,
setQueryString,
]);

return (
<ThemeProvider theme={mode === "light" ? lightTheme : darkTheme}>
<GlobalStyles />
<div>
<MainMenu
onSetMode={(theme) => setMode(theme)}
queryString={queryString}
onSearch={(qs) => setQueryString(qs)}
/>
<QueryContext.Provider value={contextValue}>
<main className="container">{children}</main>
</QueryContext.Provider>
</div>
</ThemeProvider>
);
};

export default Layout;
3 changes: 0 additions & 3 deletions src/components/Layout/Layout.styles.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
.container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: -3rem;
}
5 changes: 4 additions & 1 deletion src/components/Layout/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { default } from './Layout.component';
import { useQueryContext } from "./Layout.component";

export { default } from "./Layout.component";
export { useQueryContext };
73 changes: 73 additions & 0 deletions src/components/MainMenu/MainMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from "react";
import { Link, useHistory } from "react-router-dom";
import { Button, Dropdown, Icon } from "semantic-ui-react";

import { useAuth } from "../../providers/Auth";

import "./MainMenu.scss";

const MainMenu = ({ queryString, onSearch, onSetMode }) => {
const history = useHistory();
const { authenticated, logout } = useAuth();

const deAuthenticate = (event) => {
event.preventDefault();
logout();
history.push("/");
};

return (
<div className="component__main-menu">
<div className="menu-options">
<Dropdown item icon="bars" simple>
<Dropdown.Menu>
<Dropdown.Item>
<Link to="/">Home</Link>
</Dropdown.Item>
{authenticated && (
<Dropdown.Item>
<Link to="/favorites">Favorites</Link>
</Dropdown.Item>
)}
</Dropdown.Menu>
</Dropdown>
</div>
<div className="component__search-bar">
<input
onChange={(event) => onSearch(event.target.value)}
name="video-search"
type="text"
value={queryString}
/>
{console.log({ queryString })}
</div>
<div className="theme-options">
<Button.Group>
<Button
icon="sun"
content="Light mode"
onClick={() => onSetMode("light")}
/>
<Button
icon="moon"
content="Dark mode"
onClick={() => onSetMode("dark")}
/>
</Button.Group>
</div>
<div className="user-menu">
{authenticated ? (
<Link to="/" onClick={deAuthenticate}>
<Icon name="user" />
</Link>
) : (
<Link to="/login">
<Icon name="user outline" />
</Link>
)}
</div>
</div>
);
};

export default MainMenu;
13 changes: 13 additions & 0 deletions src/components/MainMenu/MainMenu.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.component__main-menu {
display: flex;
padding: 10px;

.menu-options {
padding: 10px;
}

.user-menu {
padding: 10px;
margin-left: auto !important;
}
}
1 change: 1 addition & 0 deletions src/components/MainMenu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./MainMenu";
Loading