Fixed bug where undefined languages were showing inlanguage drop down. Book search results can now be clicked to be taken to the book
parent
0524b18250
commit
639354dd73
File diff suppressed because it is too large
Load Diff
30
src/App.js
30
src/App.js
|
@ -5,7 +5,7 @@ import SearchResult from './components/SearchResult';
|
|||
import axios from 'axios';
|
||||
import Fuse from 'fuse.js';
|
||||
|
||||
const fpb = require('./fpb.json');
|
||||
const fpb = require('./fpb.json'); //local copy of json becuase online currently can't be accessed
|
||||
|
||||
function makeBook(author, hLang, cLang, title, url)
|
||||
{
|
||||
|
@ -64,34 +64,6 @@ function searchByLanguage(lang, json)
|
|||
console.log(answer)
|
||||
}
|
||||
|
||||
class SubmitButton extends Component{
|
||||
constructor(props)
|
||||
{
|
||||
super(props);
|
||||
}
|
||||
async click()
|
||||
{
|
||||
let result = await fetch('https://raw.githubusercontent.com/FreeEbookFoundationBot/free-programming-books-json/main/fpb.json')
|
||||
if (result.ok)
|
||||
{
|
||||
let json = await result.json();
|
||||
console.log(json.children[0])
|
||||
searchByLanguage("Arabic",json.children[0].children)
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("ERROR in fetching json: " + result.status.toString() + " " + result.statusText)
|
||||
}
|
||||
|
||||
}
|
||||
render()
|
||||
{
|
||||
return (
|
||||
<button onClick = {this.click}>Submit</button>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Sorts search results by their score
|
||||
function sortByScore(results){
|
||||
results.sort(function(a,b){
|
||||
|
|
|
@ -13,7 +13,11 @@ function LangDropdown({ changeParameter, data }){
|
|||
if(data){
|
||||
let langArray = [];
|
||||
data.children[0].children.forEach( (document) => {
|
||||
if (typeof document.language.name === "string" && document.language.name.length > 0) //make sure the language is valid and not blank
|
||||
{
|
||||
//console.log("LANGUAGE: " + document.language.name)
|
||||
langArray.push(document.language);
|
||||
}
|
||||
});
|
||||
langArray.sort((a, b) => a.name > b.name)
|
||||
setLanguages(langArray);
|
||||
|
|
|
@ -3,7 +3,10 @@ import React, { useState, useEffect } from 'react';
|
|||
function SearchResult({ data }){
|
||||
return(
|
||||
<div>
|
||||
<button>
|
||||
<button onClick={(e) => {
|
||||
e.preventDefault();
|
||||
window.location.href=data.url;
|
||||
}}>
|
||||
<h3>{data.title} by {data.author}</h3>
|
||||
<p>({data.lang.code})</p>
|
||||
</button>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue