Skip to content

Commit

Permalink
Minor fixes, removal of debug code, scrollbars always slightly visible
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Aug 28, 2024
1 parent 548e20c commit fa41d0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
44 changes: 20 additions & 24 deletions frontend/src/lib/components/SortableList/sortableList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { createPortal } from "@lib/utils/createPortal";
import { MANHATTAN_LENGTH, rectContainsPoint } from "@lib/utils/geometry";
import { MANHATTAN_LENGTH, Rect2D, rectContainsPoint } from "@lib/utils/geometry";
import { resolveClassNames } from "@lib/utils/resolveClassNames";
import { Vec2, point2Distance, vec2FromPointerEvent } from "@lib/utils/vec2";

Expand Down Expand Up @@ -76,12 +76,17 @@ export function SortableList(props: SortableListProps): React.ReactNode {
}

React.useEffect(
function addEventHandlers() {
function addEventListeners() {
if (!listDivRef.current) {
return;
}

if (!mainDivRef.current) {
return;
}

const currentListDivRef = listDivRef.current;
const currentMainDivRef = mainDivRef.current;

let pointerDownPosition: Vec2 | null = null;
let pointerDownPositionRelativeToElement: Vec2 = { x: 0, y: 0 };
Expand Down Expand Up @@ -199,14 +204,19 @@ export function SortableList(props: SortableListProps): React.ReactNode {

// If no element was found, check if the pointer is in the bottom area of the main list
const directChildren = elements.filter((el) => el.parentElement === currentListDivRef);
if (
mainDivRef.current &&
rectContainsPoint(mainDivRef.current.getBoundingClientRect(), vec2FromPointerEvent(e))
) {
return { element: directChildren[directChildren.length - 1], area: HoveredArea.BOTTOM };
const mainDivOriginalBoundingRect = currentMainDivRef.getBoundingClientRect();
const smallerMainDivRect: Rect2D = {
x: mainDivOriginalBoundingRect.x + 5,
y: mainDivOriginalBoundingRect.y + 5,
width: mainDivOriginalBoundingRect.width - 10,
height: mainDivOriginalBoundingRect.height - 10,
};

if (!rectContainsPoint(smallerMainDivRect, vec2FromPointerEvent(e))) {
return null;
}

return null;
return { element: directChildren[directChildren.length - 1], area: HoveredArea.BOTTOM };
}

function getItemPositionInGroup(item: HTMLElement): number {
Expand Down Expand Up @@ -276,20 +286,6 @@ export function SortableList(props: SortableListProps): React.ReactNode {
const positionDelta = hoveredElementAndArea.area === HoveredArea.TOP ? 0 : 1;
const newPosition = getItemPositionInGroup(hoveredElementAndArea.element) + positionDelta;
const currentPosition = getItemPositionInGroup(draggedElement.element);
const hoveredItemParentGroupId = getItemParentGroupId(hoveredElementAndArea.element);

console.debug(
"newPosition",
newPosition,
"currentPosition",
currentPosition,
"positionDelta",
positionDelta,
"draggedElementParentGroupId",
draggedElement.parentId,
"hoveredItemParentGroupId",
hoveredItemParentGroupId
);

if (
draggedElement.parentId === getItemParentGroupId(hoveredElementAndArea.element) &&
Expand Down Expand Up @@ -429,7 +425,7 @@ export function SortableList(props: SortableListProps): React.ReactNode {
document.addEventListener("keydown", handleKeyDown);
window.addEventListener("blur", handleWindowBlur);

return function removeEventHandlers() {
return function removeEventListeners() {
currentListDivRef.removeEventListener("pointerdown", handlePointerDown);
document.removeEventListener("pointermove", handlePointerMove);
document.removeEventListener("pointerup", handlePointerUp);
Expand Down Expand Up @@ -492,7 +488,7 @@ export function SortableList(props: SortableListProps): React.ReactNode {
ref={scrollDivRef}
onScroll={handleScroll}
>
<div className="flex flex-col border border-slate-100 relative max-h-0" ref={listDivRef}>
<div className="flex flex-col border border-slate-100 relative" ref={listDivRef}>
{makeChildren()}
<div className="h-2 min-h-2">
<div className="h-2" />
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ body {
border-radius: 2px;
width: 4px;
height: 4px;
background-color: rgba(190, 190, 190, 0);
background-color: rgba(190, 190, 190, 0.3);
transition: background-color 0.5s ease-in-out;
}

*:hover > *::-webkit-scrollbar-thumb {
width: 4px;
height: 4px;
background-color: rgba(190, 190, 190, 0.6);
background-color: rgba(190, 190, 190, 0.8);
transition: background-color 0.5s ease-in-out;
}

*:hover > *::-webkit-scrollbar-thumb:hover {
background-color: rgba(134, 134, 134, 0.8);
background-color: rgba(134, 134, 134, 0.9);
transition: background-color 0.5s ease-in-out;
}

Expand Down

0 comments on commit fa41d0a

Please sign in to comment.