mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Moved fetching site data to first load of search popup
refs https://github.com/TryGhost/Team/issues/1665 - previously the search was loading site data on load for indexing, which adds unnecessary load if search is not used - moves data fetch and indexing to when the search popup is opened first time avoiding unnecessary fetch
This commit is contained in:
parent
c30cb19650
commit
1e57af8fdd
@ -15,16 +15,14 @@ export default class App extends React.Component {
|
||||
|
||||
this.state = {
|
||||
searchIndex,
|
||||
showPopup: false
|
||||
showPopup: false,
|
||||
indexStarted: false,
|
||||
indexComplete: false
|
||||
};
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
componentDidMount() {
|
||||
this.initSetup();
|
||||
await this.state.searchIndex.init();
|
||||
this.setState({
|
||||
indexComplete: true
|
||||
});
|
||||
}
|
||||
|
||||
componentDidUpdate(_prevProps, _prevState) {
|
||||
@ -33,6 +31,20 @@ export default class App extends React.Component {
|
||||
searchValue: ''
|
||||
});
|
||||
}
|
||||
|
||||
if (this.state.showPopup && !this.state.indexStarted) {
|
||||
this.setupSearchIndex();
|
||||
}
|
||||
}
|
||||
|
||||
async setupSearchIndex() {
|
||||
this.setState({
|
||||
indexStarted: true
|
||||
});
|
||||
await this.state.searchIndex.init();
|
||||
this.setState({
|
||||
indexComplete: true
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -9,7 +9,10 @@ const AppContext = React.createContext({
|
||||
lastPage: '',
|
||||
page: '',
|
||||
pageData: {},
|
||||
dispatch: (_action, _data) => {}
|
||||
dispatch: (_action, _data) => {},
|
||||
searchIndex: null,
|
||||
indexComplete: false,
|
||||
searchValue: ''
|
||||
});
|
||||
|
||||
export default AppContext;
|
||||
|
Loading…
Reference in New Issue
Block a user