Skip to content

Commit

Permalink
[ENG-1612] Fix mouse nav forwards and backwards (#2105)
Browse files Browse the repository at this point in the history
Fix mouse nav forwards and backwards
  • Loading branch information
ameer2468 authored Feb 19, 2024
1 parent bd1f11b commit e845082
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 21 additions & 2 deletions interface/app/$libraryId/Explorer/View/Grid/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HTMLAttributes, ReactNode, useMemo } from 'react';
import { useNavigate } from 'react-router';
import { useSelector, type ExplorerItem } from '@sd/client';
import { useOperatingSystem } from '~/hooks';
import { useRoutingContext } from '~/RoutingContext';

import { useExplorerContext } from '../../Context';
import { explorerStore, isCut } from '../../store';
Expand All @@ -17,6 +20,9 @@ interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
export const GridItem = ({ children, item, index, ...props }: Props) => {
const explorer = useExplorerContext();
const explorerView = useExplorerViewContext();
const { currentIndex, maxIndex } = useRoutingContext();
const os = useOperatingSystem();
const navigate = useNavigate();

const dragSelect = useDragSelectContext();

Expand All @@ -31,16 +37,29 @@ export const GridItem = ({ children, item, index, ...props }: Props) => {
[explorer.selectedItems, item]
);

const canGoBack = currentIndex !== 0;
const canGoForward = currentIndex !== maxIndex;

const { attributes } = useDragSelectable({ index, id: uniqueId(item), selected });

return (
<div
{...props}
{...attributes}
className="h-full w-full"
className="w-full h-full"
// Prevent explorer view onMouseDown event from
// being executed and resetting the selection
onMouseDown={(e) => e.stopPropagation()}
onMouseDown={(e) => {
if (os === 'browser') return;
e.stopPropagation();
if (e.buttons === 8 || e.buttons === 3) {
if (!canGoBack) return;
navigate(-1);
} else if (e.buttons === 16 || e.buttons === 4) {
if (!canGoForward) return;
navigate(1);
}
}}
onContextMenu={(e) => {
if (!explorerView.selectable || explorer.selectedItems.has(item)) return;
explorer.resetSelectedItems([item]);
Expand Down
5 changes: 3 additions & 2 deletions interface/app/$libraryId/TopBar/NavigationButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ export const NavigationButtons = () => {

useEffect(() => {
const onMouseDown = (e: MouseEvent) => {
if (os === 'browser') return;
e.stopPropagation();
if (e.buttons === 8) {
if (e.buttons === 8 || e.buttons === 3) {
if (!canGoBack) return;
navigate(-1);
} else if (e.buttons === 16) {
} else if (e.buttons === 16 || e.buttons === 4) {
if (!canGoForward) return;
navigate(1);
}
Expand Down

0 comments on commit e845082

Please sign in to comment.