Skip to content

Commit

Permalink
hashes, type safety, alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-rt committed Apr 12, 2024
1 parent b6f2c1c commit 67a8de4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 50 deletions.
2 changes: 0 additions & 2 deletions frontend/plan/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,6 @@ export const deleteAlertItem = (sectionId, alertId) => (dispatch) => {
dispatch(deleteAlertFrontend(sectionId));
}
});
// // .catch((error) => console.log(error));
};

export const fetchAlerts = () => (dispatch) => {
Expand Down Expand Up @@ -929,7 +928,6 @@ export const updateContactInfo = (contactInfo) => (dispatch) => {
if (!res.ok) {
throw new Error(JSON.stringify(res));
} else {
// update on front end
dispatch(updateContactInfoFrontend(profile));
}
});
Expand Down
8 changes: 2 additions & 6 deletions frontend/plan/components/CartSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const CourseDetailsContainer = styled.div`
flex-grow: 0;
display: flex;
flex-direction: column;
max-width: 70%;
text-align: left;
align-items: left;
`;
Expand Down Expand Up @@ -133,14 +132,11 @@ const CourseCartItem = styled.div<{ lastAdded: boolean; isMobile: boolean }>`
cursor: pointer;
user-select: none;
display: ${(props) => (props.isMobile ? "grid" : "flex")};
display: grid;
flex-direction: row;
justify-content: space-around;
padding: 0.8rem;
border-bottom: 1px solid #e5e8eb;
grid-template-columns: ${(props) =>
props.isMobile ? "20% 50% 15% 15%" : ""};
grid-template-columns: 20% 50% 15% 15%;
* {
user-select: none;
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/plan/components/alert/AlertButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface AlertButtonProps {
inAlerts: boolean;
}

const Bell = styled.button`
const Button = styled.button`
color: gray;
padding: 0;
border: none;
Expand All @@ -21,7 +21,7 @@ const Bell = styled.button`

const AlertButton: React.FC<AlertButtonProps> = ({ alerts, inAlerts }) => {
return(
<Bell
<Button
role="button"
onClick={(event) => {
event.stopPropagation();
Expand All @@ -36,7 +36,7 @@ const AlertButton: React.FC<AlertButtonProps> = ({ alerts, inAlerts }) => {
style={{ fontSize: "1rem" }}
className={inAlerts ? "fas fa-bell": "far fa-bell"}
/>
</Bell>
</Button>
)
}

Expand Down
14 changes: 2 additions & 12 deletions frontend/plan/components/alert/AlertSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const CourseDetailsContainer = styled.div`
flex-grow: 0;
display: flex;
flex-direction: column;
max-width: 70%;
text-align: left;
align-items: left;
`;
Expand Down Expand Up @@ -108,14 +107,10 @@ const AlertItem = styled.div<{ isMobile: boolean }>`
transition: 250ms ease background;
user-select: none;
display: ${(props) => (props.isMobile ? "grid" : "flex")};
flex-direction: row;
justify-content: space-around;
display: grid;
padding: 0.8rem;
border-bottom: 1px solid #e5e8eb;
grid-template-columns: ${(props) =>
props.isMobile ? "20% 50% 15% 15%" : ""};
grid-template-columns: 20% 50% 15% 15%;
* {
user-select: none;
}
Expand All @@ -142,15 +137,10 @@ const AlertSection: React.FC<AlertSectionProps> = ({
aria-checked="false"
isMobile={isMobile}
>
<div style={{
alignItems: "center",
display: "flex",
}}>
<AlertButton
alerts={alerts}
inAlerts={inAlerts}
/>
</div>
<CourseDetails alert={alert} />
<CourseInfoButton courseInfo={courseInfo} />
<CourseTrashCan remove={(event) => {
Expand Down
52 changes: 25 additions & 27 deletions frontend/plan/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useRef, useEffect } from "react";
import Head from "next/head";
import { Provider } from "react-redux";
import { applyMiddleware, createStore } from "redux";
import { applyMiddleware, compose, createStore } from "redux";
import thunkMiddleware from "redux-thunk";
import SwipeableViews from "react-swipeable-views";
import Tabs from "@material-ui/core/Tabs";
Expand Down Expand Up @@ -95,7 +95,7 @@ const Toast = styled(ToastContainer)`
}
`;

const CartTab = styled.h3<{ active: boolean }>`
const CartTab = styled.a<{ active: boolean }>`
display: inline-flex;
font-weight: bold;
margin-bottom: 0.5rem;
Expand Down Expand Up @@ -123,6 +123,15 @@ export function showToast(text: string, error: boolean) {
}
}

enum TabItem {
Cart = "cart-tab",
Alerts = "alerts-tab"
}

const tabItems = [
{ item: TabItem.Cart, name: "Cart", component: Cart},
{ item: TabItem.Alerts, name: "Alerts", component: Alerts},]

function Index() {
const router = useRouter();

Expand All @@ -146,12 +155,11 @@ function Index() {
const scrollTop = () => window.scrollTo(0, 0);
const isExpanded = view === 1;

// cart vs alerts
const [showAlerts, setShowAlerts] = useState(false);
const [selectedTab, setSelectedTab] = useState<TabItem>(TabItem.Cart);
useEffect(() => {
const hash = router.asPath.split("#")[1];
setShowAlerts(hash === "alerts");
}, [setShowAlerts]);
setSelectedTab(router.asPath.split("#")[1] === TabItem.Alerts ? TabItem.Alerts : TabItem.Cart);
}, []);


const [showLoginModal, setShowLoginModal] = useState(true);

Expand Down Expand Up @@ -203,6 +211,8 @@ function Index() {
}
}, [store]);

const TabContent = tabItems.find(({item}) => item === selectedTab)?.component

const headPreamble = (
<Head>
<meta charSet="utf-8" />
Expand Down Expand Up @@ -420,29 +430,17 @@ function Index() {
}}
>
<div>
{tabItems.map(({item, name}) => (
<CartTab
active={!showAlerts}
onClick={() => {
setShowAlerts(false);
router.replace("/#cart", undefined, { shallow: true })
}}
key={item}
href={`/#${item}`}
active={selectedTab === item}
onClick={() => setSelectedTab(item)}
>
Cart
</CartTab>
<CartTab
active={showAlerts}
onClick={() => {
setShowAlerts(true);
router.replace("/#alerts", undefined, { shallow: true })
}}
>
Alerts
</CartTab>
{name}
</CartTab>))}
</div>
{showAlerts ?
<Alerts mobileView={false} /> :
<Cart mobileView={false} />
}
{typeof TabContent !== "undefined" && <TabContent mobileView={false} />}
</div>
<div
style={{
Expand Down

0 comments on commit 67a8de4

Please sign in to comment.