Skip to content

Commit

Permalink
feat(Commons): add support options to navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaturner committed Sep 23, 2024
1 parent a5a97b4 commit 1d0f881
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CommonsList from "./CommonsList";
import SwitchAppWithUser from "../../navigation/SwitchAppWithUser";
import DonateLink from "./DonateLink";
import Launchpad from "../../navigation/Launchpad";
import SupportDropdown from "./SupportDropdown";

interface CommonsNavbarDesktopProps extends MenuProps {
org: Organization;
Expand All @@ -32,19 +33,24 @@ const CommonsNavbarDesktop: React.FC<CommonsNavbarDesktopProps> = ({
<Image src={org.mediumLogo} className="nav-logo" alt="" />
<span className="sr-only">{commonsTitle} Catalog Home</span>
</Menu.Item>
</div>
<Menu.Menu position="right">
<AboutOrgLink org={org} />
{org.orgID === "libretexts" && (
<>
<DonateLink />
<AccountRequestLink />
<CommonsList />
</>
)}
<SwitchAppWithUser user={user} parent="commons" />
</Menu.Menu>
</div>
<Menu.Menu position="right">
<AboutOrgLink org={org} />
{org.orgID === "libretexts" && (
<>
<DonateLink />
<AccountRequestLink />
</>
)}
<SupportDropdown />
{
org.orgID === 'libretexts' && (
<CommonsList />
)
}
<SwitchAppWithUser user={user} parent="commons" />
</Menu.Menu>
</div>
</Menu>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useState } from "react";
import SwitchAppWithUser from "../../navigation/SwitchAppWithUser";
import DonateLink from "./DonateLink";
import Launchpad from "../../navigation/Launchpad";
import SupportDropdown from "./SupportDropdown";

interface CommonsNavbarMobileProps {
org: Organization;
Expand All @@ -21,6 +22,22 @@ const CommonsNavbarMobile: React.FC<CommonsNavbarMobileProps> = ({
}) => {
const [menuOpen, setMenuOpen] = useState(false);
const [commonsOpen, setCommonsOpen] = useState(false);
const [supportOpen, setSupportOpen] = useState(false);

const SupportMenuItem = () => (
<>
<Menu.Item onClick={() => setSupportOpen(!supportOpen)}>
Support
<Icon
name={supportOpen ? "angle up" : "angle down"}
className="float-right"
/>
</Menu.Item>
{
supportOpen && <SupportDropdown isMobile={true} />
}
</>
);

return (
<Menu className="flex w-full pt-2 flex-col" secondary>
Expand Down Expand Up @@ -50,6 +67,7 @@ const CommonsNavbarMobile: React.FC<CommonsNavbarMobileProps> = ({
<>
<DonateLink isMobile={true} />
<AccountRequestLink isMobile={true} />
<SupportMenuItem />
<Menu.Item onClick={() => setCommonsOpen(!commonsOpen)}>
Campus Commons
<Icon
Expand All @@ -62,6 +80,10 @@ const CommonsNavbarMobile: React.FC<CommonsNavbarMobileProps> = ({
{org.orgID === "libretexts" && commonsOpen && (
<CommonsList isMobile={true} />
)}
{
org.orgID !== "libretexts" &&
<SupportMenuItem />
}
<SwitchAppWithUser user={user} parent="commons" isMobile />
</Menu>
</div>
Expand Down
100 changes: 100 additions & 0 deletions client/src/components/commons/CommonsNavbar/SupportDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { Dropdown, Icon, Menu, } from "semantic-ui-react";
import { useState } from "react";


interface SupportDropdownProps {
isMobile?: boolean;
}

const SupportDropdown: React.FC<SupportDropdownProps> = ({ isMobile = false }) => {
const [mouseIndex, setMouseIndex] = useState(0);

const itemsArr = [
{
name: "Knowledge Base",
props: {
key: "libretexts",
as: "a",
href: "https://commons.libretexts.org/insight",
target: "_blank",
rel: "noopener noreferrer",
},
},
{
name: 'System Status',
props: {
key: "status",
as: "a",
href: "https://status.libretexts.org",
target: "_blank",
rel: "noopener noreferrer",
},
},
{
name: "Contact Support",
props: {
key: "contact",
as: "a",
href: "https://commons.libretexts.org/support/contact",
target: "_blank",
rel: "noopener noreferrer",
},
},
]

if (isMobile) {
return (
<Menu.Menu className="commons-mobilenav-commonslist">
{itemsArr.map((item) => (
<Menu.Item {...item.props}>
{/* <Icon name="university" /> */}
{item.name}
</Menu.Item>
))}
</Menu.Menu>
);
}

const handleKeyPress = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'ArrowDown') {
setMouseIndex((prevIndex) => Math.min(prevIndex + 1, itemsArr.length - 1));
const element = document.getElementById("active");
if (element) {
element?.scrollIntoView({
behavior: "auto",
block: "start"
});
}
} else if (e.key === 'ArrowUp') {
setMouseIndex((prevIndex) => Math.max(prevIndex - 1, 0));
const element = document.getElementById("active");
if (element) {
element?.scrollIntoView({
behavior: "auto",
block: "start"
});
}
} else if (e.key == "Enter") {
window.location.href = itemsArr[mouseIndex].props.href;
}
};



return (
<div onKeyDown={handleKeyPress} className="flex flex-row items-center" >
<Dropdown item text="Support">
<Dropdown.Menu direction="left" className="commons-desktopnav-commonslist" >
{itemsArr.map((item, index) => (
<Dropdown.Item {...item.props} selected={index == mouseIndex} id={index == mouseIndex ? "active" : "inactive"} >
{/* <Icon name="university" /> */}
{item.name}
</Dropdown.Item>
))}
</Dropdown.Menu>
</Dropdown>
</div>
);
};

export default SupportDropdown;

0 comments on commit 1d0f881

Please sign in to comment.