mirror of https://github.com/buster-so/buster.git
change prevent navigation to actually drop listener
This commit is contained in:
parent
93f3f880f9
commit
693b652d38
|
@ -17,6 +17,7 @@ stop:
|
||||||
pkill ollama
|
pkill ollama
|
||||||
|
|
||||||
fast:
|
fast:
|
||||||
export RUST_LOG=debug
|
cd .. && docker compose up -d redis && cd api && \
|
||||||
export CARGO_INCREMENTAL=1
|
export RUST_LOG=debug && \
|
||||||
|
export CARGO_INCREMENTAL=1 && \
|
||||||
nice cargo watch -C server -x run
|
nice cargo watch -C server -x run
|
|
@ -68,7 +68,7 @@
|
||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"papaparse": "^5.5.2",
|
"papaparse": "^5.5.2",
|
||||||
"pluralize": "^8.0.0",
|
"pluralize": "^8.0.0",
|
||||||
"posthog-js": "^1.236.5",
|
"posthog-js": "^1.236.6",
|
||||||
"prettier": "^3.5.3",
|
"prettier": "^3.5.3",
|
||||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
@ -17986,9 +17986,9 @@
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/posthog-js": {
|
"node_modules/posthog-js": {
|
||||||
"version": "1.236.5",
|
"version": "1.236.6",
|
||||||
"resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.236.5.tgz",
|
"resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.236.6.tgz",
|
||||||
"integrity": "sha512-2FrWVZwcLyeZAtdDckJaCfsk9m6DMdr/nVPVSqzF7yvm9pDsdbkvB3A16iqRj5L3EcqV2xWOcv8xWmKgdnNnqA==",
|
"integrity": "sha512-IX4fkn3HCK+ObdHr/AuWd+Ks7bgMpRpOQB93b5rDJAWkG4if4xFVUn5pgEjyCNeOO2GM1ECnp08q9tYNYEfwbA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core-js": "^3.38.1",
|
"core-js": "^3.38.1",
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"papaparse": "^5.5.2",
|
"papaparse": "^5.5.2",
|
||||||
"pluralize": "^8.0.0",
|
"pluralize": "^8.0.0",
|
||||||
"posthog-js": "^1.236.5",
|
"posthog-js": "^1.236.6",
|
||||||
"prettier": "^3.5.3",
|
"prettier": "^3.5.3",
|
||||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
|
|
@ -38,23 +38,24 @@ export const PreventNavigation: React.FC<PreventNavigationProps> = React.memo(
|
||||||
*/
|
*/
|
||||||
const handleClick = useMemoizedFn((event: MouseEvent) => {
|
const handleClick = useMemoizedFn((event: MouseEvent) => {
|
||||||
let originalTarget = event.target as HTMLElement;
|
let originalTarget = event.target as HTMLElement;
|
||||||
let target = event.target as HTMLElement;
|
|
||||||
let href: string | null = null;
|
|
||||||
let originalEvent = event;
|
let originalEvent = event;
|
||||||
|
|
||||||
// Traverse up the DOM tree looking for an anchor tag with href
|
const newEvent = new MouseEvent('click', {
|
||||||
while (target && !href) {
|
bubbles: true,
|
||||||
if (target instanceof HTMLAnchorElement && target.href) {
|
cancelable: true,
|
||||||
href = target.href;
|
view: window,
|
||||||
break;
|
detail: originalEvent.detail,
|
||||||
}
|
screenX: originalEvent.screenX,
|
||||||
target = target.parentElement as HTMLElement;
|
screenY: originalEvent.screenY,
|
||||||
}
|
clientX: originalEvent.clientX,
|
||||||
|
clientY: originalEvent.clientY,
|
||||||
// Check if we're navigating to the same URL - if so, allow the navigation
|
ctrlKey: originalEvent.ctrlKey,
|
||||||
if (href && new URL(href).pathname === window.location.pathname) {
|
altKey: originalEvent.altKey,
|
||||||
return; // Allow navigation to the same URL
|
shiftKey: originalEvent.shiftKey,
|
||||||
}
|
metaKey: originalEvent.metaKey,
|
||||||
|
button: originalEvent.button,
|
||||||
|
buttons: originalEvent.buttons
|
||||||
|
});
|
||||||
|
|
||||||
if (isDirty) {
|
if (isDirty) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -75,24 +76,6 @@ export const PreventNavigation: React.FC<PreventNavigationProps> = React.memo(
|
||||||
originalTarget.onclick = null;
|
originalTarget.onclick = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new click event
|
|
||||||
const newEvent = new MouseEvent('click', {
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
view: window,
|
|
||||||
detail: originalEvent.detail,
|
|
||||||
screenX: originalEvent.screenX,
|
|
||||||
screenY: originalEvent.screenY,
|
|
||||||
clientX: originalEvent.clientX,
|
|
||||||
clientY: originalEvent.clientY,
|
|
||||||
ctrlKey: originalEvent.ctrlKey,
|
|
||||||
altKey: originalEvent.altKey,
|
|
||||||
shiftKey: originalEvent.shiftKey,
|
|
||||||
metaKey: originalEvent.metaKey,
|
|
||||||
button: originalEvent.button,
|
|
||||||
buttons: originalEvent.buttons
|
|
||||||
});
|
|
||||||
|
|
||||||
// Dispatch the event directly on the original target
|
// Dispatch the event directly on the original target
|
||||||
originalTarget.dispatchEvent(newEvent);
|
originalTarget.dispatchEvent(newEvent);
|
||||||
|
|
||||||
|
@ -100,16 +83,14 @@ export const PreventNavigation: React.FC<PreventNavigationProps> = React.memo(
|
||||||
if (clickHandlers) {
|
if (clickHandlers) {
|
||||||
originalTarget.onclick = clickHandlers;
|
originalTarget.onclick = clickHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-attach our listeners after a short delay
|
|
||||||
setTimeout(() => {
|
|
||||||
document.querySelectorAll('a').forEach((link) => {
|
|
||||||
link.addEventListener('click', handleClick);
|
|
||||||
});
|
|
||||||
}, 50);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
setLeavingPage(true);
|
setLeavingPage(true);
|
||||||
|
} else {
|
||||||
|
document.querySelectorAll('a').forEach((link) => {
|
||||||
|
link.removeEventListener('click', handleClick);
|
||||||
|
});
|
||||||
|
originalTarget.dispatchEvent(newEvent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue