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
17 changes: 9 additions & 8 deletions components/workspaces/item-home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,24 @@ export function TabWorkspace({ first, children }: { first: string | null; childr
}

/**
* Says in the rail's cookie which workspace this tab is in, on every page it opens, an item opened by the address's
* query included: an address that names no workspace opens in the one used last (proxy.ts `lastWorkspaceStart`,
* `TabWorkspace`). Apart from the rail, which a phone mounts only while its sheet is open, and which redraws in a tab
* left open behind.
* Says in the rail's cookie which workspace this tab is in, on every page of one that it opens, an item opened by the
* address's query included: an address that names no workspace opens in the one used last (proxy.ts
* `lastWorkspaceStart`, `TabWorkspace`). A page that is in no workspace says nothing, so signing in leaves it as it
* was. Apart from the rail, which a phone mounts only while its sheet is open, and which redraws in a tab left open
* behind.
*/
export function LastWorkspace() {
const key = lookKey(useWorkspaceSlug());
const pathname = usePathname();
const named = addressWorkspace(pathname);
const query = useSearchParams().toString();
const { userId } = useAuth();
// The browser's cookies are the outside system: the proxy and the server read them on the next page load.
useEffect(() => {
if (!userId) return;
if (!userId || named === undefined) return;
const raw = lookCookieIn(document.cookie);
const next = writeCache(usedLast(readCache(raw, userId), key), userId, key, undefined, undefined);
const next = writeCache(usedLast(readCache(raw, userId), lookKey(named)), userId, lookKey(named), undefined, undefined);
if (next && next !== raw) document.cookie = lookCookieOut(next);
}, [userId, key, pathname, query]);
}, [userId, named, pathname, query]);
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/workspaces/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ it("names the workspace of every address, and none for a page that is the same i
expect(addressWorkspace("/shared")).toBeNull();
expect(addressWorkspace("/papers/W1/a-title")).toBeUndefined();
expect(addressWorkspace("/privacy")).toBeUndefined();
// Signing in is no use of a person's own workspace: the one used last has to outlast it.
expect(addressWorkspace("/sign-in/factor-one")).toBeUndefined();
// Such a page stays in the organization its tab was in: from it, a switch to the person's own workspace goes to their home page.
expect(switchTarget(undefined, "/papers/W1", "")).toBe("/");
expect(switchTarget("lab", "/papers/W1", "")).toBe("/o/lab");
Expand Down
7 changes: 4 additions & 3 deletions lib/workspaces/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ const within = (path: string, section: string) => path === section || path.start
const ORGANIZATION_ONLY = "/settings/workspace";

/**
* Pages that are in no workspace, the same whichever one the person works in: a paper's page and the policy pages.
* A tab that opens one stays in the workspace it was in (`addressWorkspace`).
* Pages that are in no workspace, the same whichever one the person works in: a paper's page, the policy pages and
* the pages for signing in. A tab that opens one stays in the workspace it was in (`addressWorkspace`), and opening
* one is no use of a workspace: signing in must not make a person's own workspace the one they used last.
*/
const NO_WORKSPACE = ["/papers", "/privacy", "/terms", "/cookie-policy", "/credits"];
const NO_WORKSPACE = ["/papers", "/privacy", "/terms", "/cookie-policy", "/credits", "/sign-in", "/sign-up"];

/**
* The workspace a page's address names: an organization's slug under /o/<slug>, null for a person's own, and
Expand Down
Loading