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:
parent
21a9a4eaba
commit
9460875638
1 changed files with 26 additions and 1 deletions
|
@ -15,17 +15,42 @@ export default class App extends React.Component {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
searchIndex,
|
searchIndex,
|
||||||
showPopup: true
|
showPopup: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
|
this.initSetup();
|
||||||
await this.state.searchIndex.init();
|
await this.state.searchIndex.init();
|
||||||
this.setState({
|
this.setState({
|
||||||
indexComplete: true
|
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() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<AppContext.Provider value={{
|
<AppContext.Provider value={{
|
||||||
|
|
Loading…
Reference in a new issue