mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Don't show move drop target on non-move drag operations (#5219)
This commit is contained in:
@@ -1,11 +1,26 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useListContextOptional } from "src/components/List/ListProvider";
|
import { useListContextOptional } from "src/components/List/ListProvider";
|
||||||
|
|
||||||
|
// Enum representing the possible sides for a drag operation.
|
||||||
export enum DragSide {
|
export enum DragSide {
|
||||||
BEFORE,
|
BEFORE,
|
||||||
AFTER,
|
AFTER,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook to manage drag and move selection functionality.
|
||||||
|
* Dragging while selecting will allow the user to select multiple items.
|
||||||
|
* Dragging from the drag handle will allow the user to move the item or selected items.
|
||||||
|
*
|
||||||
|
* @param props - The properties for the hook.
|
||||||
|
* @param props.selecting - Whether the one or more items have been selected.
|
||||||
|
* @param props.selected - Whether this item is currently selected.
|
||||||
|
* @param props.onSelectedChanged - Callback when the selected state changes.
|
||||||
|
* @param props.objectId - The ID of this object.
|
||||||
|
* @param props.onMove - Callback when a move operation occurs.
|
||||||
|
*
|
||||||
|
* @returns An object containing the drag event handlers and state.
|
||||||
|
*/
|
||||||
export function useDragMoveSelect(props: {
|
export function useDragMoveSelect(props: {
|
||||||
selecting: boolean;
|
selecting: boolean;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
@@ -15,8 +30,12 @@ export function useDragMoveSelect(props: {
|
|||||||
}) {
|
}) {
|
||||||
const { selectedIds } = useListContextOptional();
|
const { selectedIds } = useListContextOptional();
|
||||||
|
|
||||||
|
// true if the mouse is over the drag handle
|
||||||
const [inHandle, setInHandle] = useState(false);
|
const [inHandle, setInHandle] = useState(false);
|
||||||
|
|
||||||
|
// true if this is the source of a move operation
|
||||||
const [moveSrc, setMoveSrc] = useState(false);
|
const [moveSrc, setMoveSrc] = useState(false);
|
||||||
|
// the target side for a move operation
|
||||||
const [moveTarget, setMoveTarget] = useState<DragSide | undefined>();
|
const [moveTarget, setMoveTarget] = useState<DragSide | undefined>();
|
||||||
|
|
||||||
const canSelect = props.onSelectedChanged && props.selecting;
|
const canSelect = props.onSelectedChanged && props.selecting;
|
||||||
@@ -75,6 +94,7 @@ export function useDragMoveSelect(props: {
|
|||||||
ev.dataTransfer.dropEffect = "copy";
|
ev.dataTransfer.dropEffect = "copy";
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
} else if (ev.dataTransfer.effectAllowed === "move" && !moveSrc) {
|
} else if (ev.dataTransfer.effectAllowed === "move" && !moveSrc) {
|
||||||
|
// don't allow move on self
|
||||||
doSetMoveTarget(event);
|
doSetMoveTarget(event);
|
||||||
ev.dataTransfer.dropEffect = "move";
|
ev.dataTransfer.dropEffect = "move";
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
@@ -92,7 +112,8 @@ export function useDragMoveSelect(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onDragOver(event: React.DragEvent<HTMLElement>) {
|
function onDragOver(event: React.DragEvent<HTMLElement>) {
|
||||||
if (event.dataTransfer.effectAllowed === "move" && moveSrc) {
|
// only set move target if move is allowed, or if this is not the source of the move
|
||||||
|
if (event.dataTransfer.effectAllowed !== "move" || moveSrc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user