mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 01:46:18 -05:00
app: search Other tab distinguishes pending channels from none (#728)
* app: search Other tab distinguishes pending channels from none useSearchChannels initialised channels to [] and loading to false, and only set loading inside its mount effect, so the Other tab's first render painted "No Channels" with a count of 0 before the search had run. A failed search was rendered the same way, since the hook had no catch and the API helper returns undefined on a non-OK response. Invariants now enforced and tested: * null = pending, undefined = fetch failed, [] = no channels; loading is true from the first render because the search starts on mount. * Changing tags resets to pending, and only the newest request may write state, so a slow response for previous tags is dropped. * The tab shows a loader while pending, an error on failure, and "No Channels" only once the server confirmed there are none. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * app: useSearchChannels follows its caller's tags The hook read its tag argument only as the initial state, so the Other tab never refetched when the filter modal changed the URL's tags while the tab stayed mounted; the list, including a stale "No Channels", was whatever the mount fetched. The internal tag state now follows the argument's contents, keyed on the serialized list because the caller builds a new array every render. Tests change the hook argument after a loaded result and expect a second search and a reset to pending, check that a new array with the same tags does not refetch, and keep the slow-response drop. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
811793d767
commit
9caa140fb6
4 changed files with 184 additions and 9 deletions
|
|
@ -6,7 +6,7 @@ import {ShortcutHint} from "./ShortcutHint";
|
|||
import {ZimSearchView} from "./Zim";
|
||||
import {MapSearchView} from "./MapSearchView";
|
||||
import {searchEstimateFiles, searchEstimateMap, searchEstimateOthers, searchEstimateZims, searchSuggestions} from "../api";
|
||||
import {filterToMimetypes, fuzzyMatch, normalizeEstimate, SearchResultsInput, TabLinks} from "./Common";
|
||||
import {ErrorMessage, filterToMimetypes, fuzzyMatch, normalizeEstimate, SearchResultsInput, TabLinks} from "./Common";
|
||||
import _ from "lodash";
|
||||
import {TagsContext} from "../Tags";
|
||||
import {Accordion, Header, Icon, Label, Loading, Panel, Stack} from "./ui";
|
||||
|
|
@ -541,14 +541,17 @@ function SearchChannelPreview({channel}) {
|
|||
</div>
|
||||
}
|
||||
|
||||
function OtherSearchView({loading}) {
|
||||
// `channels` follows useSearchChannels: null = pending, undefined = fetch failed, [] = none.
|
||||
export function OtherSearchView({loading}) {
|
||||
const {searchParams} = React.useContext(QueryContext);
|
||||
const [activeValue, setActiveValue] = React.useState('channels');
|
||||
const activeTags = searchParams.getAll('tag');
|
||||
const {channels, loading: channelsLoading} = useSearchChannels(activeTags);
|
||||
|
||||
if (loading || channelsLoading) {
|
||||
if (loading || channelsLoading || channels === null) {
|
||||
return <Panel><Loading/></Panel>
|
||||
} else if (channels === undefined) {
|
||||
return <Panel><ErrorMessage>Could not fetch the channels.</ErrorMessage></Panel>
|
||||
}
|
||||
|
||||
return <Accordion value={activeValue} onChange={setActiveValue}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue