Skip to content

Commit

Permalink
fix: make cursor grabbing hook more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
Preston-Cook committed Feb 3, 2025
1 parent fdf0a98 commit 99360bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/views/components/common/SortableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function SortableList<T extends BaseItem>({
}: ListProps<T>): JSX.Element {
const [active, setActive] = useState<Active | null>(null);
const [items, setItems] = useState<T[]>(draggables);
const { setCursor } = useCursor();
const { setCursorGrabbing } = useCursor();

useEffect(() => {
setItems(draggables);
Expand All @@ -73,11 +73,11 @@ export function SortableList<T extends BaseItem>({
modifiers={[restrictToParentElement]}
sensors={sensors}
onDragStart={({ active }) => {
setCursor('grabbing');
setCursorGrabbing(true);
setActive(active);
}}
onDragEnd={({ active, over }) => {
setCursor('default');
setCursorGrabbing(false);
if (over && active.id !== over.id) {
const activeIndex = items.findIndex(({ id }) => id === active.id);
const overIndex = items.findIndex(({ id }) => id === over.id);
Expand All @@ -88,7 +88,7 @@ export function SortableList<T extends BaseItem>({
setActive(null);
}}
onDragCancel={() => {
setCursor('default');
setCursorGrabbing(false);
setActive(null);
}}
>
Expand Down
13 changes: 7 additions & 6 deletions src/views/hooks/useCursor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ export const useCursor = () => {
const html = document.documentElement;
return () => {
html.style.removeProperty('cursor');
html.classList.remove('[&_*]:!cursor-grabbing', '!cursor-grabbing');
html.classList.remove('[&_*]:!cursor-grabbing');
};
}, []);

const setCursor = (cursor: string) => {
const setCursorGrabbing = (isGrabbing: boolean) => {
const html = document.documentElement;
if (cursor === 'grabbing') {
html.classList.add('[&_*]:!cursor-grabbing', '!cursor-grabbing');

if (isGrabbing) {
html.classList.add('[&_*]:!cursor-grabbing');
} else {
html.classList.remove('[&_*]:!cursor-grabbing', '!cursor-grabbing');
html.classList.remove('[&_*]:!cursor-grabbing');
}
};

return { setCursor };
return { setCursorGrabbing };
};

0 comments on commit 99360bf

Please sign in to comment.