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:
@@ -18,6 +18,7 @@ class Search extends Component {
|
|||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.baseSearchPageURL = `${siteRoot}search/`;
|
||||||
this.state = {
|
this.state = {
|
||||||
width: 'default',
|
width: 'default',
|
||||||
value: '',
|
value: '',
|
||||||
@@ -28,6 +29,7 @@ class Search extends Component {
|
|||||||
isResultGetted: false,
|
isResultGetted: false,
|
||||||
isCloseShow: false,
|
isCloseShow: false,
|
||||||
isSearchInputShow: false, // for mobile
|
isSearchInputShow: false, // for mobile
|
||||||
|
searchPageUrl: this.baseSearchPageURL
|
||||||
};
|
};
|
||||||
this.inputValue = '';
|
this.inputValue = '';
|
||||||
this.source = null; // used to cancel request;
|
this.source = null; // used to cancel request;
|
||||||
@@ -120,6 +122,7 @@ class Search extends Component {
|
|||||||
toaster.danger(errMessage);
|
toaster.danger(errMessage);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
this.updateSearchPageURL(queryData);
|
||||||
seafileAPI.searchFiles(queryData,cancelToken).then(res => {
|
seafileAPI.searchFiles(queryData,cancelToken).then(res => {
|
||||||
if (!res.data.total) {
|
if (!res.data.total) {
|
||||||
_this.setState({
|
_this.setState({
|
||||||
@@ -148,6 +151,14 @@ class Search extends Component {
|
|||||||
this.source.cancel('prev request is cancelled');
|
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) {
|
getValueLength(str) {
|
||||||
var i = 0, code, len = 0;
|
var i = 0, code, len = 0;
|
||||||
for (; i < str.length; i++) {
|
for (; i < str.length; i++) {
|
||||||
@@ -253,13 +264,10 @@ class Search extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearchPage = () => {
|
|
||||||
window.location.href = siteRoot + 'search/';
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let width = this.state.width !== 'default' ? this.state.width : '';
|
let width = this.state.width !== 'default' ? this.state.width : '';
|
||||||
let style = {'width': width};
|
let style = {'width': width};
|
||||||
|
const { searchPageUrl } = this.state;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<MediaQuery query="(min-width: 768px)">
|
<MediaQuery query="(min-width: 768px)">
|
||||||
@@ -280,7 +288,7 @@ class Search extends Component {
|
|||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
/>
|
/>
|
||||||
{(this.state.isCloseShow && username) &&
|
{(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 &&
|
{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>
|
<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"
|
autoComplete="off"
|
||||||
/>
|
/>
|
||||||
{(this.state.isCloseShow && username) &&
|
{(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 &&
|
{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>
|
<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>
|
||||||
|
@@ -9,10 +9,10 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.search = {
|
window.search = {
|
||||||
pageOptions: {
|
pageOptions: {
|
||||||
q: '{{ keyword }}',
|
q: '{{ keyword|escapejs }}',
|
||||||
search_repo: '{{ search_repo }}',
|
search_repo: '{{ search_repo|escapejs }}',
|
||||||
search_ftypes: '{{ search_ftypes }}',
|
search_ftypes: '{{ search_ftypes|escapejs }}',
|
||||||
repo_name:'{{ repo.name }}',
|
repo_name:'{{ repo.name|escapejs }}',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user