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

Subscription page desktop #322

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
83 changes: 53 additions & 30 deletions components/SubscriptionsPage/ClassCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LastUpdated } from '../common/LastUpdated';
import { DesktopSectionPanel } from '../ResultsPage/Results/SectionPanel';
import { getFormattedSections } from '../ResultsPage/ResultsLoader';
import DropdownArrow from '../icons/DropdownArrow.svg';
import IconCollapseExpand from '../icons/IconCollapseExpand';
import CourseCheckBox from '../panels/CourseCheckBox';
import { CRNBadge } from './CRNBadge';
import axios from 'axios';
Expand All @@ -24,8 +25,10 @@ export const ClassCardWrapper = ({
}: ClassCardWrapperType): ReactElement => {
return (
<div className="SearchResult">
<div>{headerLeft}</div>
{headerRight}
<div className="SearchResult__header">
<div className="SearchResult__header--left">{headerLeft}</div>
{headerRight}
</div>

{body}
{afterBody}
Expand Down Expand Up @@ -72,24 +75,45 @@ export function ClassCard({
return (
<ClassCardWrapper
headerLeft={
// ask Nick what this is and if this makes me not have to div --left
<>
<span className="SearchResult__header--classTitle">
{course.subject} {course.classId}: {course.name}
</span>
<LastUpdated
{/* <LastUpdated
lastUpdateTime={course.lastUpdateTime}
className="SearchResult__header--sub"
/>
{course.sections.map((section) => (
<CRNBadge
key={section.crn}
userInfo={userInfo}
crn={section.crn}
></CRNBadge>
))}
/> */}
<div className="SearchResult__header--sub">
{course.sections.map((section) => (
<CRNBadge
key={section.crn}
userInfo={userInfo}
crn={section.crn}
></CRNBadge>
))}
</div>
</>
}
headerRight={<button onClick={unsubscribeAll}>Unsubscribe</button>}
headerRight={
<div
className="SearchResult__showAll"
onClick={() => setAreSectionsHidden(!areSectionsHidden)}
style={{
cursor: 'pointer',
display: 'inline-flex',
alignItems: 'center',
}}
>
<IconCollapseExpand
className={
areSectionsHidden
? 'SearchResult__showAll--subscriptionCollapsed'
: 'SearchResult__showAll--subscriptionExpanded'
}
/>
</div>
}
body={
<>
<div style={{ display: areSectionsHidden ? 'none' : 'block' }}>
Expand Down Expand Up @@ -143,27 +167,26 @@ export function ClassCard({
</>
}
afterBody={
<>
<div
className={
areSectionsHidden
? 'SearchResult__showAll--subscriptionButton'
: 'SearchResult__showAll'
}
role="button"
tabIndex={0}
onClick={() => setAreSectionsHidden(!areSectionsHidden)}
>
<span>{areSectionsHidden ? 'Show sections' : 'Hide sections'}</span>
<DropdownArrow
!areSectionsHidden && (
<>
<div
className={
areSectionsHidden
? 'SearchResult__showAll--subscriptionCollapsed'
: 'SearchResult__showAll--subscriptionExpanded'
? 'SearchResult__showAll--subscriptionButton'
: 'SearchResult__showAll'
}
/>
</div>
</>
role="button"
tabIndex={0}
>
<button
className={'SearchResult__showAll--unsubscribeButton'}
onClick={unsubscribeAll}
>
Unsubscribe All
</button>
</div>
</>
)
}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@
},
"engines": {
"node": ">=18"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
74 changes: 53 additions & 21 deletions pages/subscriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { SubscriptionCourse } from '../components/types';
import { gqlClient } from '../utils/courseAPIClient';
import useUserInfo from '../utils/useUserInfo';
import { EmptyCard } from '../components/SubscriptionsPage/EmptyCard';
import getTermInfosWithError from '../utils/TermInfoProvider';
import { getTermName, getLatestTerm } from '../components/terms';
import { Campus } from '../components/types';
import Keys from '../components/Keys';
import axios from 'axios';

async function fetchCourseNotifs(classMapping, courseIds) {
for (const courseId of courseIds) {
Expand Down Expand Up @@ -116,6 +121,10 @@ export default function SubscriptionsPage(): ReactElement {
// is the user subscribed to at least one class
const [isSubscribed, setIsSubscribed] = useState(false);

const termInfos = getTermInfosWithError().termInfos;
const termId = getLatestTerm(termInfos, Campus.NEU);
const termName = getTermName(termInfos, termId).replace('Semester', '');

useEffect(() => {
if (isUserInfoLoading) {
return;
Expand Down Expand Up @@ -145,6 +154,22 @@ export default function SubscriptionsPage(): ReactElement {
fetchSubscriptions();
}, [userInfo?.phoneNumber, isUserInfoLoading]);

const unsubscribeAll = () => {
const allSections = Array.from(classes.values()).flatMap(
(course) => course.sections
);

axios
.delete(`${process.env.NEXT_PUBLIC_NOTIFS_ENDPOINT}/user/subscriptions`, {
data: {
token: userInfo.token,
sectionIds: allSections.map((s) => Keys.getSectionHash(s)),
// courseIds: [Keys.getClassHash(course)],
},
})
.then(() => fetchUserInfo());
};

if (isFetching) {
return (
<>
Expand All @@ -171,7 +196,6 @@ export default function SubscriptionsPage(): ReactElement {
<div>
<Header
title={`Subscriptions`}
// TODO (sam 11-04-2024: maybe we can get the previous campus/termid if we wnt to preserve this behavior)
campus={null}
termId={null}
searchData={null}
Expand All @@ -180,30 +204,38 @@ export default function SubscriptionsPage(): ReactElement {
onSignOut={onSignOut}
/>
</div>

{isSubscribed ? (
<>
<div className="Results_Container">
<div className="Results_MainWrapper">
<div className="Results_Main">
<h2>Subscriptions</h2>
{Array.from(classes)
.sort((a, b) => (a > b ? 1 : -1)) // Sort to ensure the sub order doesn't change
.map(([courseCode, course]) => {
return (
<ClassCard
key={courseCode}
course={course}
sections={course.sections}
userInfo={userInfo}
fetchUserInfo={fetchUserInfo}
onSignIn={onSignIn}
/>
);
})}
<div className="Results_Container">
<div className="Results_MainWrapper">
<div className="Results_Main">
<div className="Subscriptions_Header_Container">
<h2 className="Subscriptions_Title">
{termName} Notifications
</h2>
<button
className="Unsubscribe_All_Button"
onClick={unsubscribeAll}
>
<img src="/unsubscribe.svg" className="Unsubscribe_Icon" />
Unsubscribe All
</button>
</div>
{Array.from(classes)
.sort((a, b) => (a > b ? 1 : -1))
.map(([courseCode, course]) => (
<ClassCard
key={courseCode}
course={course}
sections={course.sections}
userInfo={userInfo}
fetchUserInfo={fetchUserInfo}
onSignIn={onSignIn}
/>
))}
</div>
</div>
</>
</div>
) : (
<EmptyCard />
)}
Expand Down
7 changes: 7 additions & 0 deletions public/unsubscribe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions styles/pages/_Results.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,47 @@ $SIDEBAR_WIDTH: 268px;
padding-left: 10px;
}

.Subscriptions_Header_Container {
display: flex;
justify-content: space-between;
align-items: end;
flex-direction: row;

.Subscriptions_Title {
font-family: Lato;
font-size: 24px;
font-style: normal;
font-weight: 700;
line-height: 28.8px;
}

.Unsubscribe_All_Button {
display: flex;
gap: 8px;
align-items: center;

padding: 9px 18px;

cursor: pointer;

border: 0.5px solid #1d3557;
background-color: white;
border-radius: 8px;

color: #212121;
font-family: Lato;
font-size: 14px;
font-style: normal;
font-weight: 700;
line-height: 16px;

.Unsuscribe_Icon {
width: 8px;
height: 8px;
}
}
}

.Results_Main__EmptyCard {
display: flex;
flex-direction: column;
Expand Down
19 changes: 17 additions & 2 deletions styles/results/_SearchResult.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
font-size: 18px;
line-height: 2px;
border-radius: 5px 5px 0 0;
color: Colors.$NEU9;
}

&--employeeName {
Expand Down Expand Up @@ -175,6 +176,7 @@
&__sectionTable > thead > tr > th {
text-align: left;
padding-left: 16px;
padding-top: 20px;
}

&__sectionTable > thead > tr > th:nth-child(6) {
Expand Down Expand Up @@ -236,15 +238,28 @@
}

&--subscriptionExpanded {
transform: rotate(-180deg);
transform: rotate(-90deg);
margin-top: 2px;
}

&--subscriptionCollapsed {
transform: rotate(0deg);
transform: rotate(90deg);
margin-top: 3px;
}

&--unsubscribeButton {
margin-left: auto;
width: fit-content;
display: flex;
width: auto;
padding: 8px 16px;
align-items: center;
border-radius: 8px;
border: 1px solid #d1d3d7;
font-weight: 700;
background: #fff;
}

& > span {
margin-right: 8px;
}
Expand Down
Loading