Clear some react warnings
parent
269f75a0ae
commit
597b30b19f
|
@ -51,10 +51,10 @@ function jsonToArray(json) {
|
||||||
function App() {
|
function App() {
|
||||||
const [data, setData] = useState(undefined); // keeps the state of the json
|
const [data, setData] = useState(undefined); // keeps the state of the json
|
||||||
const [dataArray, setDataArray] = useState([]); // put everything into one array. uses more memory, but search is faster and less complex
|
const [dataArray, setDataArray] = useState([]); // put everything into one array. uses more memory, but search is faster and less complex
|
||||||
// eslint-disable-next-line
|
|
||||||
const [loading, setLoading] = useState(true); // Determines whether to show spinner
|
const [loading, setLoading] = useState(true); // Determines whether to show spinner
|
||||||
const [searchParams, setSearchParams] = useState({ searchTerm: "", "lang.code": ""});
|
const [searchParams, setSearchParams] = useState({ searchTerm: "", "lang.code": ""});
|
||||||
const [searchResults, setSearchResults] = useState([]);
|
const [searchResults, setSearchResults] = useState([]);
|
||||||
|
// eslint-disable-next-line
|
||||||
const [cookies, setCookie, removeCookie] = useCookies(["lightMode"]);
|
const [cookies, setCookie, removeCookie] = useCookies(["lightMode"]);
|
||||||
const [queries, setQueries] = useState({lang: "", subject: ""});
|
const [queries, setQueries] = useState({lang: "", subject: ""});
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ function App() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setQueries(queryString.parse(document.location.search));
|
setQueries(queryString.parse(document.location.search));
|
||||||
if (queries.lang) {
|
if (queries.lang) {
|
||||||
if (queries.lang == "langs" || queries.lang == "subjects") {
|
if (queries.lang === "langs" || queries.lang === "subjects") {
|
||||||
changeParameter("lang.code", "en");
|
changeParameter("lang.code", "en");
|
||||||
} else {
|
} else {
|
||||||
changeParameter("lang.code", queries.lang);
|
changeParameter("lang.code", queries.lang);
|
||||||
|
@ -86,11 +86,12 @@ function App() {
|
||||||
"https://raw.githubusercontent.com/FreeEbookFoundationBot/free-programming-books-json/main/fpb.json"
|
"https://raw.githubusercontent.com/FreeEbookFoundationBot/free-programming-books-json/main/fpb.json"
|
||||||
);
|
);
|
||||||
setData(result.data);
|
setData(result.data);
|
||||||
|
// eslint-disable-next-line
|
||||||
let { arr, sections } = jsonToArray(result.data);
|
let { arr, sections } = jsonToArray(result.data);
|
||||||
setDataArray(arr);
|
setDataArray(arr);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// setError("Couldn't get data. Please try again later")
|
|
||||||
setData(fpb);
|
setData(fpb);
|
||||||
|
// eslint-disable-next-line
|
||||||
let { arr, sections } = jsonToArray(fpb);
|
let { arr, sections } = jsonToArray(fpb);
|
||||||
setDataArray(arr);
|
setDataArray(arr);
|
||||||
}
|
}
|
||||||
|
@ -224,6 +225,7 @@ function App() {
|
||||||
changeTheme(willBeDarkMode ? themes.light : themes.dark);
|
changeTheme(willBeDarkMode ? themes.light : themes.dark);
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
|
alt="Toggle light/dark mode"
|
||||||
src={willBeDarkMode ? MoonImg : SunImg}
|
src={willBeDarkMode ? MoonImg : SunImg}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setCookie("lightMode", willBeDarkMode);
|
setCookie("lightMode", willBeDarkMode);
|
||||||
|
|
|
@ -22,7 +22,7 @@ function BookList({ langCode }) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, [langCode]);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p>Loading...</p>;
|
return <p>Loading...</p>;
|
||||||
|
|
|
@ -15,7 +15,7 @@ function LangFilters({ changeParameter, data, langCode }) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let queries = queryString.parse(document.location.search);
|
let queries = queryString.parse(document.location.search);
|
||||||
if (queries.lang) {
|
if (queries.lang) {
|
||||||
if (queries.lang == "langs" || queries.lang == "subjects") {
|
if (queries.lang === "langs" || queries.lang === "subjects") {
|
||||||
changeParameter("lang.code", "en");
|
changeParameter("lang.code", "en");
|
||||||
setSelected("en");
|
setSelected("en");
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,7 +23,7 @@ function LangFilters({ changeParameter, data, langCode }) {
|
||||||
setSelected(queries.lang);
|
setSelected(queries.lang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, []);
|
}, [changeParameter]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
// run whenever data changes
|
// run whenever data changes
|
||||||
|
@ -57,7 +57,7 @@ function LangFilters({ changeParameter, data, langCode }) {
|
||||||
key={language.code}
|
key={language.code}
|
||||||
value={language.code}
|
value={language.code}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
checked={language.code == selected}
|
checked={language.code === selected}
|
||||||
/>
|
/>
|
||||||
{language.name}
|
{language.name}
|
||||||
</label>
|
</label>
|
||||||
|
@ -80,7 +80,7 @@ function LangFilters({ changeParameter, data, langCode }) {
|
||||||
className="sect-select"
|
className="sect-select"
|
||||||
value=""
|
value=""
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
checked={"" == selected}
|
checked={"" === selected}
|
||||||
/>
|
/>
|
||||||
All Languages
|
All Languages
|
||||||
</label>
|
</label>
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState } from "react";
|
||||||
|
|
||||||
function LightSwitch(App){
|
function LightSwitch() {
|
||||||
const [lightMode, setLightMode] = useState(false);
|
const [lightMode, setLightMode] = useState(false);
|
||||||
return (
|
return (
|
||||||
<img src={lightMode ? "https://toppng.com/uploads/preview/sun-11545692406nbrflpmao0.png" : "https://www.kindpng.com/picc/m/293-2939577_clip-art-drawing-of-moon-and-stars-star.png"}
|
<img
|
||||||
onClick = {()=>setLightMode(!lightMode)} style={{width: "100px", height: "100px",display: "block",
|
alt="Toggle light/dark mode"
|
||||||
marginLeft: "auto",
|
src={
|
||||||
marginRight: "auto",
|
lightMode
|
||||||
}}/>
|
? "https://toppng.com/uploads/preview/sun-11545692406nbrflpmao0.png"
|
||||||
)
|
: "https://www.kindpng.com/picc/m/293-2939577_clip-art-drawing-of-moon-and-stars-star.png"
|
||||||
|
}
|
||||||
|
onClick={() => setLightMode(!lightMode)}
|
||||||
|
style={{ width: "100px", height: "100px", display: "block", marginLeft: "auto", marginRight: "auto" }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LightSwitch;
|
export default LightSwitch;
|
|
@ -1,4 +1,4 @@
|
||||||
import React, {useEffect, useState} from "react";
|
import React, {useEffect} from "react";
|
||||||
const queryString = require("query-string");
|
const queryString = require("query-string");
|
||||||
|
|
||||||
function SearchBar(props) {
|
function SearchBar(props) {
|
||||||
|
@ -8,7 +8,7 @@ function SearchBar(props) {
|
||||||
document.getElementById("searchBar").value = queries.search;
|
document.getElementById("searchBar").value = queries.search;
|
||||||
props.changeParameter("searchTerm", queries.search);
|
props.changeParameter("searchTerm", queries.search);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [props]);
|
||||||
|
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
props.changeParameter("searchTerm", e.target.value);
|
props.changeParameter("searchTerm", e.target.value);
|
||||||
|
|
|
@ -24,7 +24,7 @@ function SectDropdown({ changeParameter, data, value }) {
|
||||||
for (let i = 0; i < document.sections.length; i++) {
|
for (let i = 0; i < document.sections.length; i++) {
|
||||||
// console.log("h")
|
// console.log("h")
|
||||||
// console.log(document.sections[i]);
|
// console.log(document.sections[i]);
|
||||||
if (sectArray.indexOf(document.sections[i].section) == -1) {
|
if (sectArray.indexOf(document.sections[i].section) === -1) {
|
||||||
sectArray.push(document.sections[i].section.trim());
|
sectArray.push(document.sections[i].section.trim());
|
||||||
}
|
}
|
||||||
// sectArray.push(document.sections[i].section);
|
// sectArray.push(document.sections[i].section);
|
||||||
|
@ -48,7 +48,7 @@ function SectDropdown({ changeParameter, data, value }) {
|
||||||
key={section}
|
key={section}
|
||||||
value={section}
|
value={section}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
checked={section == selected}
|
checked={section === selected}
|
||||||
/>
|
/>
|
||||||
{section}
|
{section}
|
||||||
</label>
|
</label>
|
||||||
|
@ -67,7 +67,7 @@ function SectDropdown({ changeParameter, data, value }) {
|
||||||
<h3>Select Programming Language:</h3>
|
<h3>Select Programming Language:</h3>
|
||||||
<form class="filters">
|
<form class="filters">
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" className="sect-select" value="" onChange={handleChange} checked={"" == selected} />
|
<input type="radio" className="sect-select" value="" onChange={handleChange} checked={"" === selected} />
|
||||||
All Programming Languages
|
All Programming Languages
|
||||||
</label>
|
</label>
|
||||||
{options}
|
{options}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState, useEffect, createContext } from "react";
|
import React, { useState, createContext } from "react";
|
||||||
|
|
||||||
//https://levelup.gitconnected.com/dark-mode-in-react-533faaee3c6e
|
//https://levelup.gitconnected.com/dark-mode-in-react-533faaee3c6e
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue