237 |
238 | {({ changeTheme }) => {
239 | let willBeDarkMode = cookies.lightMode && cookies.lightMode.toLowerCase() !== "true"; //whether or not we are currently light mode and will become dark mode
240 | changeTheme(willBeDarkMode ? themes.light : themes.dark);
241 | return (
242 |
{
246 | setCookie("lightMode", willBeDarkMode);
247 | changeTheme(willBeDarkMode ? themes.light : themes.dark);
248 | }}
249 | style={{ width: "20px", height: "20px", display: "block", marginLeft: "auto" }}
250 | />
251 | );
252 | }}
253 |
254 |
295 |
296 |
297 | {loading ? (
298 | Loading
299 | ) : resultsList ? (
300 |
301 |
302 |
Search Results
303 |
304 |
305 | ) : searchParams.searchTerm ? (
306 |
307 |
308 |
No results found.
309 |
310 | ) :
311 |
312 | }
313 |
314 |
330 |
331 | );
332 | }
333 |
334 | export default App;
335 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import { render, screen } from '@testing-library/react';
2 | import App from './App';
3 |
4 | test('renders learn react link', () => {
5 | render(
96 |
97 |
Filter by Language
98 |
99 |
100 | {showFilters ? filterList : ""}
101 |
102 | );
103 | }
104 |
105 | export default LangFilters;
106 |
--------------------------------------------------------------------------------
/src/components/MarkdownParser.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from "react";
2 | import axios from "axios";
3 |
4 | import ReactMarkdown from "react-markdown";
5 | import rehypeSlug from "rehype-slug";
6 | import rehypeRaw from "rehype-raw";
7 |
8 | import ParsedLink from "./ParsedLink";
9 |
10 | function MarkdownParser({ file, sect }) {
11 | let [markdown, setMarkdown] = useState(null);
12 | const [loading, setLoading] = useState(true);
13 |
14 | useEffect(() => {
15 | async function fetchData() {
16 | try {
17 | // console.log({sect: sect, file: file});
18 | setLoading(true);
19 | let result = null;
20 | if (sect && file) {
21 | // Both sect and file exist so construct the URL with both parameters
22 | result = await axios.get(
23 | `https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/${sect}/${file}`
24 | );
25 | } else if (!sect && file) {
26 | // Occurs when getting a file from the root directory
27 | result = await axios.get(
28 | `https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/${file}`
29 | );
30 | } else {
31 | // Default to getting the README
32 | result = await axios.get(
33 | `https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/README.md`
34 | );
35 | }
36 |
37 | setMarkdown(result.data);
38 | } catch (e) {
39 | console.log("Couldn't get data. Please try again later");
40 | }
41 | setLoading(false);
42 | }
43 | fetchData();
44 | }, [file, sect]);
45 |
46 | if (loading) {
47 | return Loading...
;
48 | }
49 |
50 | if (!markdown) {
51 | return Error: Could not retrieve data.
;
52 | }
53 |
54 | return (
55 |