mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-18 23:18:27 +00:00
fix search when change repoID (#6338)
* fix search when change repoID * change function name
This commit is contained in:
parent
1963e7538e
commit
10dfe2e47c
@ -30,7 +30,6 @@ export default class AISearch extends Component {
|
|||||||
path: PropTypes.string,
|
path: PropTypes.string,
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
onSearchedClick: PropTypes.func.isRequired,
|
onSearchedClick: PropTypes.func.isRequired,
|
||||||
repoName: PropTypes.string,
|
|
||||||
currentRepoInfo: PropTypes.object,
|
currentRepoInfo: PropTypes.object,
|
||||||
isViewFile: PropTypes.bool,
|
isViewFile: PropTypes.bool,
|
||||||
isLibView: PropTypes.bool,
|
isLibView: PropTypes.bool,
|
||||||
@ -64,22 +63,10 @@ export default class AISearch extends Component {
|
|||||||
this.inputRef = React.createRef();
|
this.inputRef = React.createRef();
|
||||||
this.searchContainer = React.createRef();
|
this.searchContainer = React.createRef();
|
||||||
this.searchResultListRef = React.createRef();
|
this.searchResultListRef = React.createRef();
|
||||||
|
this.searchResultListContainerRef = React.createRef();
|
||||||
this.indexStateTimer = null;
|
this.indexStateTimer = null;
|
||||||
this.isChineseInput = false;
|
this.isChineseInput = false;
|
||||||
if (props.isLibView && props.currentRepoInfo) {
|
this.calculateStoreKey(props);
|
||||||
this.isRepoOwner = props.currentRepoInfo.owner_email === username;
|
|
||||||
this.isAdmin = props.currentRepoInfo.is_admin;
|
|
||||||
} else {
|
|
||||||
this.isRepoOwner = false;
|
|
||||||
this.isAdmin = false;
|
|
||||||
}
|
|
||||||
this.searchResultListContainerRef = React.createRef();
|
|
||||||
const { repoID } = props;
|
|
||||||
let storeKey = 'sfVisitedAISearchItems';
|
|
||||||
if (repoID) {
|
|
||||||
storeKey += repoID;
|
|
||||||
}
|
|
||||||
this.storeKey = storeKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -88,12 +75,45 @@ export default class AISearch extends Component {
|
|||||||
document.addEventListener('compositionend', this.onCompositionEnd);
|
document.addEventListener('compositionend', this.onCompositionEnd);
|
||||||
document.addEventListener('click', this.handleOutsideClick);
|
document.addEventListener('click', this.handleOutsideClick);
|
||||||
if (this.props.isLibView) {
|
if (this.props.isLibView) {
|
||||||
this.queryLibraryIndexState();
|
this.queryLibraryIndexState(this.props.repoID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
queryLibraryIndexState() {
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
seafileAPI.queryLibraryIndexState(this.props.repoID).then(res => {
|
this.calculateStoreKey(nextProps);
|
||||||
|
if (nextProps.isLibView) {
|
||||||
|
if (this.props.repoID !== nextProps.repoID) {
|
||||||
|
this.queryLibraryIndexState(nextProps.repoID);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.indexStateTimer) {
|
||||||
|
clearInterval(this.indexStateTimer);
|
||||||
|
this.indexStateTimer = null;
|
||||||
|
}
|
||||||
|
this.isChineseInput = false;
|
||||||
|
this.setState({
|
||||||
|
indexState: '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateStoreKey = (props) => {
|
||||||
|
if (props.isLibView && props.currentRepoInfo) {
|
||||||
|
this.isRepoOwner = props.currentRepoInfo.owner_email === username;
|
||||||
|
this.isAdmin = props.currentRepoInfo.is_admin;
|
||||||
|
} else {
|
||||||
|
this.isRepoOwner = false;
|
||||||
|
this.isAdmin = false;
|
||||||
|
}
|
||||||
|
let storeKey = 'sfVisitedAISearchItems';
|
||||||
|
if (props.repoID) {
|
||||||
|
storeKey += props.repoID;
|
||||||
|
}
|
||||||
|
this.storeKey = storeKey;
|
||||||
|
};
|
||||||
|
|
||||||
|
queryLibraryIndexState(repoID) {
|
||||||
|
seafileAPI.queryLibraryIndexState(repoID).then(res => {
|
||||||
const { state: indexState, task_id: taskId } = res.data;
|
const { state: indexState, task_id: taskId } = res.data;
|
||||||
this.setState({ indexState }, () => {
|
this.setState({ indexState }, () => {
|
||||||
if (indexState === INDEX_STATE.RUNNING) {
|
if (indexState === INDEX_STATE.RUNNING) {
|
||||||
|
@ -58,12 +58,7 @@ class Search extends Component {
|
|||||||
this.searchResultListRef = React.createRef();
|
this.searchResultListRef = React.createRef();
|
||||||
this.isChineseInput = false;
|
this.isChineseInput = false;
|
||||||
this.searchResultListContainerRef = React.createRef();
|
this.searchResultListContainerRef = React.createRef();
|
||||||
const { repoID } = props;
|
this.calculateStoreKey(props);
|
||||||
let storeKey = 'sfVisitedSearchItems';
|
|
||||||
if (repoID) {
|
|
||||||
storeKey += repoID;
|
|
||||||
}
|
|
||||||
this.storeKey = storeKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -72,6 +67,11 @@ class Search extends Component {
|
|||||||
document.addEventListener('compositionend', this.onCompositionEnd);
|
document.addEventListener('compositionend', this.onCompositionEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
this.calculateStoreKey(nextProps);
|
||||||
|
this.isChineseInput = false;
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
document.removeEventListener('keydown', this.onDocumentKeydown);
|
document.removeEventListener('keydown', this.onDocumentKeydown);
|
||||||
document.removeEventListener('compositionstart', this.onCompositionStart);
|
document.removeEventListener('compositionstart', this.onCompositionStart);
|
||||||
@ -79,6 +79,15 @@ class Search extends Component {
|
|||||||
this.isChineseInput = false;
|
this.isChineseInput = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calculateStoreKey = (props) => {
|
||||||
|
const { repoID } = props;
|
||||||
|
let storeKey = 'sfVisitedSearchItems';
|
||||||
|
if (repoID) {
|
||||||
|
storeKey += repoID;
|
||||||
|
}
|
||||||
|
this.storeKey = storeKey;
|
||||||
|
};
|
||||||
|
|
||||||
onCompositionStart = () => {
|
onCompositionStart = () => {
|
||||||
this.isChineseInput = true;
|
this.isChineseInput = true;
|
||||||
};
|
};
|
||||||
|
@ -32,6 +32,7 @@ class CommonToolbar extends React.Component {
|
|||||||
isLibView: props.isLibView,
|
isLibView: props.isLibView,
|
||||||
path: props.path,
|
path: props.path,
|
||||||
isViewFile: props.isViewFile,
|
isViewFile: props.isViewFile,
|
||||||
|
currentRepoInfo: props.currentRepoInfo,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,12 +46,12 @@ class CommonToolbar extends React.Component {
|
|||||||
this.unsubscribeLibChange && this.unsubscribeLibChange();
|
this.unsubscribeLibChange && this.unsubscribeLibChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
onRepoChange = ({ repoID, repoName, isLibView, path, isViewFile }) => {
|
onRepoChange = ({ repoID, repoName, isLibView, path, isViewFile, currentRepoInfo }) => {
|
||||||
this.setState({ repoID, repoName, isLibView, path, isViewFile });
|
this.setState({ repoID, repoName, isLibView, path, isViewFile, currentRepoInfo });
|
||||||
};
|
};
|
||||||
|
|
||||||
renderSearch = () => {
|
renderSearch = () => {
|
||||||
const { repoID, repoName, isLibView, path, isViewFile } = this.state;
|
const { repoID, repoName, isLibView, path, isViewFile, currentRepoInfo } = this.state;
|
||||||
const { searchPlaceholder } = this.props;
|
const { searchPlaceholder } = this.props;
|
||||||
const placeholder = searchPlaceholder || gettext('Search files');
|
const placeholder = searchPlaceholder || gettext('Search files');
|
||||||
|
|
||||||
@ -62,9 +63,8 @@ class CommonToolbar extends React.Component {
|
|||||||
path={path}
|
path={path}
|
||||||
isViewFile={isViewFile}
|
isViewFile={isViewFile}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
|
currentRepoInfo={currentRepoInfo}
|
||||||
onSearchedClick={this.props.onSearchedClick}
|
onSearchedClick={this.props.onSearchedClick}
|
||||||
repoName={repoName}
|
|
||||||
currentRepoInfo={this.props.currentRepoInfo}
|
|
||||||
isLibView={isLibView}
|
isLibView={isLibView}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -207,6 +207,7 @@ class LibContentView extends React.Component {
|
|||||||
path: '',
|
path: '',
|
||||||
isViewFile: false,
|
isViewFile: false,
|
||||||
isLibView: false,
|
isLibView: false,
|
||||||
|
currentRepoInfo: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,6 +216,7 @@ class LibContentView extends React.Component {
|
|||||||
this.props.eventBus.dispatch(EVENT_BUS_TYPE.CURRENT_LIBRARY_CHANGED, {
|
this.props.eventBus.dispatch(EVENT_BUS_TYPE.CURRENT_LIBRARY_CHANGED, {
|
||||||
repoID: this.props.repoID,
|
repoID: this.props.repoID,
|
||||||
repoName: this.state.repoName,
|
repoName: this.state.repoName,
|
||||||
|
currentRepoInfo: this.state.currentRepoInfo,
|
||||||
path: this.state.path,
|
path: this.state.path,
|
||||||
isViewFile: this.state.isViewFile,
|
isViewFile: this.state.isViewFile,
|
||||||
isLibView: true,
|
isLibView: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user