Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
AddToLearningPathDialog,
AddToUserListDialog,
} from "../Dialogs/AddToListDialog"
import * as urls from "@/common/urls"
import { SignupPopover } from "../SignupPopover/SignupPopover"

const RESOURCE_DRAWER_PARAMS = [RESOURCE_DRAWER_QUERY_PARAM] as const

Expand Down Expand Up @@ -65,8 +65,8 @@ const unsafe_html2plaintext = (text: string) => {
const DrawerContent: React.FC<{
resourceId: number
}> = ({ resourceId }) => {
const loc = useLocation()
const resource = useLearningResourcesDetail(Number(resourceId))
const [signupEl, setSignupEl] = React.useState<HTMLElement | null>(null)
const { data: user } = useUserMe()
const handleAddToLearningPathClick: LearningResourceCardProps["onAddToLearningPathClick"] =
useMemo(() => {
Expand All @@ -79,12 +79,13 @@ const DrawerContent: React.FC<{
}, [user])
const handleAddToUserListClick: LearningResourceCardProps["onAddToUserListClick"] =
useMemo(() => {
if (user?.is_authenticated) {
return (event, resourceId: number) => {
NiceModal.show(AddToUserListDialog, { resourceId })
return (event, resourceId: number) => {
if (!user?.is_authenticated) {
setSignupEl(event.currentTarget)
return
}
NiceModal.show(AddToUserListDialog, { resourceId })
}
return null
}, [user])
useCapturePageView(Number(resourceId))

Expand All @@ -103,11 +104,8 @@ const DrawerContent: React.FC<{
user={user}
onAddToLearningPathClick={handleAddToLearningPathClick}
onAddToUserListClick={handleAddToUserListClick}
signupUrl={urls.login({
pathname: loc.pathname,
search: loc.search,
})}
/>
<SignupPopover anchorEl={signupEl} onClose={() => setSignupEl(null)} />
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
LearningResourceCard,
LearningResourceListCard,
LearningResourceListCardCondensed,
SignupPopover,
} from "ol-components"
import * as NiceModal from "@ebay/nice-modal-react"
import type { LearningResourceCardProps } from "ol-components"
Expand All @@ -14,8 +13,7 @@ import {
import { useResourceDrawerHref } from "../LearningResourceDrawer/LearningResourceDrawer"
import { useUserMe } from "api/hooks/user"
import { LearningResource } from "api"
import * as urls from "@/common/urls"
import { useLocation } from "react-router"
import { SignupPopover } from "../SignupPopover/SignupPopover"

const useResourceCard = (resource?: LearningResource | null) => {
const getDrawerHref = useResourceDrawerHref()
Expand Down Expand Up @@ -87,7 +85,6 @@ const ResourceCard: React.FC<ResourceCardProps> = ({
list,
...others
}) => {
const loc = useLocation()
const {
getDrawerHref,
anchorEl,
Expand All @@ -114,14 +111,7 @@ const ResourceCard: React.FC<ResourceCardProps> = ({
inLearningPath={inLearningPath}
{...others}
/>
<SignupPopover
signupUrl={urls.login({
pathname: loc.pathname,
search: loc.search,
})}
anchorEl={anchorEl}
onClose={handleClosePopover}
/>
<SignupPopover anchorEl={anchorEl} onClose={handleClosePopover} />
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import {
useSearchSubscriptionDelete,
useSearchSubscriptionList,
} from "api/hooks/searchSubscription"
import { Button, SignupPopover, SimpleMenu, styled } from "ol-components"
import { Button, SimpleMenu, styled } from "ol-components"
import type { SimpleMenuItem } from "ol-components"
import { RiArrowDownSLine, RiMailLine } from "@remixicon/react"
import { useUserMe } from "api/hooks/user"
import { SourceTypeEnum } from "api"
import * as urls from "@/common/urls"
import { useLocation } from "react-router"
import { SignupPopover } from "../SignupPopover/SignupPopover"

const StyledButton = styled(Button)({
minWidth: "130px",
Expand All @@ -27,7 +26,6 @@ const SearchSubscriptionToggle: React.FC<SearchSubscriptionToggleProps> = ({
searchParams,
sourceType,
}) => {
const loc = useLocation()
const [buttonEl, setButtonEl] = useState<null | HTMLElement>(null)

const subscribeParams: Record<string, string[] | string> = useMemo(() => {
Expand Down Expand Up @@ -92,14 +90,7 @@ const SearchSubscriptionToggle: React.FC<SearchSubscriptionToggleProps> = ({
>
Follow
</StyledButton>
<SignupPopover
signupUrl={urls.login({
pathname: loc.pathname,
search: loc.search,
})}
anchorEl={buttonEl}
onClose={() => setButtonEl(null)}
/>
<SignupPopover anchorEl={buttonEl} onClose={() => setButtonEl(null)} />
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react"
import { SignupPopover } from "./SignupPopover"
import { renderWithProviders, screen, within } from "@/test-utils"
import invariant from "tiny-invariant"
import * as urls from "@/common/urls"

test("SignupPopover shows link to sign up", async () => {
renderWithProviders(
<SignupPopover anchorEl={document.body} onClose={jest.fn} />,
{
url: "/some-path?dog=woof",
},
)
const dialog = screen.getByRole("dialog")
const link = within(dialog).getByRole("link")
invariant(link instanceof HTMLAnchorElement)
expect(link.href).toMatch(
urls.login({
pathname: "/some-path",
search: "?dog=woof",
}),
)
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from "react"
import { Popover, Typography, styled, ButtonLink } from "ol-components"
import type { PopoverProps } from "ol-components"
import styled from "@emotion/styled"
import { Popover } from "../Popover/Popover"
import Typography from "@mui/material/Typography"
import { ButtonLink } from "../Button/Button"
import * as urls from "@/common/urls"
import { useLocation } from "react-router"

const StyledPopover = styled(Popover)({
width: "300px",
Expand All @@ -26,13 +25,11 @@ const Footer = styled.div({
type SignupPopoverProps = Pick<
PopoverProps,
"anchorEl" | "onClose" | "placement"
> & {
signupUrl?: string
}
>
const SignupPopover: React.FC<SignupPopoverProps> = (props) => {
const { signupUrl, ...popoverProps } = props
const loc = useLocation()
return (
<StyledPopover {...popoverProps} open={!!popoverProps.anchorEl}>
<StyledPopover {...props} open={!!props.anchorEl}>
<HeaderText variant="subtitle2">
Join {APP_SETTINGS.SITE_NAME} for free.
</HeaderText>
Expand All @@ -41,7 +38,14 @@ const SignupPopover: React.FC<SignupPopoverProps> = (props) => {
and follow your areas of interest.
</BodyText>
<Footer>
<ButtonLink href={signupUrl}>Sign Up</ButtonLink>
<ButtonLink
href={urls.login({
pathname: loc.pathname,
search: loc.search,
})}
>
Sign Up
</ButtonLink>
</Footer>
</StyledPopover>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react"
import React from "react"
import styled from "@emotion/styled"
import ISO6391 from "iso-639-1"
import {
Expand Down Expand Up @@ -26,7 +26,6 @@ import Typography from "@mui/material/Typography"
import type { User } from "api/hooks/user"
import { CardActionButton } from "../LearningResourceCard/LearningResourceListCard"
import { LearningResourceCardProps } from "../LearningResourceCard/LearningResourceCard"
import { SignupPopover } from "../SignupPopover/SignupPopover"

const InfoItems = styled.section`
display: flex;
Expand Down Expand Up @@ -243,17 +242,13 @@ const InfoSection = ({
user,
onAddToLearningPathClick,
onAddToUserListClick,
signupUrl,
}: {
resource?: LearningResource
run?: LearningResourceRun
user?: User
onAddToLearningPathClick?: LearningResourceCardProps["onAddToLearningPathClick"]
onAddToUserListClick?: LearningResourceCardProps["onAddToUserListClick"]
signupUrl?: string
}) => {
const [buttonEl, setButtonEl] = useState<null | HTMLElement>(null)

if (!resource) {
return null
}
Expand Down Expand Up @@ -294,19 +289,14 @@ const InfoSection = ({
<CardActionButton
filled={inUserList}
aria-label="Add to User List"
onClick={(event) =>
onClick={
onAddToUserListClick
? onAddToUserListClick(event, resource.id)
: setButtonEl(event.currentTarget)
? (event) => onAddToUserListClick?.(event, resource.id)
: undefined
}
>
<RiBookmarkLine aria-hidden />
</CardActionButton>
<SignupPopover
signupUrl={signupUrl}
anchorEl={buttonEl}
onClose={() => setButtonEl(null)}
/>
</ListButtonContainer>
</InfoHeader>
{infoItems.map((props, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ type LearningResourceExpandedProps = {
imgConfig: EmbedlyConfig
onAddToLearningPathClick?: LearningResourceCardProps["onAddToLearningPathClick"]
onAddToUserListClick?: LearningResourceCardProps["onAddToUserListClick"]
signupUrl?: string
}

const ImageSection: React.FC<{
Expand Down Expand Up @@ -324,7 +323,6 @@ const LearningResourceExpanded: React.FC<LearningResourceExpandedProps> = ({
imgConfig,
onAddToLearningPathClick,
onAddToUserListClick,
signupUrl,
}) => {
const [selectedRun, setSelectedRun] = useState(resource?.runs?.[0])

Expand Down Expand Up @@ -427,7 +425,6 @@ const LearningResourceExpanded: React.FC<LearningResourceExpandedProps> = ({
user={user}
onAddToLearningPathClick={onAddToLearningPathClick}
onAddToUserListClick={onAddToUserListClick}
signupUrl={signupUrl}
/>
</Container>
)
Expand Down
3 changes: 1 addition & 2 deletions frontends/ol-components/src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import type { PopperProps } from "@mui/material/Popper"
import Fade from "@mui/material/Fade"
import { FocusTrap } from "@mui/base/FocusTrap"
import ClickAwayListener from "@mui/material/ClickAwayListener"
import { MUI_DRAWER_Z_INDEX } from "../../constants/styleOverrides"

/**
* Based on MUI demo:
* https://github.com/mui/material-ui/blob/d3ef60158ba066779102fba775dda6765e2cc0f5/docs/data/material/components/popper/ScrollPlayground.js#L175
*/
const StyledPopper = styled(MuiPopper)(({ theme }) => ({
zIndex: MUI_DRAWER_Z_INDEX + 1,
zIndex: theme.zIndex.drawer + 1,
"& > div": {
position: "relative",
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as typography from "./typography"
import * as buttons from "./buttons"
import * as chips from "./chips"
import { colors } from "./colors"
import { MUI_DRAWER_Z_INDEX } from "../../constants/styleOverrides"

const shadow = {
shadowOffsetX: 3,
Expand Down Expand Up @@ -81,13 +80,6 @@ const themeOptions: ThemeOptions = {
styleOverrides: { paper: { borderRadius: "4px" } },
},
MuiChip: chips.chipComponent,
MuiDrawer: {
styleOverrides: {
paper: {
zIndex: MUI_DRAWER_Z_INDEX,
},
},
},
},
}

Expand Down
3 changes: 0 additions & 3 deletions frontends/ol-components/src/constants/styleOverrides.ts

This file was deleted.

2 changes: 0 additions & 2 deletions frontends/ol-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ export * from "./constants/imgConfigs"

export { Input, AdornmentButton } from "./components/Input/Input"
export type { InputProps, AdornmentButtonProps } from "./components/Input/Input"
export { SignupPopover } from "./components/SignupPopover/SignupPopover"
export type { SignupPopoverProps } from "./components/SignupPopover/SignupPopover"
export { SearchInput } from "./components/SearchInput/SearchInput"
export type { SearchInputProps } from "./components/SearchInput/SearchInput"
export { TextField } from "./components/TextField/TextField"
Expand Down