Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NP-24 Restrict sidebar auto-scrolling #691

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/planner/Planner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export default function Planner({
// Course that is currently being dragged
const [activeCourse, setActiveCourse] = useState<ActiveDragData | null>(null);

// Controls drag locking for the sidebar
const [isCourseDragging, setIsCourseDragging] = useState(false);

// Delay necessary so events inside draggables propagate
// valid sensors: https://github.com/clauderic/dnd-kit/discussions/82#discussioncomment-347608
const sensors = useSensors(
Expand All @@ -116,6 +119,7 @@ export default function Planner({
const handleOnDragStart = ({ active }: { active: Active }) => {
const originData = active.data.current as DragEventOriginData;
setActiveCourse({ from: originData.from, course: originData.course });
setIsCourseDragging(true);
};

const handleOnDragEnd = ({ active, over }: { active: Active; over: Over | null }) => {
Expand Down Expand Up @@ -143,15 +147,16 @@ export default function Planner({
);
}
}

setIsCourseDragging(false);
};

const ref = useRef<HTMLDivElement>(null);
// TODO: Use resizeobserver to change column count based on screen size

return (
<DndContext
// Enabling autoScroll causes odd behavior when dragging outside of a scrollable container (eg. Sidebar)
autoScroll={false}
autoScroll={true}
sensors={sensors}
collisionDetection={pointerWithin}
onDragStart={handleOnDragStart}
Expand Down Expand Up @@ -218,6 +223,7 @@ export default function Planner({
transferCredits={transferCredits}
getSearchedDragId={(course) => `course-list-searched-${course.id}`}
getRequirementDragId={(course) => `course-list-requirement-${course.id}`}
courseDragged={isCourseDragging}
/>
</div>
</DndContext>
Expand Down
6 changes: 5 additions & 1 deletion src/components/planner/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface CourseSelectorContainerProps {
transferCredits: string[];
getSearchedDragId: GetDragIdByCourse;
getRequirementDragId: GetDragIdByCourse;
courseDragged: boolean;
}

function CourseSelectorContainer({
Expand All @@ -33,6 +34,7 @@ function CourseSelectorContainer({
transferCredits,
getSearchedDragId,
getRequirementDragId,
courseDragged,
}: CourseSelectorContainerProps) {
const {
data: validationData,
Expand Down Expand Up @@ -119,7 +121,9 @@ function CourseSelectorContainer({
{open ? (
<div
id="tutorial-editor-1"
className="z-0 h-screen w-[30%] min-w-[30%] overflow-x-hidden overflow-y-scroll"
className={`z-0 h-screen w-[30%] min-w-[30%] overflow-x-hidden ${
courseDragged ? 'overflow-y-hidden' : 'overflow-y-scroll'
}`}
>
<div className="flex h-fit min-h-screen w-full flex-col gap-y-4 bg-white p-4">
<div className="flex flex-col">
Expand Down
Loading