login for RN app
This commit is contained in:
@@ -161,23 +161,9 @@ class ArtikelSearchPage extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
restoreStoredQuery = (stored) => {
|
||||
this.props.navigate(
|
||||
buildSearchUrl(stored.target, stored.filter ?? '', stored.offset ?? 0),
|
||||
{ replace: true },
|
||||
);
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
document.addEventListener('mousedown', preserveSearchFocus, true);
|
||||
window.addEventListener('resize', this.handleWindowResize);
|
||||
|
||||
const query = queryFromParams(this.props.searchParams);
|
||||
const stored = readArtikelQuery();
|
||||
|
||||
if (query.target.trim().length < 3 && stored?.target?.trim().length >= 3) {
|
||||
this.restoreStoredQuery(stored);
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@@ -192,14 +178,6 @@ class ArtikelSearchPage extends Component {
|
||||
const target = searchParams.get('target') ?? '';
|
||||
const prevTarget = prev.get('target') ?? '';
|
||||
|
||||
if (target.trim().length < 3 && prevTarget.trim().length >= 3) {
|
||||
const stored = readArtikelQuery();
|
||||
if (stored?.target?.trim().length >= 3) {
|
||||
this.restoreStoredQuery(stored);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (target !== prevTarget && target !== this.state.input) {
|
||||
this.setState({ input: target });
|
||||
}
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { buildSearchUrl, queryFromParams, readArtikelQuery } from './artikelQuery';
|
||||
|
||||
export default function withSearchParams(Wrapped) {
|
||||
function SearchParamsWrapper(props) {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
const query = queryFromParams(searchParams);
|
||||
if (query.target.trim().length >= 3) return;
|
||||
|
||||
const stored = readArtikelQuery();
|
||||
if (!stored?.target || stored.target.trim().length < 3) return;
|
||||
|
||||
navigate(
|
||||
buildSearchUrl(stored.target, stored.filter ?? '', stored.offset ?? 0),
|
||||
{ replace: true },
|
||||
);
|
||||
}, [searchParams, navigate]);
|
||||
|
||||
return (
|
||||
<Wrapped
|
||||
{...props}
|
||||
|
||||
Reference in New Issue
Block a user