@peers-app/peers-ui 0.33.6 → 0.33.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openInGroup = openInGroup;
4
+ exports.resumeGroupNavigation = resumeGroupNavigation;
5
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
6
+ const identity_routes_1 = require("../screens/identity/identity-routes");
7
+ const tabs_state_1 = require("../tabs-layout/tabs-state");
8
+ const find_route_1 = require("./find-route");
9
+ // The name is from when only notifications opened links in other groups; kept so a switch
10
+ // already under way when the app updates still finishes.
11
+ const pendingNavigationKey = "peers.notificationNavigation";
12
+ /**
13
+ * Open a route that belongs to one of the user's groups, as a notification or a mention does.
14
+ *
15
+ * - A screen that shows any group itself (its route's `opensAnyGroup`) opens in place, with
16
+ * `groupId` added to the path for the screen to read.
17
+ * - A route in the active group opens as it is.
18
+ * - Otherwise Peers switches to the group, which reloads the window, and opens the route once the
19
+ * group's routes and tabs have loaded ({@link resumeGroupNavigation}).
20
+ *
21
+ * @param path - The route, such as `package-nav/<packageId>/app?taskId=<id>`.
22
+ * @param groupId - The group it belongs to; the user's id for Personal.
23
+ * @returns false, having opened nothing, when the group isn't one the user is in (left or
24
+ * disabled): selecting it would create a context for it and keep it across restarts.
25
+ */
26
+ async function openInGroup(path, groupId) {
27
+ const userContext = await (0, peers_sdk_1.getUserContext)();
28
+ const member = () => groupId === userContext.userId || userContext.groupIds().includes(groupId);
29
+ // Match the path the tab will render, including the host's group and normal query encoding.
30
+ const inPlacePath = (0, identity_routes_1.canonicalizeRoute)(withGroupId(path, groupId));
31
+ if (opensAnyGroup(inPlacePath) && member()) {
32
+ (0, tabs_state_1.goToTabPath)(inPlacePath);
33
+ return true;
34
+ }
35
+ if ((userContext.currentlyActiveGroupId() || userContext.userId) !== groupId) {
36
+ if (!member())
37
+ return false;
38
+ // Group switching reloads the renderer. Carry the destination through startup; navigating
39
+ // after a delay can lose the link or write it into the old group's tabs.
40
+ sessionStorage.setItem(pendingNavigationKey, JSON.stringify({ userId: userContext.userId, groupId, path }));
41
+ userContext.currentlyActiveGroupId(groupId);
42
+ await userContext.waitForActiveGroupPersistence();
43
+ await peers_sdk_1.rpcServerCalls.flushDatabases();
44
+ window.location.reload();
45
+ return true;
46
+ }
47
+ (0, tabs_state_1.goToTabPath)(path);
48
+ return true;
49
+ }
50
+ /** Finish {@link openInGroup}'s group switch after the new group's routes and tabs have loaded. */
51
+ async function resumeGroupNavigation() {
52
+ const pending = sessionStorage.getItem(pendingNavigationKey);
53
+ if (!pending)
54
+ return;
55
+ sessionStorage.removeItem(pendingNavigationKey);
56
+ const userContext = await (0, peers_sdk_1.getUserContext)();
57
+ try {
58
+ const target = JSON.parse(pending);
59
+ if (target.userId === userContext.userId &&
60
+ target.groupId === (userContext.currentlyActiveGroupId() || userContext.userId) &&
61
+ typeof target.path === "string")
62
+ (0, tabs_state_1.goToTabPath)(target.path);
63
+ }
64
+ catch {
65
+ // A stale or malformed session value must not prevent the shell from starting.
66
+ }
67
+ }
68
+ /** Whether the active group's screen for this path shows any of the user's groups itself. */
69
+ function opensAnyGroup(path) {
70
+ // UIRouter includes the rendered props in the context passed to isMatch too.
71
+ const context = { path, uiCategory: "screen", props: {} };
72
+ return !!(0, find_route_1.findRoute)(context, context.props)?.opensAnyGroup;
73
+ }
74
+ /** The path with `groupId` set in its query, replacing one the link carried. */
75
+ function withGroupId(path, groupId) {
76
+ const at = path.indexOf("?");
77
+ const route = at < 0 ? path : path.slice(0, at);
78
+ const params = new URLSearchParams(at < 0 ? "" : path.slice(at + 1));
79
+ params.set("groupId", groupId);
80
+ return `${route}?${params.toString()}`;
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-ui",
3
- "version": "0.33.6",
3
+ "version": "0.33.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-ui.git"
@@ -29,14 +29,14 @@
29
29
  "release:minor": "npm run release:guard && npm run clean && npm run build && npm version minor && git push && git push --tags",
30
30
  "release:major": "npm run release:guard && npm run clean && npm run build && npm version major && git push && git push --tags",
31
31
  "release": "npm run release:patch",
32
- "test": "jest --no-watchman",
32
+ "test": "jest --no-watchman && node --test src/components/markdown-remark.test.mjs",
33
33
  "test:watch": "jest --watch",
34
34
  "test:coverage": "jest --coverage",
35
35
  "lint": "biome check .",
36
36
  "lint:fix": "biome check --write ."
37
37
  },
38
38
  "peerDependencies": {
39
- "@peers-app/peers-sdk": "^0.33.6",
39
+ "@peers-app/peers-sdk": "^0.33.7",
40
40
  "bootstrap": "^5.3.3",
41
41
  "react": "^18.0.0",
42
42
  "react-dom": "^18.0.0"
@@ -47,7 +47,7 @@
47
47
  "@babel/preset-react": "^7.24.1",
48
48
  "@babel/preset-typescript": "^7.27.1",
49
49
  "@biomejs/biome": "2.3.11",
50
- "@peers-app/peers-sdk": "0.33.6",
50
+ "@peers-app/peers-sdk": "0.33.7",
51
51
  "@testing-library/dom": "^10.4.0",
52
52
  "@testing-library/jest-dom": "^6.6.3",
53
53
  "@testing-library/react": "^16.3.0",