mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 01:16:18 -05:00
Removing search suggestions context. Passing suggestions down to search table.
This commit is contained in:
parent
c9f7520604
commit
170e227bf9
4 changed files with 18 additions and 42 deletions
|
|
@ -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 <ThemeProvider>
|
||||
<TagsProvider>
|
||||
<FilePreviewProvider>
|
||||
<SearchSuggestionsProvider>
|
||||
<header>
|
||||
<NavBar/>
|
||||
</header>
|
||||
<Outlet/>
|
||||
<Footer/>
|
||||
</SearchSuggestionsProvider>
|
||||
<header>
|
||||
<NavBar/>
|
||||
</header>
|
||||
<Outlet/>
|
||||
<Footer/>
|
||||
</FilePreviewProvider>
|
||||
</TagsProvider>
|
||||
</ThemeProvider>
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
</React.Fragment>;
|
||||
if (searchStr || (activeTags && activeTags.length > 0)) {
|
||||
// User has submitted and wants full search.
|
||||
body = <SearchView/>;
|
||||
body = <SearchView suggestions={suggestions} suggestionsSums={suggestionsSums} loading={loading}/>;
|
||||
}
|
||||
|
||||
const getSearchResultsInput = (props) => {
|
||||
|
|
|
|||
|
|
@ -673,7 +673,7 @@ export function CardPoster({to, file}) {
|
|||
const image = <>
|
||||
{/* Replicate <Image label/> but with maxHeight applied to image */}
|
||||
{imageLabel}
|
||||
<img alt='poster' src={posterPath} style={{maxHeight: '163px', width: 'auto'}}/>
|
||||
<img alt='poster' src={posterPath} style={{maxHeight: '163px', maxWidth: '290px', width: 'auto'}}/>
|
||||
</>;
|
||||
|
||||
if (to) {
|
||||
|
|
|
|||
|
|
@ -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 <Search/> 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 <SearchSuggestionsContext.Provider value={value}>
|
||||
{props.children}
|
||||
</SearchSuggestionsContext.Provider>
|
||||
}
|
||||
|
||||
|
||||
export function SearchView() {
|
||||
const {suggestions, suggestionsSums, loading} = useContext(SearchSuggestionsContext);
|
||||
export function SearchView({suggestions, suggestionsSums, loading}) {
|
||||
|
||||
const filesTabName = <span>Files <Label>{normalizeEstimate(suggestionsSums?.fileGroups)}</Label></span>;
|
||||
const zimsTabName = <span>Zims <Label>{normalizeEstimate(suggestionsSums?.zims)}</Label></span>;
|
||||
|
|
@ -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 <React.Fragment>
|
||||
<TabLinks links={links}/>
|
||||
|
|
@ -317,7 +295,7 @@ export function SearchIconButton() {
|
|||
loading,
|
||||
searchStr,
|
||||
setSearchStr,
|
||||
} = useContext(SearchSuggestionsContext);
|
||||
} = useSearchSuggestions();
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
||||
const localHandleResultSelect = (i) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue