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

Add a dock clear button #648

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion frontend/degree-plan/components/Dock/Dock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AccountIndicator from "pcx-shared-components/src/accounts/AccountIndicato
import _ from 'lodash';
import CoursePlanned from '../FourYearPlan/CourseInPlan';
import CourseInDock from './CourseInDock';
import { CourseXButton } from "../Course/Course";

const DockWrapper = styled.div`
z-index: 1;
Expand Down Expand Up @@ -79,6 +80,17 @@ const DockedCourses = styled.div`
overflow: auto;
`

const CloseIcon = styled.div`
cursor: pointer;
opacity: 0.5;
display: flex;
align-items: center;
justify-content: flex-end;
&:hover {
opacity: 1;
}
`;

const CenteringCourseDock = styled.div`
color: var(--primary-color-extra-dark);
margin-left: auto;
Expand Down Expand Up @@ -108,7 +120,7 @@ interface DockProps {
const Dock = ({ user, login, logout, activeDegreeplanId }: DockProps) => {
// const [courseAdded, setCourseAdded] = React.useState(false);
const { searchPanelOpen, setSearchPanelOpen, setSearchRuleQuery, setSearchRuleId } = useContext(SearchPanelContext)
const { createOrUpdate } = useSWRCrud<DockedCourse>(`/api/degree/docked`, { idKey: 'full_code' });
const { createOrUpdate, remove } = useSWRCrud<DockedCourse>(`/api/degree/docked`, { idKey: 'full_code' });
const { data: dockedCourses = [], isLoading } = useSWR<DockedCourse[]>(user ? `/api/degree/docked` : null);

// Returns a boolean that indiates whether this is the first render
Expand Down Expand Up @@ -143,6 +155,10 @@ const Dock = ({ user, login, logout, activeDegreeplanId }: DockProps) => {
// }
// }, [isMount, dockedCourses]);

const handleRemoveCourse = (full_code: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convention: fullCode

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-04-09 at 3 59 35 PM 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we've been using full_code. That might not be a good pattern (mb if so), but tbh I think this OK for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will defer to @esinx here, but if we want to clean this up, we should probably do so at the entire project level and likely after we solve the user facing issues

remove(full_code);
}

return (
<DockWrapper ref={drop} >
<DockContainer $isDroppable={canDrop} $isOver={isOver}>
Expand Down Expand Up @@ -189,6 +205,12 @@ const Dock = ({ user, login, logout, activeDegreeplanId }: DockProps) => {
{dockedCourses.map((course) =>
<AnimatedDockedCourseItem course={course} isDisabled={false} />
)}
<CloseIcon>
<CourseXButton onClick={(e) => {
dockedCourses.forEach((course) => handleRemoveCourse(course.full_code));
e.stopPropagation();
}} hidden={false}/>
</CloseIcon>
</DockedCourses>}
</DockedCoursesWrapper>
<Logo src='pdp-logo.svg' width='30' height='45'/>
Expand Down