diff --git a/e2e/specs/routing.spec.ts b/e2e/specs/routing.spec.ts index 81de5ec7..66fcb75d 100644 --- a/e2e/specs/routing.spec.ts +++ b/e2e/specs/routing.spec.ts @@ -173,7 +173,10 @@ test("takes over the space menu's history entry when you navigate out of it", as await expect(drawer).toHaveCount(0) }) -test("switches spaces inside the space menu without closing it", async ({seed, as}) => { +test("switches spaces inside the space menu, and out of one it has a page for", async ({ + seed, + as, +}) => { const scenario = await seed(({relay, user}) => { const space = relay("space") const other = relay("other") @@ -207,6 +210,14 @@ test("switches spaces inside the space menu without closing it", async ({seed, a await expect(page).toHaveURL(new RegExp(`${roomPath(other.url, "garden")}$`)) await expect(drawer).toHaveCount(0) + + // The space she started in has a page behind it now, so picking it needs no second tap and the + // menu has nothing left to ask. + await page.getByRole("button", {name: "Open space menu"}).click() + await drawer.locator('.primary-nav [data-tip^="space"]').click() + + await expect(page).toHaveURL(new RegExp(`${roomPath(space.url, "lounge")}$`)) + await expect(drawer).toHaveCount(0) }) test("enters a space on its details page whatever its relay advertises", async ({seed, as}) => { diff --git a/src/app/components/PrimaryNavItemSpace.svelte b/src/app/components/PrimaryNavItemSpace.svelte index 20c38a21..30e1087f 100644 --- a/src/app/components/PrimaryNavItemSpace.svelte +++ b/src/app/components/PrimaryNavItemSpace.svelte @@ -4,7 +4,7 @@ import RelayIcon from "@app/components/RelayIcon.svelte" import {relays} from "@app/core" import {navigate} from "@app/modal" - import {makeSpacePath, makeSpaceEntryPath} from "@app/routes" + import {makeSpacePath, makeSpaceEntryPath, hasSpacePage} from "@app/routes" import {notifications} from "@app/notifications" type Props = { @@ -17,7 +17,10 @@ const onClick = () => { const entryPath = makeSpaceEntryPath(url) - navigate(entryPath, {keepModal: true, replaceState: entryPath === $page.url.pathname}) + navigate(entryPath, { + keepModal: !hasSpacePage(url), + replaceState: entryPath === $page.url.pathname, + }) } const path = makeSpacePath(url) diff --git a/src/app/routes.ts b/src/app/routes.ts index 345384e0..f939fcc4 100644 --- a/src/app/routes.ts +++ b/src/app/routes.ts @@ -94,6 +94,8 @@ export const makeSpacePath = (url: string, ...extra: (string | undefined)[]) => export const forgetSpacePage = (url: string) => lastPageBySpaceUrl.delete(url) +export const hasSpacePage = (url: string) => lastPageBySpaceUrl.has(url) + export const makeSpaceEntryPath = (url: string) => lastPageBySpaceUrl.get(url) ?? makeSpacePath(url, "about")