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

fix: download form #242

Merged
merged 3 commits into from
Sep 14, 2023
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
1 change: 1 addition & 0 deletions cypress/e2e/download-page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe("The Download Page", () => {
cy.get(inputSelector).type("99");
cy.get(inputSelector).should("have.value", maxSize);
cy.url().should("include", `size=${maxSize}`);
cy.get("button#all-button").should("be.disabled");
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
"use client";

import { useState, forwardRef } from "react";
import { useTranslations } from "next-intl";
import { useRouter } from "next-intl/client";
import { Dialog, DialogContent, Slide } from "@mui/material";
import CloseIcon from "@mui/icons-material/Close";
import {
Dialog,
DialogContent,
DialogTitle,
IconButton,
Slide,
} from "@mui/material";
import { useTheme } from "@mui/material/styles";
import type { TransitionProps } from "@mui/material/transitions";
import type { ClientComponent } from "@/types/next";
Expand All @@ -17,11 +25,12 @@ const Transition = forwardRef(function Transition(
const DownloadModal: ClientComponent<Record<string, unknown>, true> = ({
children,
}) => {
const t = useTranslations("download");
const [open, setOpen] = useState(true);
const router = useRouter();
const theme = useTheme();

const close = (): void => {
const close = () => {
setOpen(false);

// Wait until the leaving screen animation is over to go back to the /results page
Expand All @@ -38,7 +47,20 @@ const DownloadModal: ClientComponent<Record<string, unknown>, true> = ({
maxWidth="xl"
scroll="body"
>
<DialogContent sx={{ bgcolor: "colors.white" }}>{children}</DialogContent>
<DialogTitle sx={{ bgcolor: "colors.white" }}>{t("title")}</DialogTitle>
<IconButton
onClick={close}
sx={{
position: "absolute",
right: 8,
top: 8,
}}
>
<CloseIcon />
</IconButton>
<DialogContent dividers sx={{ bgcolor: "colors.white" }}>
{children}
</DialogContent>
</Dialog>
);
};
Expand Down
16 changes: 12 additions & 4 deletions src/app/[locale]/download/components/DownloadForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import UsageSelector from "./UsageSelector";
import useSearchParams from "@/lib/useSearchParams";
import type { ClientComponent } from "@/types/next";

const DownloadForm: ClientComponent<{ resultsCount: number }> = ({
interface DownloadFormProps {
resultsCount: number;
displayTitle?: boolean;
}

const DownloadForm: ClientComponent<DownloadFormProps> = ({
resultsCount,
displayTitle,
}) => {
const t = useTranslations("download");
const searchParams = useSearchParams();
Expand All @@ -26,9 +32,11 @@ const DownloadForm: ClientComponent<{ resultsCount: number }> = ({

return (
<>
<Typography component="h1" variant="h5" gutterBottom>
{t("title")}
</Typography>
{displayTitle === true && (
<Typography component="h1" variant="h5" gutterBottom>
{t("title")}
</Typography>
)}
<Grid container spacing={2}>
<Grid item xs={12} md={8}>
<Paper elevation={0} sx={{ p: 2 }}>
Expand Down
6 changes: 4 additions & 2 deletions src/app/[locale]/download/components/ResultsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const ResultsSettings: ClientComponent<{ resultsCount: number }> = ({
onChange={handleChange}
/>
<span data-testid="max-size-label">
/&nbsp;{maxSize.toLocaleString(locale)}
/&nbsp;{resultsCount.toLocaleString(locale)}
</span>
{resultsCount > maxSize && (
<Tooltip
Expand All @@ -72,11 +72,13 @@ const ResultsSettings: ClientComponent<{ resultsCount: number }> = ({
</Tooltip>
)}
<Button
id="all-button"
variant="outlined"
sx={{ ml: "auto" }}
disabled={size === maxSize}
onClick={() => {
setSize(maxSize);
}}
sx={{ ml: "auto" }}
>
{t("allButton")}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/download/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const DownloadPage: Page = async ({ searchParams: nextSearchParams }) => {

return (
<Container sx={{ py: 6 }}>
<DownloadForm resultsCount={resultsCount} />
<DownloadForm resultsCount={resultsCount} displayTitle />
</Container>
);
};
Expand Down