diff --git a/app/src/App.js b/app/src/App.js
index b0fd943c..d4b881e0 100644
--- a/app/src/App.js
+++ b/app/src/App.js
@@ -21,7 +21,6 @@ import {SemanticToastContainer} from "react-semantic-toasts-2";
import {FilePreviewProvider} from "./components/FilePreview";
import {TagsProvider} from "./Tags";
import {ZimRoute} from "./components/Zim";
-import {SearchSuggestionsProvider} from "./components/Search";
function PageNotFound() {
const {t} = useContext(ThemeContext);
@@ -65,13 +64,11 @@ function Root() {
return
-
-
-
-
-
+
+
+
diff --git a/app/src/DashboardPage.js b/app/src/DashboardPage.js
index 66af8fae..72d9dd73 100644
--- a/app/src/DashboardPage.js
+++ b/app/src/DashboardPage.js
@@ -22,7 +22,7 @@ import {refreshFiles} from "./api";
import _ from "lodash";
import {TagsDashboard} from "./Tags";
import {Upload} from "./components/Upload";
-import {SearchSuggestionsContext, SearchView, useSearch} from "./components/Search";
+import {SearchView, useSearch, useSearchSuggestions} from "./components/Search";
import {KiwixRestartMessage, OutdatedZimsMessage} from "./components/Zim";
import {useSettings, useWROLMode} from "./hooks/customHooks";
import {FileSearchFilterButton} from "./components/Files";
@@ -160,15 +160,16 @@ export function DashboardPage() {
const {searchStr, setSearchStr, activeTags} = useSearch();
// The search that the user is typing.
const [localSearchStr, setLocalSearchStr] = React.useState(searchStr);
- console.log('searchStr', searchStr, 'localSearchStr', localSearchStr);
const {
+ suggestions,
suggestionsResults,
+ suggestionsSums,
handleResultSelect,
resultRenderer,
loading,
setSearchStr: setSuggestionSearchStr,
setSearchTags,
- } = useContext(SearchSuggestionsContext);
+ } = useSearchSuggestions(searchStr, activeTags);
const {status} = useContext(StatusContext);
React.useEffect(() => {
@@ -204,7 +205,7 @@ export function DashboardPage() {
;
if (searchStr || (activeTags && activeTags.length > 0)) {
// User has submitted and wants full search.
- body = ;
+ body = ;
}
const getSearchResultsInput = (props) => {
diff --git a/app/src/components/Common.js b/app/src/components/Common.js
index 31021fb2..def9e409 100644
--- a/app/src/components/Common.js
+++ b/app/src/components/Common.js
@@ -673,7 +673,7 @@ export function CardPoster({to, file}) {
const image = <>
{/* Replicate but with maxHeight applied to image */}
{imageLabel}
-
+
>;
if (to) {
diff --git a/app/src/components/Search.js b/app/src/components/Search.js
index 7b5e0f99..329f5d1b 100644
--- a/app/src/components/Search.js
+++ b/app/src/components/Search.js
@@ -1,4 +1,4 @@
-import React, {useContext, useState} from "react";
+import React, {useState} from "react";
import {createSearchParams, Route, Routes, useNavigate} from "react-router-dom";
import {FileSearchFilterButton, FilesSearchView} from "./Files";
import {useLatestRequest, usePages, useQuery} from "../hooks/customHooks";
@@ -94,18 +94,6 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false
}
}
-export const SearchSuggestionsContext = React.createContext({
- suggestions: {}, // from the api
- suggestionsResults: {}, // suggestions converted for results.
- suggestionsSums: {}, // suggestions from the api summarized.
- handleResultSelect: null, // user clicks "result"
- resultRenderer: null,
- loading: false,
- searchStr: '',
- setSearchStr: null,
- setSearchTags: null,
-});
-
export function useSuggestions(searchStr, tagNames) {
const defaultSuggestions = {
fileGroups: [],
@@ -115,9 +103,9 @@ export function useSuggestions(searchStr, tagNames) {
}
const [suggestions, setSuggestions] = React.useState(defaultSuggestions);
// fileGroups/channels/domains.
- const {data, sendRequest, loading} = useLatestRequest(500, true);
+ const {data, sendRequest, loading} = useLatestRequest(500);
// Zims are slow, so they are separate.
- const {data: zimData, sendRequest: sendZimRequest, loading: zimLoading} = useLatestRequest(500, true);
+ const {data: zimData, sendRequest: sendZimRequest, loading: zimLoading} = useLatestRequest(500);
React.useEffect(() => {
if ((searchStr && searchStr.length > 0) || (tagNames && tagNames.length > 0)) {
@@ -274,22 +262,12 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames) {
setSearchTags,
handleResultSelect,
resultRenderer,
- loading
+ loading,
}
}
-export const SearchSuggestionsProvider = (props) => {
- const value = useSearchSuggestions();
-
- return
- {props.children}
-
-}
-
-
-export function SearchView() {
- const {suggestions, suggestionsSums, loading} = useContext(SearchSuggestionsContext);
+export function SearchView({suggestions, suggestionsSums, loading}) {
const filesTabName = Files ;
const zimsTabName = Zims ;
@@ -297,7 +275,7 @@ export function SearchView() {
const links = [
{text: filesTabName, to: '/search', key: 'filesSearch', end: true},
{text: zimsTabName, to: '/search/zim', key: 'zimsSearch'},
- ]
+ ];
return
@@ -317,7 +295,7 @@ export function SearchIconButton() {
loading,
searchStr,
setSearchStr,
- } = useContext(SearchSuggestionsContext);
+ } = useSearchSuggestions();
const [open, setOpen] = React.useState(false);
const localHandleResultSelect = (i) => {