-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of github.com:chingu-voyage5/Geckos-Team-0…
… into feature-Link-modal-#78-kiran
- Loading branch information
Showing
17 changed files
with
311 additions
and
130 deletions.
There are no files selected for viewing
This file contains 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,44 @@ | ||
function changeBackground() { | ||
// Array of backgrounds | ||
let backgrounds = [ | ||
{ name: 'White Sand Beach', author: 'Monica Silvestre', location: './img/white_beach_monica_silvestre.jpeg' }, | ||
{ name: 'Toronto', author: 'Next Voyage', location: './img/toronto_by_next_voyage.jpeg' }, | ||
{ name: 'Snow Covered Mountains by Lake', author: 'Ricardo Bresciani', location: './img/snow_mountains_by_ricardo_bresciani.jpeg' }, | ||
{ name: 'Boats', author: 'Callebe Miranda', location: './img/boats_by_callebe_miranda.jpeg' } | ||
]; | ||
|
||
// Get current date | ||
let date = new Date(); | ||
let month, dayOfMonth, background; | ||
|
||
// Check if there is a date already in localStorage | ||
if (localStorage.getItem('backgroundMonth')) { | ||
// Grab the month and day from localStorage | ||
month = localStorage.getItem('backgroundMonth'); | ||
dayOfMonth = localStorage.getItem('backgroundDay'); | ||
|
||
// Check if the current day is equal to stored date | ||
if (month != date.getMonth() && dayOfMonth != date.getDate()) { | ||
setBackgroundData(date, backgrounds); | ||
} | ||
} else { | ||
setBackgroundData(date, backgrounds); | ||
} | ||
|
||
background = "url(" + localStorage.getItem('background') + ")"; | ||
|
||
document.body.style.backgroundImage = background; | ||
} | ||
|
||
// Function to set the new month, day, and background path | ||
function setBackgroundData(currentDate, backgroundArray) { | ||
let randomNum = Math.floor(Math.random() * backgroundArray.length); | ||
|
||
localStorage.setItem('backgroundMonth', currentDate.getMonth()); | ||
localStorage.setItem('backgroundDay', currentDate.getDate()); | ||
localStorage.setItem('background', backgroundArray[randomNum].location); | ||
localStorage.setItem('backgroundName', backgroundArray[randomNum].name); | ||
localStorage.setItem('backgroundAuthor', backgroundArray[randomNum].author); | ||
} | ||
|
||
changeBackground(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 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,70 @@ | ||
import React from "react"; | ||
import "../styles/Quote.css"; | ||
|
||
import { TiHeartOutline, TiHeartFullOutline } from "react-icons/lib/ti"; | ||
import FaTwitter from "react-icons/lib/fa/twitter"; | ||
import GoQuote from "react-icons/lib/go/quote"; | ||
|
||
class Quote extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { isClicked: false } | ||
} | ||
|
||
toggleHeart = () => { | ||
this.setState({ isClicked: !this.state.isClicked }); | ||
} | ||
|
||
shareOnTwitter = () => { | ||
const quoteLine = `"${this.props.quote.trim()}" — ${this.props.author}`; | ||
const href = `https://twitter.com/intent/tweet?text=${quoteLine}`; | ||
window.open( | ||
href, | ||
"Twitter", | ||
"height=420, width=550, top=190px, left=365px" | ||
); | ||
} | ||
|
||
render() { | ||
const { quote, author } = this.props; | ||
|
||
return ( | ||
<div id="Quote"> | ||
<div className="Quote__Container"> | ||
<p> | ||
<span> | ||
<GoQuote /> | ||
</span> | ||
{quote} | ||
</p> | ||
</div> | ||
<div className="Action__Container"> | ||
<Actions | ||
author={author} | ||
isClicked={this.state.isClicked} | ||
toggleHeart={this.toggleHeart} | ||
shareOnTwitter={this.shareOnTwitter} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
function Actions({ isClicked, author, toggleHeart, shareOnTwitter }) { | ||
return ( | ||
<div className="Actions"> | ||
<span id="quote-author"> | ||
{author} | ||
</span> | ||
<span id="quote-heart" onClick={() => toggleHeart()}> | ||
{isClicked ? <TiHeartFullOutline /> : <TiHeartOutline />} | ||
</span> | ||
<span id="quote-twitter" onClick={() => shareOnTwitter()}> | ||
<FaTwitter /> | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default Quote; |
This file contains 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,92 @@ | ||
import React from "react"; | ||
import Quote from "./Quote"; | ||
import "../styles/Quote.css"; | ||
|
||
class QuoteContainer extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
quoteText: "", | ||
quoteAuthor: "", | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
this.loadQuote(); | ||
this.callAtMidnight(); | ||
} | ||
|
||
// Schedule to get a new quote every midnight | ||
callAtMidnight = () => { | ||
const currentTime = new Date().getTime(); | ||
const setTime = new Date().setHours(24, 0, 0, 0); // set to midnight | ||
let timeLeft; | ||
|
||
// It's before midnight, | ||
if (currentTime < setTime) { | ||
timeLeft = setTime - currentTime; | ||
// It's after midnight, schedule for tomorrow at 12:00am | ||
} else { | ||
timeLeft = setTime + 86400000 - currentTime; | ||
} | ||
// Call the function 3 hours later from now (if timeLeft = 3h) | ||
// console.log("timeLeft", timeLeft) | ||
setTimeout(() => { | ||
// Repeat every 24h | ||
setInterval(() => { | ||
this.getQuote(); | ||
}, 86400000); | ||
}, timeLeft); | ||
}; | ||
|
||
// If there is no quote stored, call getQuote function. | ||
loadQuote = async () => { | ||
try { | ||
const quoteObj = await localStorage.getItem("quoteObj"); | ||
if (quoteObj) { | ||
const parsedQuote = JSON.parse(quoteObj); | ||
const { quoteText, quoteAuthor } = parsedQuote; | ||
|
||
this.setState({ quoteText, quoteAuthor }); | ||
console.log("loading from local storage", this.state); | ||
} else { | ||
this.getQuote(); | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
|
||
getQuote = () => { | ||
// 👇 Enables cross-origin requests. More info: https://cors-anywhere.herokuapp.com/ | ||
const proxyUrl = "https://cors-anywhere.herokuapp.com/"; | ||
const endPoint = `https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en`; | ||
|
||
fetch(proxyUrl + endPoint) | ||
.then(response => response.json()) | ||
.then(json => { | ||
console.log(json); | ||
const { quoteText, quoteAuthor } = json; | ||
this.setState({ quoteText, quoteAuthor }); | ||
this.saveQuote(this.state); | ||
console.log("loading from state", this.state) | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
}); | ||
}; | ||
|
||
saveQuote = quoteState => { | ||
localStorage.setItem("quoteObj", JSON.stringify(quoteState)); | ||
}; | ||
|
||
render() { | ||
const { quoteText, quoteAuthor } = this.state; | ||
|
||
return ( | ||
<Quote quote={quoteText} author={quoteAuthor} /> | ||
); | ||
} | ||
} | ||
|
||
export default QuoteContainer; |
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.