-
Notifications
You must be signed in to change notification settings - Fork 15
finished adding bookmarks bar #1083
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
Open
marla-tumenjargal
wants to merge
2
commits into
main
Choose a base branch
from
gradtrak-bookmarks-sidebar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
apps/frontend/src/app/GradTrak/Dashboard/BookmarksSidebar/BookmarksSidebar.module.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| .root { | ||
| --bookmarks-padding-x: 0.9rem; | ||
| position: relative; | ||
| display: flex; | ||
| flex-direction: column; | ||
| background: var(--background-color); | ||
| color: var(--heading-color); | ||
| width: 384px; /* 20% wider than 320px */ | ||
| min-width: 384px; | ||
| overflow: hidden; | ||
| border-left: 1px solid var(--border-color); | ||
| } | ||
|
|
||
| .header { | ||
| display: flex; | ||
| flex-direction: column; | ||
| flex-shrink: 0; | ||
| gap: 2rem; | ||
| padding: 1.2rem var(--bookmarks-padding-x); | ||
| border-bottom: 1px solid var(--border-color); | ||
| } | ||
|
|
||
| .topRow { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .closeSidebarButton { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| background: none; | ||
| border: none; | ||
| cursor: pointer; | ||
| padding: 0.25rem; | ||
| color: var(--heading-color); | ||
| border-radius: 6px; | ||
| transition: background-color 0.2s ease; | ||
|
|
||
| &:hover { | ||
| background-color: var(--button-hover-color); | ||
| } | ||
| } | ||
|
|
||
| .bookmarksButton { | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .closeSidebarIcon { | ||
| width: 1.25rem; | ||
| height: 1.25rem; | ||
| } | ||
|
|
||
| .headerRow { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.6rem; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .headerLeft { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.45rem; | ||
| flex: 1; | ||
| min-width: 0; | ||
| } | ||
|
|
||
| .headerTitle { | ||
| font-size: var(--text-18); | ||
| font-weight: var(--font-semibold); | ||
| margin: 0; | ||
| padding-left: 0; | ||
| white-space: nowrap; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
|
|
||
| &.headerTitleRight { | ||
| flex: 1; | ||
| text-align: right; | ||
| } | ||
| } | ||
|
|
||
| .backButton { | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .closeButton { | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .content { | ||
| flex: 1; | ||
| overflow-y: auto; | ||
| overflow-x: hidden; | ||
| padding: 1.2rem var(--bookmarks-padding-x); | ||
| background-color: var(--semesterblock-color); | ||
| scrollbar-width: thin; | ||
| scrollbar-color: var(--paragraph-color) var(--border-color); | ||
| } | ||
|
|
||
| .collectionCards { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 1.2rem; | ||
| padding: 0.3rem 0; | ||
| } | ||
|
|
||
| .loading, | ||
| .empty { | ||
| font-size: 1.05rem; | ||
| color: var(--paragraph-color); | ||
| padding: 0.6rem 0; | ||
| } | ||
|
|
||
| /* Collection detail view (classes as catalog-style cards) */ | ||
| .classList { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 12px; | ||
| padding: 0.3rem 0; | ||
| } | ||
|
|
||
| .draggableClassWrapper { | ||
| cursor: grab; | ||
|
|
||
| &:active { | ||
| cursor: grabbing; | ||
| } | ||
| } | ||
|
|
||
| .classEmpty { | ||
| font-size: 1.05rem; | ||
| color: var(--paragraph-color); | ||
| padding: 1.2rem 0; | ||
| text-align: center; | ||
| } |
224 changes: 224 additions & 0 deletions
224
apps/frontend/src/app/GradTrak/Dashboard/BookmarksSidebar/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| import { useMemo, useState } from "react"; | ||
|
|
||
| import { Bookmark, NavArrowRight } from "iconoir-react"; | ||
|
|
||
| import { Button, Color } from "@repo/theme"; | ||
|
|
||
| import { CollectionCard } from "@/app/Profile/Bookmarks/CollectionCard"; | ||
| import ClassCard from "@/components/ClassCard"; | ||
| import { useGetAllCollectionsWithPreview } from "@/hooks/api/collections"; | ||
| import { Collection, CollectionPreviewClass } from "@/types/collection"; | ||
|
|
||
| import styles from "./BookmarksSidebar.module.scss"; | ||
|
|
||
| interface BookmarksSidebarProps { | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| const GRADTRAK_BOOKMARK_DRAG_TYPE = "application/x-gradtrak-bookmark-class"; | ||
|
|
||
| export default function BookmarksSidebar({ onClose }: BookmarksSidebarProps) { | ||
| const [selectedCollectionId, setSelectedCollectionId] = useState< | ||
| string | null | ||
| >(null); | ||
|
|
||
| const { data: apiCollections, loading } = useGetAllCollectionsWithPreview(); | ||
|
|
||
| const collections = useMemo<Collection[]>(() => { | ||
| if (!apiCollections) return []; | ||
| return apiCollections | ||
| .map((c) => { | ||
| const previewClasses: CollectionPreviewClass[] = []; | ||
| for (const entry of c.classes ?? []) { | ||
| if (previewClasses.length >= 2) break; | ||
| if (!entry.class) continue; | ||
| const cls = entry.class; | ||
| previewClasses.push({ | ||
| subject: cls.subject, | ||
| courseNumber: cls.courseNumber, | ||
| number: cls.number, | ||
| title: cls.title ?? cls.course?.title ?? null, | ||
| gradeAverage: | ||
| cls.gradeDistribution?.average ?? | ||
| cls.course?.gradeDistribution?.average ?? | ||
| null, | ||
| enrolledCount: | ||
| cls.primarySection?.enrollment?.latest?.enrolledCount ?? null, | ||
| maxEnroll: | ||
| cls.primarySection?.enrollment?.latest?.maxEnroll ?? null, | ||
| unitsMin: cls.unitsMin ?? 0, | ||
| unitsMax: cls.unitsMax ?? 0, | ||
| hasReservedSeats: | ||
| (cls.primarySection?.enrollment?.latest | ||
| ?.activeReservedMaxCount ?? 0) > 0, | ||
| }); | ||
| } | ||
| return { | ||
| id: c._id, | ||
| name: c.name, | ||
| classCount: c.classes?.length ?? 0, | ||
| isPinned: !!c.pinnedAt, | ||
| pinnedAt: c.pinnedAt ? new Date(c.pinnedAt).getTime() : null, | ||
| isSystem: c.isSystem ?? false, | ||
| color: (c.color ?? null) as Color | null, | ||
| lastAdd: new Date(c.lastAdd).getTime(), | ||
| previewClasses, | ||
| }; | ||
| }) | ||
| .sort((a, b) => { | ||
| if (a.isSystem && !b.isSystem) return -1; | ||
| if (!a.isSystem && b.isSystem) return 1; | ||
| if (a.isPinned && !b.isPinned) return -1; | ||
| if (!a.isPinned && b.isPinned) return 1; | ||
| if (a.isPinned && b.isPinned && a.pinnedAt != null && b.pinnedAt != null) { | ||
| return b.pinnedAt - a.pinnedAt; | ||
| } | ||
| return b.lastAdd - a.lastAdd; | ||
| }); | ||
| }, [apiCollections]); | ||
|
|
||
| const selectedCollection = useMemo( | ||
| () => collections.find((c) => c.id === selectedCollectionId) ?? null, | ||
| [collections, selectedCollectionId] | ||
| ); | ||
|
|
||
| const selectedCollectionApi = useMemo( | ||
| () => | ||
| apiCollections?.find((c) => c._id === selectedCollectionId) ?? null, | ||
| [apiCollections, selectedCollectionId] | ||
| ); | ||
|
|
||
| const handleBack = () => { | ||
| setSelectedCollectionId(null); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={styles.root}> | ||
| <div className={styles.header}> | ||
| <div className={styles.topRow}> | ||
| <button | ||
| type="button" | ||
| className={styles.closeSidebarButton} | ||
| onClick={onClose} | ||
| aria-label="Close sidebar" | ||
| > | ||
| <NavArrowRight className={styles.closeSidebarIcon} /> | ||
| </button> | ||
| <Button | ||
| variant="secondary" | ||
| onClick={onClose} | ||
| className={styles.bookmarksButton} | ||
| > | ||
| <Bookmark /> | ||
| Bookmarks | ||
| </Button> | ||
| </div> | ||
| <div className={styles.headerRow}> | ||
| <div className={styles.headerLeft}> | ||
| {selectedCollection ? ( | ||
| <> | ||
| <Button | ||
| variant="secondary" | ||
| onClick={handleBack} | ||
| className={styles.backButton} | ||
| > | ||
| Back | ||
| </Button> | ||
| <h2 | ||
| className={`${styles.headerTitle} ${styles.headerTitleRight}`} | ||
| > | ||
| {selectedCollection.name} | ||
| </h2> | ||
| </> | ||
| ) : ( | ||
| <h2 className={styles.headerTitle}>Bookmarks</h2> | ||
| )} | ||
| </div> | ||
| {!selectedCollection && ( | ||
| <Button | ||
| variant="secondary" | ||
| onClick={onClose} | ||
| className={styles.closeButton} | ||
| > | ||
| Close | ||
| </Button> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className={styles.content}> | ||
| {selectedCollection && selectedCollectionApi ? ( | ||
| <> | ||
| {selectedCollectionApi.classes?.length === 0 ? ( | ||
| <div className={styles.classEmpty}> | ||
| No classes in this collection | ||
| </div> | ||
| ) : ( | ||
| <div className={styles.classList}> | ||
| {selectedCollectionApi.classes?.map((entry) => { | ||
| const c = entry?.class; | ||
| if (!c) return null; | ||
| return ( | ||
| <div | ||
| key={`${c.subject}-${c.courseNumber}-${c.number}`} | ||
| className={styles.draggableClassWrapper} | ||
| draggable | ||
| onDragStart={(e) => { | ||
| e.dataTransfer.setData( | ||
| GRADTRAK_BOOKMARK_DRAG_TYPE, | ||
| JSON.stringify({ | ||
| source: "bookmarks", | ||
| class: { | ||
| subject: c.subject, | ||
| courseNumber: c.courseNumber, | ||
| number: c.number, | ||
| title: c.title ?? c.course?.title ?? "", | ||
| unitsMin: c.unitsMin ?? 0, | ||
| unitsMax: c.unitsMax ?? 0, | ||
| }, | ||
| }) | ||
| ); | ||
| e.dataTransfer.effectAllowed = "copy"; | ||
| }} | ||
| > | ||
| <ClassCard | ||
| class={c} | ||
| style={{ cursor: "grab" }} | ||
| /> | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| )} | ||
| </> | ||
| ) : ( | ||
| <> | ||
| {loading ? ( | ||
| <div className={styles.loading}>Loading...</div> | ||
| ) : collections.length === 0 ? ( | ||
| <div className={styles.empty}>No collections yet.</div> | ||
| ) : ( | ||
| <div className={styles.collectionCards}> | ||
| {collections.map((collection) => ( | ||
| <CollectionCard | ||
| key={collection.id} | ||
| name={collection.name} | ||
| classCount={collection.classCount} | ||
| isPinned={collection.isPinned} | ||
| isSystem={collection.isSystem} | ||
| color={collection.color} | ||
| previewClasses={collection.previewClasses} | ||
| onClick={() => setSelectedCollectionId(collection.id)} | ||
| width={346} | ||
| height={204} | ||
| showPin={!collection.isSystem} | ||
| /> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've rotated the keys, but these changes are not correct. I cannot merge until you remove this.