OS check for mouse navigate (#1621)

Update useMouseNavigate.ts
This commit is contained in:
ameer2468 2023-10-18 11:32:25 +03:00 committed by GitHub
parent a4acd2c533
commit 1fe61700e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,22 +1,24 @@
import { useNavigate } from "react-router";
import { useSearchStore } from "~/hooks";
import { MouseEvent } from "react";
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 { isFocused } = useSearchStore();
const os = useOperatingSystem();
const realOs = useOperatingSystem(true);
const handler = (e: MouseEvent) => {
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);
}
}
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;
}
};