1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-14 14:21:23 +00:00

Merge pull request #5064 from haiwen/keep-query

[search] keep the query keyword when entering the independent search …
This commit is contained in:
Daniel Pan
2021-12-17 14:05:47 +08:00
committed by GitHub
2 changed files with 18 additions and 10 deletions

View File

@@ -18,6 +18,7 @@ class Search extends Component {
constructor(props) {
super(props);
this.baseSearchPageURL = `${siteRoot}search/`;
this.state = {
width: 'default',
value: '',
@@ -28,6 +29,7 @@ class Search extends Component {
isResultGetted: false,
isCloseShow: false,
isSearchInputShow: false, // for mobile
searchPageUrl: this.baseSearchPageURL
};
this.inputValue = '';
this.source = null; // used to cancel request;
@@ -120,6 +122,7 @@ class Search extends Component {
toaster.danger(errMessage);
});
} else {
this.updateSearchPageURL(queryData);
seafileAPI.searchFiles(queryData,cancelToken).then(res => {
if (!res.data.total) {
_this.setState({
@@ -148,6 +151,14 @@ class Search extends Component {
this.source.cancel('prev request is cancelled');
}
updateSearchPageURL(queryData) {
let params = '';
for (let key in queryData) {
params += key + '=' + encodeURIComponent(queryData[key]) + '&';
}
this.setState({searchPageUrl: `${this.baseSearchPageURL}?${params.substring(0, params.length - 1)}`});
}
getValueLength(str) {
var i = 0, code, len = 0;
for (; i < str.length; i++) {
@@ -253,13 +264,10 @@ class Search extends Component {
});
}
onSearchPage = () => {
window.location.href = siteRoot + 'search/';
}
render() {
let width = this.state.width !== 'default' ? this.state.width : '';
let style = {'width': width};
const { searchPageUrl } = this.state;
return (
<Fragment>
<MediaQuery query="(min-width: 768px)">
@@ -280,7 +288,7 @@ class Search extends Component {
autoComplete="off"
/>
{(this.state.isCloseShow && username) &&
<a href={`${siteRoot}search/`} className="search-icon-right input-icon-addon fas fa-external-link-alt search-icon-arrow"></a>
<a href={searchPageUrl} className="search-icon-right input-icon-addon fas fa-external-link-alt search-icon-arrow"></a>
}
{this.state.isCloseShow &&
<button type="button" className="search-icon-right input-icon-addon fas fa-times border-0 bg-transparent" onClick={this.onCloseHandler} aria-label={gettext('Close')}></button>
@@ -314,7 +322,7 @@ class Search extends Component {
autoComplete="off"
/>
{(this.state.isCloseShow && username) &&
<a href={`${siteRoot}search/`} className="search-icon-right input-icon-addon fas fa-external-link-alt search-icon-arrow"></a>
<a href={searchPageUrl} className="search-icon-right input-icon-addon fas fa-external-link-alt search-icon-arrow"></a>
}
{this.state.isCloseShow &&
<button type="button" className="search-icon-right input-icon-addon fas fa-times border-0 bg-transparent" onClick={this.onCloseHandler} aria-label={gettext('Close')}></button>

View File

@@ -9,10 +9,10 @@
<script type="text/javascript">
window.search = {
pageOptions: {
q: '{{ keyword }}',
search_repo: '{{ search_repo }}',
search_ftypes: '{{ search_ftypes }}',
repo_name:'{{ repo.name }}',
q: '{{ keyword|escapejs }}',
search_repo: '{{ search_repo|escapejs }}',
search_ftypes: '{{ search_ftypes|escapejs }}',
repo_name:'{{ repo.name|escapejs }}',
}
}
</script>