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
28 changes: 28 additions & 0 deletions lang/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <link>Python Editor guide</link>",
"description": "Text with an external link to support/help content"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/e2e/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -848,7 +850,7 @@ export const appUrlPattern = (path: string = ""): RegExp => {
export const appUrl = (path: string, options: UrlOptions = {}): string => {
const flags = new Set<string>([
"none",
"noWelcome",
...(options.welcome ? [] : ["noWelcome"]),
...(options.flags ?? []),
]);
const params: Array<[string, string]> = Array.from(flags).map((f) => [
Expand Down
18 changes: 17 additions & 1 deletion src/e2e/home.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -73,8 +74,10 @@ const HomePage = () => {
);
useReportCreateProjectFailure();
useReportOpenFailure();
const [whatsNewOpen, closeWhatsNew] = useWhatsNewDialog();
return (
<DefaultPageLayout>
<WhatsNewDialog isOpen={whatsNewOpen} onClose={closeWhatsNew} />
{selectedIdea && (
<IdeaDialog
{...selectedIdea}
Expand Down
134 changes: 134 additions & 0 deletions src/pages/WhatsNewDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* (c) 2026, Micro:bit Educational Foundation and contributors
*
* SPDX-License-Identifier: MIT
*/
import {
Button,
Icon,
Modal,
ModalBody,
ModalCloseButton,
ModalFooter,
ModalHeader,
Text,
} from "@microbit/ui";
import { ReactNode, useEffect, useState } from "react";
import { IconType } from "react-icons";
import { RiDownload2Line, RiFolderOpenLine, RiHome2Line } from "react-icons/ri";
import { FormattedMessage, useIntl } from "react-intl";
import { HStack, Stack } from "styled-system/jsx";
import { useStorage } from "../common/use-storage";
import { useCookieConsent } from "../deployment";
import { flags } from "../flags";

// Bump this to show the dialog again.
const currentVersion = 1;

interface WhatsNewStorage {
version: number;
}

const isWhatsNewStorage = (v: unknown): v is WhatsNewStorage =>
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 (
<Modal isOpen={isOpen} onClose={onClose} size="lg">
<ModalCloseButton />
<ModalHeader css={{ fontWeight: "bold" }}>
<FormattedMessage id="whats-new-title" />
</ModalHeader>
<ModalBody>
<Stack gap="5">
<Point
icon={RiHome2Line}
heading={<FormattedMessage id="whats-new-home-heading" />}
>
<FormattedMessage id="whats-new-home" />
</Point>
<Point
icon={RiFolderOpenLine}
heading={<FormattedMessage id="my-projects-row-title" />}
>
<FormattedMessage
id="whats-new-projects"
values={{
viewAll: intl.formatMessage({ id: "view-all-projects" }),
}}
/>
</Point>
<Point
icon={RiDownload2Line}
heading={<FormattedMessage id="whats-new-copy-heading" />}
>
<FormattedMessage id="whats-new-copy" />
</Point>
</Stack>
</ModalBody>
<ModalFooter>
<Button variant="primary" size="lg" onPress={onClose}>
<FormattedMessage id="get-started-action" />
</Button>
</ModalFooter>
</Modal>
);
};

const Point = ({
icon,
heading,
children,
}: {
icon: IconType;
heading: ReactNode;
children: ReactNode;
}) => (
<HStack gap="4" alignItems="flex-start">
<Icon
as={icon}
aria-hidden
css={{ flexShrink: 0, width: 6, height: 6, mt: 0.5, color: "brand.500" }}
/>
<Stack gap="1">
<Text as="h3" fontSize="lg" fontWeight="semibold">
{heading}
</Text>
<Text>{children}</Text>
</Stack>
</HStack>
);

export default WhatsNewDialog;