0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added hash link for opening search

refs https://github.com/TryGhost/Team/issues/1665

- adds custom hash url for opening sodo search on site - `/#/sodo-search
- closes the search popup by default
This commit is contained in:
Rishabh 2022-07-06 11:41:54 +02:00
parent 21a9a4eaba
commit 9460875638

View file

@ -15,17 +15,42 @@ export default class App extends React.Component {
this.state = {
searchIndex,
showPopup: true
showPopup: false
};
}
async componentDidMount() {
this.initSetup();
await this.state.searchIndex.init();
this.setState({
indexComplete: true
});
}
componentWillUnmount() {
/**Clear timeouts and event listeners on unmount */
window.removeEventListener('hashchange', this.hashHandler, false);
}
initSetup() {
// Listen to preview mode changes
this.handleSearchUrl();
this.hashHandler = () => {
this.handleSearchUrl();
};
window.addEventListener('hashchange', this.hashHandler, false);
}
handleSearchUrl() {
const [path] = window.location.hash.substr(1).split('?');
if (path === '/sodo-search') {
this.setState({
showPopup: true
});
window.history.replaceState('', document.title, window.location.pathname);
}
}
render() {
return (
<AppContext.Provider value={{