diff --git a/lang/ui.en.json b/lang/ui.en.json index 018809bb0..8dbbba0ec 100644 --- a/lang/ui.en.json +++ b/lang/ui.en.json @@ -375,6 +375,10 @@ "defaultMessage": "Font size", "description": "Font size option text" }, + "get-started-action": { + "defaultMessage": "Get started", + "description": "Button that closes the what's new dialog on the home page" + }, "guide-link": { "defaultMessage": "For more support, see the Python Editor guide", "description": "Text with an external link to support/help content" @@ -1490,6 +1494,30 @@ "defaultMessage": "video introducing the Python Editor", "description": "iframe title for the welcome video" }, + "whats-new-copy": { + "defaultMessage": "Saving a HEX file to your computer is the most reliable way to keep a copy of your project.", + "description": "Body of the keep a copy point in the what's new dialog shown on the home page" + }, + "whats-new-copy-heading": { + "defaultMessage": "Keep a copy", + "description": "Heading of the point in the what's new dialog advising users to save a HEX file" + }, + "whats-new-home": { + "defaultMessage": "Your projects, ideas and help, all in one place.", + "description": "Body of the home page point in the what's new dialog shown on the home page" + }, + "whats-new-home-heading": { + "defaultMessage": "A new Home page", + "description": "Heading of the point in the what's new dialog introducing the home page" + }, + "whats-new-projects": { + "defaultMessage": "Your projects now stay in this browser between visits. Select \"{viewAll}\" to find, rename and delete them.", + "description": "Body of the My projects point in the what's new dialog. {viewAll} is the link label on the home page's My projects row (\"View all\")" + }, + "whats-new-title": { + "defaultMessage": "What's new in the Python Editor", + "description": "Title of the dialog shown once on the home page explaining the home page and saved projects" + }, "zoom-in-action": { "defaultMessage": "Zoom in", "description": "Text label for zoom in button" diff --git a/src/e2e/app.ts b/src/e2e/app.ts index 866d76b57..2b979df1e 100644 --- a/src/e2e/app.ts +++ b/src/e2e/app.ts @@ -36,6 +36,8 @@ export interface UrlOptions { language?: string; /** Iframe controller mode, as embedded by classroom. */ controller?: boolean; + /** Show the dialogs that greet a browser on its first visit. */ + welcome?: boolean; } interface SaveOptions { @@ -848,7 +850,7 @@ export const appUrlPattern = (path: string = ""): RegExp => { export const appUrl = (path: string, options: UrlOptions = {}): string => { const flags = new Set([ "none", - "noWelcome", + ...(options.welcome ? [] : ["noWelcome"]), ...(options.flags ?? []), ]); const params: Array<[string, string]> = Array.from(flags).map((f) => [ diff --git a/src/e2e/home.test.ts b/src/e2e/home.test.ts index 744a6d4f1..20a102ac2 100644 --- a/src/e2e/home.test.ts +++ b/src/e2e/home.test.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ import { expect } from "@playwright/test"; -import { appUrlPattern } from "./app.js"; +import { appUrlPattern, homeUrl } from "./app.js"; import { test } from "./app-test-fixtures.js"; import { modalDialog } from "./home-page.js"; @@ -32,6 +32,22 @@ test.describe("home page", () => { await homePage.expectNoNewAccessibilityViolations(); }); + test("shows what's new once", async ({ homePage }) => { + // Not homePage.goto(): the dialog repeats the heading it waits for. + await homePage.page.goto(homeUrl({ welcome: true })); + const dialog = modalDialog(homePage.page); + await expect( + dialog.getByRole("heading", { name: "What's new in the Python Editor" }) + ).toBeVisible(); + await homePage.expectNoNewAccessibilityViolations(); + await dialog.getByRole("button", { name: "Get started" }).click(); + await expect(dialog).toBeHidden(); + + await homePage.page.reload(); + await homePage.expectOnPage(); + await expect(dialog).toBeHidden(); + }); + test("creates a project and opens it in the editor", async ({ app, homePage, diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx index 9ebc55e1e..7c28e6216 100644 --- a/src/pages/HomePage.tsx +++ b/src/pages/HomePage.tsx @@ -34,6 +34,7 @@ import ActionCard from "./ActionCard"; import DefaultPageLayout from "./DefaultPageLayout"; import IdeaDialog from "./IdeaDialog"; import ProjectIcon from "./ProjectIcon"; +import WhatsNewDialog, { useWhatsNewDialog } from "./WhatsNewDialog"; import HomepageBanner from "./HomepageBanner"; import HomepageFooter from "./HomepageFooter"; import { @@ -73,8 +74,10 @@ const HomePage = () => { ); useReportCreateProjectFailure(); useReportOpenFailure(); + const [whatsNewOpen, closeWhatsNew] = useWhatsNewDialog(); return ( + {selectedIdea && ( + typeof v === "object" && Number.isInteger((v as any).version); + +/** + * Shown once per browser after cookie consent, to new users as well as + * returning ones: on shared school machines the change is new to the teacher + * even when the browser is not. + * + * Only the home page uses this, and it is only reachable with the projects + * database, so iframe mode and the session storage fallback never see it. + */ +export const useWhatsNewDialog = (): [boolean, () => void] => { + const [stored, setStored] = useStorage( + "local", + "whats-new", + { version: 0 }, + isWhatsNewStorage + ); + const [isOpen, setIsOpen] = useState(false); + const cookieConsent = useCookieConsent(); + useEffect(() => { + if (cookieConsent && !flags.noWelcome && stored.version < currentVersion) { + setIsOpen(true); + setStored({ version: currentVersion }); + } + }, [cookieConsent, stored, setStored]); + return [isOpen, () => setIsOpen(false)]; +}; + +interface WhatsNewDialogProps { + isOpen: boolean; + onClose: () => void; +} + +const WhatsNewDialog = ({ isOpen, onClose }: WhatsNewDialogProps) => { + const intl = useIntl(); + return ( + + + + + + + + } + > + + + } + > + + + } + > + + + + + + + + + ); +}; + +const Point = ({ + icon, + heading, + children, +}: { + icon: IconType; + heading: ReactNode; + children: ReactNode; +}) => ( + + + + + {heading} + + {children} + + +); + +export default WhatsNewDialog;