Skip to content

Commit

Permalink
Implement Randomizer Feature App, SCSS, HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
agmt92 committed Aug 7, 2024
1 parent ead41f3 commit d6f80bf
Show file tree
Hide file tree
Showing 10 changed files with 16,986 additions and 12,339 deletions.
28,875 changes: 16,642 additions & 12,233 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.7.3",
"node-sass": "^9.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"react-redux": "^9.1.2",
"react-scripts": "^3.0.1",
"redux": "^5.0.1",
"redux-thunk": "^3.1.0",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
51 changes: 10 additions & 41 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<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"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Quote Machine</title>
</head>
<body>
<div id="root"></div>
<script src="index.js"></script>
</body>
</html>
136 changes: 111 additions & 25 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,124 @@
.App {
text-align: center;
}
/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Roboto+Slab:wght@700&display=swap');

.App-logo {
height: 40vmin;
pointer-events: none;
}
/* Variables */
:root {
--background-start-blue: #0f0c29;
--background-middle-blue: #302b63;
--background-end-blue: #24243e;

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
--background-start-green: #0f2b3d;
--background-middle-green: #0f4c75;
--background-end-green: #0b6e99;

--background-start-red: #2b0f0f;
--background-middle-red: #4c0f0f;
--background-end-red: #6e0b0b;

--card-color: #2b2b2b;
--text-color: #f0f0f0;
--button-bg-color: #4a4a4a;
--button-hover-bg-color: #383838;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
/* Global styles */
body {
font-family: 'Roboto', sans-serif;
margin: 0;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
align-items: center;
color: var(--text-color);
}

.App-link {
color: #61dafb;
body.dark-blue {
background: linear-gradient(-45deg, var(--background-start-blue), var(--background-middle-blue), var(--background-end-blue));
background-size: 400% 400%;
animation: gradientAnimation 15s ease infinite;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
body.dark-green {
background: linear-gradient(-45deg, var(--background-start-green), var(--background-middle-green), var(--background-end-green));
background-size: 400% 400%;
animation: gradientAnimation 15s ease infinite;
}

body.dark-red {
background: linear-gradient(-45deg, var(--background-start-red), var(--background-middle-red), var(--background-end-red));
background-size: 400% 400%;
animation: gradientAnimation 15s ease infinite;
}

@keyframes gradientAnimation {
0% {
background-position: 0% 50%;
}
to {
transform: rotate(360deg);
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}

/* Styles for #text */
#text {
font-family: 'Roboto Slab', serif;
font-weight: 700;
font-style: italic;
}

/* quote-box transparent card styles */
#quote-box {
background-color: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
text-align: center;
max-width: 600px;
margin: auto;
}

/* h1 styles */
h1 {
font-size: 24px;
margin-bottom: 20px;
font-weight: 700;
}

/* h2 styles */
h2 {
font-size: 18px;
margin-bottom: 20px;
font-weight: 400;
}

/* Button styles */
button {
margin: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 4px;
background-color: var(--button-bg-color);
color: var(--text-color);
transition: background-color 0.3s ease;
}

button:hover {
background-color: var(--button-hover-bg-color);
}

/* tweet a element styles */
a {
color: var(--text-color);
text-decoration: none;
font-size: 16px;
transition: color 0.3s ease;
}

a:hover {
color: var(--button-bg-color);
}
70 changes: 53 additions & 17 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
import logo from './logo.svg';
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import './App.css';

const RandomIndexQuote = ({ jsonData }) => {
const [index, setIndex] = useState(0);
const [theme, setTheme] = useState('dark-blue');

const randomIndex = () => setIndex(Math.floor(Math.random() * jsonData.length));

const toggleTheme = () => {
const themes = ['dark-blue', 'dark-green', 'dark-red'];
const currentThemeIndex = themes.indexOf(theme);
const nextThemeIndex = (currentThemeIndex + 1) % themes.length;
setTheme(themes[nextThemeIndex]);
};

useEffect(() => {
document.body.className = '';
document.body.classList.add(theme);
}, [theme]);

return (
<div id="quote-box" className="quote">
<h1 id="text">{jsonData[index].quote}</h1>
<h2 id="author">{jsonData[index].author}</h2>
<button id="new-quote" onClick={() => { randomIndex(); toggleTheme(); }}>Randomize</button>
<a id="tweet-quote" href={`https://twitter.com/intent/tweet?text="${jsonData[index].quote}" - ${jsonData[index].author}`} target="_blank" rel="noopener noreferrer">Tweet</a>
</div>
);
};

function App() {
const [jsonData, setJsonData] = useState([]);

useEffect(() => {
const url = 'https://api.github.com/gists/c026b4d87dee807673166b62eac912e0';
axios.get(url)
.then(response => {
const fileKeys = Object.keys(response.data.files);
if (fileKeys.length > 0) {
const fileContent = response.data.files[fileKeys[0]].content;
const jsonData = JSON.parse(fileContent);
setJsonData(jsonData);
} else {
console.error('No files found in the Gist.');
}
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error.message);
});
}, []);

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<div>
{jsonData.length > 0 ? <RandomIndexQuote jsonData={jsonData} /> : <p>Loading...</p>}
</div>
);
}

export default App;
export default App;
Empty file added src/actions.js
Empty file.
15 changes: 4 additions & 11 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
/* index.css */
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
padding: 0;
box-sizing: border-box;
}
16 changes: 5 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
</React.StrictMode>,
document.getElementById('root')
);
Loading

0 comments on commit d6f80bf

Please sign in to comment.