Files
spacedrive/interface/hooks/useMouseNavigate.ts
ameer2468 b39a108886 check correction for mouse navigation (#1653)
Update useMouseNavigate.ts
2023-10-21 18:36:56 +00:00

25 lines
683 B
TypeScript

import { MouseEvent } from 'react';
import { useNavigate } from 'react-router';
import { useOperatingSystem, useSearchStore } from '~/hooks';
export const useMouseNavigate = () => {
const idx = history.state.idx as number;
const navigate = useNavigate();
const { isFocused } = useSearchStore();
const os = useOperatingSystem();
const realOs = useOperatingSystem(true);
const handler = (e: MouseEvent) => {
if (os === 'browser' || realOs !== 'macOS') return;
if (e.buttons === 8) {
if (idx === 0 || isFocused) return;
navigate(-1);
} else if (e.buttons === 16) {
if (idx === history.length - 1 || isFocused) return;
navigate(1);
}
};
return handler;
};