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

LB-1555: Fresh Releases Page fixes #2975

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions frontend/css/sidebar.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
flex: 0 0 250px;
max-height: 100vh;
overflow-y: auto;
z-index: 9997;
z-index: 109;
right: 0;
background: #f3f3f3;

Expand All @@ -30,6 +30,7 @@
transition: right 0.3s ease-in-out;
&.open {
right: 0;
z-index: 112;
}
}

Expand Down Expand Up @@ -86,7 +87,7 @@

.toggle-sidebar-button {
position: fixed;
bottom: 20px;
bottom: 20px + @brainzplayer-height;
right: 20px;
z-index: 9999;
width: 64px;
Expand Down
11 changes: 9 additions & 2 deletions frontend/js/src/components/Pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ type PillProps = {
};

export default function Pill(props: React.PropsWithChildren<PillProps>) {
const { active, children, type, style: propStyle, ...buttonProps } = props;
const {
active,
children,
type,
style: propStyle,
className: propClassName = "",
...buttonProps
} = props;

return (
<button
Expand All @@ -19,7 +26,7 @@ export default function Pill(props: React.PropsWithChildren<PillProps>) {
{...buttonProps}
className={`pill ${type === "secondary" ? "secondary" : ""} ${
active ? "active" : ""
}`}
} ${propClassName}`}
>
{children}
</button>
Expand Down
24 changes: 22 additions & 2 deletions frontend/js/src/explore/fresh-releases/FreshReleases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Spinner from "react-loader-spinner";
import { toast } from "react-toastify";
import { Helmet } from "react-helmet";
import { useQuery } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";
import GlobalAppContext from "../../utils/GlobalAppContext";
import { ToastMsg } from "../../notifications/Notifications";
import ReleaseFilters from "./components/ReleaseFilters";
Expand Down Expand Up @@ -104,6 +105,7 @@ type FreshReleasesData = {

export default function FreshReleases() {
const { APIService, currentUser } = React.useContext(GlobalAppContext);
const navigate = useNavigate();

const isLoggedIn: boolean = Object.keys(currentUser).length !== 0;

Expand Down Expand Up @@ -278,6 +280,18 @@ export default function FreshReleases() {
message = `0/${releases.length} releases match your filters.`;
}

const handleLoginRedirect = () => {
toast.error(
anshg1214 marked this conversation as resolved.
Show resolved Hide resolved
<ToastMsg
title="You must be logged in to view personalized releases"
message="Please log in to view personalized releases"
/>,
{ toastId: "login-error" }
);

navigate("/login");
};

return (
<>
<Helmet>
Expand All @@ -301,10 +315,16 @@ export default function FreshReleases() {
</Pill>
<Pill
id="user-releases"
onClick={() => setPageType(PAGE_TYPE_USER)}
onClick={() => {
if (isLoggedIn) {
setPageType(PAGE_TYPE_USER);
} else {
handleLoginRedirect();
}
}}
active={pageType === PAGE_TYPE_USER}
type="secondary"
disabled={!isLoggedIn}
className={isLoggedIn ? "" : "disabled"}
>
For You
</Pill>
Expand Down
16 changes: 11 additions & 5 deletions frontend/js/tests/components/Pill.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ import Pill from "../../src/components/Pill";
describe("Pill", () => {
it("renders correctly for primary active", () => {
const wrapper = mount(<Pill active type="primary" />);
expect(wrapper.getDOMNode()).toContainHTML('<button type="button" class="pill active"></button>');
expect(wrapper.getDOMNode()).toContainHTML(
'<button type="button" class="pill active "></button>'
);
});

it("renders correctly for secondary active", () => {
const wrapper = mount(<Pill active type="secondary" />);
expect(wrapper.getDOMNode()).toContainHTML('<button type="button" class="pill secondary active"></button>');
expect(wrapper.getDOMNode()).toContainHTML(
'<button type="button" class="pill secondary active "></button>'
);
});

it("renders correctly for inactive", () => {
const wrapper = mount(<Pill />);
expect(wrapper.getDOMNode()).toContainHTML('<button type="button" class="pill "></button>');
expect(wrapper.getDOMNode()).toContainHTML(
'<button type="button" class="pill "></button>'
);
});
});
34 changes: 14 additions & 20 deletions frontend/js/tests/explore/fresh-releases/FreshReleases.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from "react";
import { BrowserRouter } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render, screen, waitFor } from "@testing-library/react";
import { screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import APIService from "../../../src/utils/APIService";
Expand All @@ -13,9 +12,8 @@ import * as sitewideFilters from "../../__mocks__/freshReleasesSitewideFilters.j
import * as userDisplayFilters from "../../__mocks__/freshReleasesDisplaySettings.json";
import RecordingFeedbackManager from "../../../src/utils/RecordingFeedbackManager";

import GlobalAppContext, {
GlobalAppContextT,
} from "../../../src/utils/GlobalAppContext";
import type { GlobalAppContextT } from "../../../src/utils/GlobalAppContext";
import { renderWithProviders } from "../../test-utils/rtl-test-utils";

const freshReleasesProps = {
user: {
Expand Down Expand Up @@ -86,12 +84,11 @@ describe("FreshReleases", () => {
});
mountOptions.context.APIService.fetchUserFreshReleases = mockFetchUserFreshReleases;

render(
<GlobalAppContext.Provider value={{ ...mountOptions.context }}>
<QueryClientProvider client={queryClient}>
<FreshReleases />
</QueryClientProvider>
</GlobalAppContext.Provider>
renderWithProviders(
<QueryClientProvider client={queryClient}>
<FreshReleases />
</QueryClientProvider>,
mountOptions.context
);

await waitFor(() => {
Expand All @@ -117,14 +114,11 @@ describe("FreshReleases", () => {
});
mountOptions.context.APIService.fetchUserFreshReleases = mockFetchUserFreshReleases;

render(
<GlobalAppContext.Provider value={{ ...mountOptions.context }}>
<BrowserRouter>
<QueryClientProvider client={queryClient}>
<FreshReleases />
</QueryClientProvider>
</BrowserRouter>
</GlobalAppContext.Provider>
renderWithProviders(
<QueryClientProvider client={queryClient}>
<FreshReleases />
</QueryClientProvider>,
mountOptions.context
);

await waitFor(() => {
Expand All @@ -151,7 +145,7 @@ describe("FreshReleases", () => {
const setShowFutureReleases = jest.fn();
const releaseCardGridRef: React.RefObject<HTMLDivElement> = React.createRef();

render(
renderWithProviders(
<ReleaseFilters
releaseTags={sitewideFilters.releaseTags}
releaseTypes={sitewideFilters.releaseTypes}
Expand Down