Fixed bug where undefined languages were showing inlanguage drop down. Book search results can now be clicked to be taken to the book

pull/6/head
leo ouyang 2021-12-02 18:10:50 -05:00
parent 0524b18250
commit 639354dd73
5 changed files with 42462 additions and 54 deletions

21383
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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){

View File

@ -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);

View File

@ -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>

21092
src/fpb.json Normal file

File diff suppressed because it is too large Load Diff