Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/components/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import produce from 'immer';
import {memo, useState, useEffect, useMemo, useCallback, useRef} from 'react';
import * as Icon from 'react-feather';
import {useTranslation} from 'react-i18next';
import {useTranslation, getInitialProps} from 'react-i18next';
import {Link} from 'react-router-dom';
import {useDebounce, useKeyPressEvent, useUpdateEffect} from 'react-use';

Expand Down Expand Up @@ -42,6 +42,7 @@ const stateSuggestions = [
function Search() {
const [searchValue, setSearchValue] = useState('');
const [expand, setExpand] = useState(false);
const [language, setLanguage] = useState(getInitialProps().initialLanguage);
const [results, setResults] = useState([]);
const searchInput = useRef(null);
const {t} = useTranslation();
Expand Down Expand Up @@ -174,6 +175,10 @@ function Search() {
target.textContent = '';
return true;
}
if (language != getInitialProps().initialLanguage) {
setLanguage(getInitialProps().initialLanguage);
return true;
}
const text = t(suggestions[index]);
const placeholder = target.textContent;
target.classList.remove('disappear');
Expand All @@ -186,7 +191,7 @@ function Search() {
}
callback();
},
[expand, t]
[language, expand, t]
);

const clearPlaceholder = useCallback((target, callback) => {
Expand All @@ -208,7 +213,10 @@ function Search() {
target.textContent = '';
return true;
}

if (language != getInitialProps().initialLanguage) {
setLanguage(getInitialProps().initialLanguage);
return true;
}
fillPlaceholder(target, index, 0, function () {
setTimeout(function () {
clearPlaceholder(target, function () {
Expand All @@ -217,7 +225,7 @@ function Search() {
}, 2000);
});
},
[clearPlaceholder, expand, fillPlaceholder]
[language, clearPlaceholder, expand, fillPlaceholder]
);

useEffect(() => {
Expand Down