Skip to content

Commit 101f88e

Browse files
authored
Arceen: Improve UI of Random quote activity (#52)
1 parent 7f43b8c commit 101f88e

File tree

2 files changed

+154
-41
lines changed

2 files changed

+154
-41
lines changed

src/pages/activities/RandomQuote.js

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
1-
import {useEffect, useState} from "react";
1+
import { useEffect, useState } from "react";
22
import axios from "axios";
3-
import "../../styles/pages/activities/RandomQuote.css"
3+
import "../../styles/pages/activities/RandomQuote.css";
44

55
export const RandomQuote = () => {
6+
const [quote, setQuote] = useState(null);
67

7-
const [quote, setQuote] = useState()
8+
const generateQuote = () => {
9+
setQuote(null);
10+
axios({
11+
method: "GET",
12+
url: "https://api.quotable.io/random",
13+
})
14+
.then((res) => setQuote(res.data))
15+
.catch((error) => console.error(error));
16+
};
817

9-
const generateQuote = () => {
10-
axios({
11-
method: "GET",
12-
url: "https://api.quotable.io/random"
13-
}).then(res => setQuote(res.data))
14-
.catch(error => console.error(error))
15-
}
18+
useEffect(() => {
19+
generateQuote();
20+
}, []);
1621

17-
useEffect(() => {
18-
generateQuote()
19-
}, [])
20-
21-
return (
22-
<div className="rquote-root">
23-
<h1>Random Quote Generator</h1>
24-
<div>Generate any random quote to get some inspiration!</div>
25-
{
26-
quote && (
27-
<div className="rquote-content">
28-
<div className="rquote-quote">{quote.content}</div>
29-
<div className="rquote-author">- {quote.author}</div>
30-
</div>
31-
)
32-
}
33-
<button className="rquote-button" onClick={generateQuote}>
34-
Generate Quote
35-
</button>
22+
return (
23+
<div className="rquote-root">
24+
<h1 class="header">Random Quote Generator</h1>
25+
<div class="description">
26+
Generate any random quote to get some inspiration!
27+
</div>
28+
{quote && (
29+
<div className="rquote-content">
30+
<div className="rquote-quote">{quote.content}</div>
31+
<div className="rquote-author">- {quote.author}</div>
32+
</div>
33+
)}
34+
{!quote && (
35+
<div className="spinner-wrapper">
36+
<div className="spinner"></div>
3637
</div>
37-
)
38-
}
38+
)}
39+
<button className="rquote-button" onClick={generateQuote}>
40+
Generate Quote
41+
</button>
42+
</div>
43+
);
44+
};
Lines changed: 117 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,138 @@
1+
.rquote-root {
2+
margin-top: 25px;
3+
font-family: "Fira Code Light";
4+
}
5+
.header {
6+
font-size: 2rem;
7+
margin-bottom: 5px;
8+
}
9+
.description {
10+
font-size: 1.2rem;
11+
font-weight: 300;
12+
font-style: italic;
13+
}
114
.rquote-content {
2-
margin: 10px;
315
font-style: italic;
4-
padding: 10px;
5-
font-family: "Fira Code Light";
16+
padding: 15px 10px;
17+
background: white;
18+
margin: auto;
19+
border: 1px solid #4b4b4b;
20+
width: 80vw;
21+
max-width: 800px;
22+
margin-top: 50px;
23+
margin-bottom: 20px;
24+
border-radius: 15px;
25+
box-shadow: 2px 2px 5px #4b4b4b;
26+
padding-left: 20px;
27+
animation: quote-appeared 0.5s ease;
28+
}
29+
30+
@keyframes quote-appeared {
31+
0% {
32+
opacity: 0.5;
33+
}
34+
100% {
35+
opacity: 1;
36+
}
37+
}
38+
39+
.rquote-content:hover {
40+
background: #f1f1f1;
641
}
742

843
.rquote-quote {
9-
font-size: 50px;
1044
margin: 10px;
45+
text-align: left;
46+
font-size: 1.8rem;
47+
line-height: 2.2rem;
48+
font-style: normal;
49+
animation: fade 0.3s ease;
50+
}
51+
52+
@keyframes fade {
53+
0% {
54+
opacity: 0.5;
55+
}
56+
100% {
57+
opacity: 1;
58+
}
59+
}
60+
61+
.rquote-quote::before {
62+
content: "“";
63+
}
64+
.rquote-quote::after {
65+
content: "”";
1166
}
1267

1368
.rquote-author {
1469
font-size: 25px;
1570
margin: 10px;
71+
text-align: right;
72+
padding-right: 20px;
73+
font-size: 1.3rem;
74+
font-style: italic;
75+
margin-top: 20px;
76+
animation: slide-left 0.6s ease-in;
77+
}
78+
79+
@keyframes slide-left {
80+
0% {
81+
transform: translateX(4%);
82+
opacity: 20%;
83+
}
84+
100% {
85+
transform: translateX(0%);
86+
opacity: 100%;
87+
}
1688
}
1789

1890
.rquote-button {
19-
font-size: 23px;
91+
font-size: 1.2rem;
2092
background: white;
21-
border-radius: 10px;
22-
padding: 10px;
23-
margin: 10px;
93+
border-radius: 5px;
94+
padding: 20px;
95+
border: 1px solid #4b4b4b;
96+
box-shadow: 1px 1px 3px #4b4b4b;
97+
margin: 10px auto;
98+
margin-top: 30px;
2499
transition-duration: 300ms;
25100
}
26101

27102
.rquote-button:hover {
28103
cursor: pointer;
29-
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
30-
background: #c9c9c9;
104+
background: black;
105+
color: white;
106+
transform: scale(1.1);
107+
}
108+
109+
.spinner-wrapper {
110+
margin: auto;
111+
width: 100px;
112+
display: flex;
113+
align-items: center;
114+
justify-content: center;
115+
max-height: 200px;
116+
height: 200px;
117+
margin-top: 10px;
118+
margin-bottom: 10px;
119+
}
120+
121+
.spinner {
122+
border: 6px solid #f3f3f3;
123+
border-top: 6px solid #3498db;
124+
border-radius: 50%;
125+
width: 50px;
126+
height: 50px;
127+
margin: auto;
128+
animation: spin 2s linear infinite;
129+
}
130+
131+
@keyframes spin {
132+
0% {
133+
transform: rotate(0deg);
134+
}
135+
100% {
136+
transform: rotate(360deg);
137+
}
31138
}

0 commit comments

Comments
 (0)