mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-13 20:31:48 +00:00
feat(SearchBar): use navigate instead window location
This commit is contained in:
parent
173745042c
commit
6b35568f85
1 changed files with 7 additions and 4 deletions
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright (C) 2017-2023 Smart code 203358507
|
||||
|
||||
const React = require('react');
|
||||
const { useNavigate } = require('react-router');
|
||||
const { useSearchParams } = require('react-router-dom');
|
||||
const PropTypes = require('prop-types');
|
||||
const classnames = require('classnames');
|
||||
const debounce = require('lodash.debounce');
|
||||
|
|
@ -22,16 +24,17 @@ const SearchBar = React.memo(({ className, query, active }) => {
|
|||
const searchHistory = useSearchHistory();
|
||||
const localSearch = useLocalSearch();
|
||||
const { createTorrentFromMagnet } = useTorrent();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [historyOpen, openHistory, closeHistory, ] = useBinaryState(query === null ? true : false);
|
||||
const [currentQuery, setCurrentQuery] = React.useState(query || '');
|
||||
|
||||
const [, setSearchParams] = useSearchParams();
|
||||
const searchInputRef = React.useRef(null);
|
||||
const containerRef = React.useRef(null);
|
||||
|
||||
const searchBarOnClick = React.useCallback(() => {
|
||||
if (!active) {
|
||||
window.location = '#/search';
|
||||
navigate('/search');
|
||||
}
|
||||
}, [active]);
|
||||
|
||||
|
|
@ -64,7 +67,7 @@ const SearchBar = React.memo(({ className, query, active }) => {
|
|||
const searchValue = `/search?search=${encodeURIComponent(event.target.value)}`;
|
||||
setCurrentQuery(searchValue);
|
||||
if (searchInputRef.current && searchValue) {
|
||||
window.location.hash = searchValue;
|
||||
setSearchParams({ search: event.target.value });
|
||||
closeHistory();
|
||||
}
|
||||
}, []);
|
||||
|
|
@ -72,7 +75,7 @@ const SearchBar = React.memo(({ className, query, active }) => {
|
|||
const queryInputClear = React.useCallback(() => {
|
||||
searchInputRef.current.value = '';
|
||||
setCurrentQuery('');
|
||||
window.location.hash = '/search';
|
||||
navigate('/search', { search: '' });
|
||||
}, []);
|
||||
|
||||
const updateLocalSearchDebounced = React.useCallback(debounce((query) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue