Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions Code/Jose/javascript/lab05/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Flask, render_template, request
app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

app.run(debug = True)
Empty file.
80 changes: 80 additions & 0 deletions Code/Jose/javascript/lab05/static/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
let requestedinputText, searchButton, previousPageButton, nextPageButton,
quoteText, quoteAuthor, quoteDiv, quoteDivAuthor, userSearch, pageNumber

searchButton = document.querySelector('#searchButton');
previousPageButton = document.querySelector('#previousPageButton');
nextPageButton = document.querySelector('#nextPageButton');
resultText = document.querySelector('#resultText');
resultAuthor = document.querySelector('#resultAuthor');

quoteNumber = 0;
pageNumber = 1;

let url = `https://favqs.com/api/quotes?page=${pageNumber}&filter=${requestedinputText}`

const headers = {
Accept: 'application/json',
Authorization: `Token token=${FAVQS_API_KEY}`
}



function fetchQuoteData() {
requestedinputText = document.querySelector('#searchInput').value;

fetch(`https://favqs.com/api/quotes?page=${pageNumber}&filter=${requestedinputText}`, {headers})
.then((response) => response.json())
.then((data) => {
author = data.quotes[quoteNumber].author;
quoteText = data.quotes[quoteNumber].body;
resultText.innerHTML = quoteText;
resultAuthor.innerHTML = author;
amountofReturnedQuotes = data.quotes.length
// Saving the data in a variable to use outside this scope
returnedQuotes = data
//console.log(returnedQuotes)
//console.log(amountofReturnedQuotes)
})
}

function nextPage() {
if (quoteNumber < amountofReturnedQuotes-1){
quoteNumber++
author = returnedQuotes.quotes[quoteNumber].author;
quoteText = returnedQuotes.quotes[quoteNumber].body;
resultText.innerHTML = quoteText;
resultAuthor.innerHTML = author;
} else {
alert("You've reached the end of the quotes!")
}
}

function previousPage() {
if (quoteNumber > 0) {
quoteNumber--
author = returnedQuotes.quotes[quoteNumber].author;
quoteText = returnedQuotes.quotes[quoteNumber].body;
resultText.innerHTML = quoteText;
resultAuthor.innerHTML = author;
} else {
alert('This is the beginning of the quotes!')
}
}


searchButton.onclick = function(){
fetchQuoteData()
}

nextPageButton.onclick = function(){
nextPage()
}

previousPageButton.onclick = function(){
previousPage()
}

//quoteText = data.quote.body;
//quoteAuthor = data.quote.author;
//resultText.innerHTML = quoteText;
//resultAuthor.innerHTML = quoteAuthor;
52 changes: 52 additions & 0 deletions Code/Jose/javascript/lab05/static/styles/mainpage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
body {
background-color: #8fbc8f;
font-family: sans-serif;
}

.instructions{
display: flex;
margin-top: 15%;
justify-content: center;

}

.instruction-text {
font-size: 3rem;
font-weight: 600;
}

.btn {
justify-content: center;
text-align: center;
color: black;
font-weight: 700;
margin-top: 15px;
}

.row {
margin-left: 45%;
width: 10%
}

.quoteDiv {
display: flex;
margin-top: 5%;
justify-content: center;
width: 50%;
margin-left: 25%;
margin-bottom: -5%;
background-color: seagreen;
border-radius: 10px;
font-size: 1.5rem;
font-weight: 600;
color: darkslategrey;
padding-left: 5%;
padding-right: 5%;
}

.searchBar {
display: flex;
margin-left: 25%;
width: 50%;
}

41 changes: 41 additions & 0 deletions Code/Jose/javascript/lab05/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/mainpage.css') }}">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<title>Random Quote</title>
</head>
<body>
<div class='instructions'>
<p class='instruction-text'>Enter text for a quote.</p>
</div>

<div class="searchBar">
<input type="search" class="form-control" id="searchInput" placeholder="What theme of quote would you like?">
</div>

<div class="row justify-content-center">
<button type="submit" class="btn btn-success" id='searchButton'>Click to search!</button>
<button class="btn btn-success" id="previousPageButton">Previous Page</button>
<button class="btn btn-success" id="nextPageButton">Next Page</button>
</div>


<div class='quoteDiv'>
<p id='resultText'>(your quote will appear here)</p>
</div>
<div class='quoteDiv'>
<p >-&nbsp;</p>
<p id='resultAuthor'>(this is the author's name!)</p>
</div>

<script src="./static/js/secrets.js"></script>
<script src="./static/js/index.js"></script>
</body>
</html>