* feat: Prototype search UI using Instantsearch + Meilisearch --------- Co-authored-by: Braden MacDonald <braden@opencraft.com>
34 lines
796 B
JavaScript
34 lines
796 B
JavaScript
import { useEffect } from 'react';
|
|
import { history } from '@edx/frontend-platform';
|
|
|
|
export const useScrollToHashElement = ({ isLoading }) => {
|
|
useEffect(() => {
|
|
const currentHash = window.location.hash;
|
|
|
|
if (currentHash) {
|
|
const element = document.querySelector(currentHash);
|
|
|
|
if (element) {
|
|
element.scrollIntoView();
|
|
history.replace({ hash: '' });
|
|
}
|
|
}
|
|
}, [isLoading]);
|
|
};
|
|
|
|
export const useEscapeClick = ({ onEscape, dependency }) => {
|
|
useEffect(() => {
|
|
const handleEscapeClick = (event) => {
|
|
if (event.key === 'Escape') {
|
|
onEscape();
|
|
}
|
|
};
|
|
|
|
window.addEventListener('keydown', handleEscapeClick);
|
|
|
|
return () => {
|
|
window.removeEventListener('keydown', handleEscapeClick);
|
|
};
|
|
}, [dependency]);
|
|
};
|