@peers-app/peers-ui 0.31.8 → 0.32.1
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.
|
@@ -48,16 +48,24 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
|
48
48
|
const [showCreateModal, setShowCreateModal] = (0, react_1.useState)(false);
|
|
49
49
|
const [allGroups, setAllGroups] = (0, react_1.useState)([]);
|
|
50
50
|
const userContext = (0, hooks_1.usePromise)(peers_sdk_1.getUserContext);
|
|
51
|
-
// Load groups from user context
|
|
51
|
+
// Load groups from user context, and again whenever a group is added, renamed, removed or
|
|
52
|
+
// restored, on this device or another of the user's.
|
|
52
53
|
(0, react_1.useEffect)(() => {
|
|
53
54
|
if (!userContext)
|
|
54
55
|
return;
|
|
56
|
+
const groupsTable = (0, peers_sdk_1.Groups)(userContext.userDataContext);
|
|
57
|
+
let disposed = false;
|
|
55
58
|
const loadGroups = async () => {
|
|
56
|
-
const groupsTable = (0, peers_sdk_1.Groups)(userContext.userDataContext);
|
|
57
59
|
const groupsList = await groupsTable.list({ disabled: { $ne: true } });
|
|
58
|
-
|
|
60
|
+
if (!disposed)
|
|
61
|
+
setAllGroups(groupsList);
|
|
62
|
+
};
|
|
63
|
+
void loadGroups();
|
|
64
|
+
const subscription = groupsTable.dataChanged.subscribe(() => void loadGroups());
|
|
65
|
+
return () => {
|
|
66
|
+
disposed = true;
|
|
67
|
+
subscription.unsubscribe();
|
|
59
68
|
};
|
|
60
|
-
loadGroups();
|
|
61
69
|
}, [userContext]);
|
|
62
70
|
// Use useMemo to recompute currentGroup when either currentGroupId or allGroups changes
|
|
63
71
|
const currentGroup = react_1.default.useMemo(() => {
|
|
@@ -3,14 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GroupDetails = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
-
const
|
|
6
|
+
const react_1 = require("react");
|
|
7
7
|
const input_1 = require("../../components/input");
|
|
8
8
|
const loading_indicator_1 = require("../../components/loading-indicator");
|
|
9
9
|
const editor_inline_1 = require("../../components/markdown-editor/editor-inline");
|
|
10
10
|
const save_button_1 = require("../../components/save-button");
|
|
11
11
|
const tabs_1 = require("../../components/tabs");
|
|
12
|
+
const globals_1 = require("../../globals");
|
|
12
13
|
const hooks_1 = require("../../hooks");
|
|
13
14
|
const context_files_1 = require("../files/context-files");
|
|
15
|
+
const identity_routes_1 = require("../identity/identity-routes");
|
|
14
16
|
const group_members_1 = require("./group-members");
|
|
15
17
|
/** Edit group metadata, manage members and invitations, and inspect files inside Identity. */
|
|
16
18
|
const GroupDetails = (props) => {
|
|
@@ -31,21 +33,14 @@ const GroupDetails = (props) => {
|
|
|
31
33
|
await userGroupTable.signAndSave(groupData);
|
|
32
34
|
return groupDoc.load();
|
|
33
35
|
};
|
|
34
|
-
const originalDelete = groupDoc.delete;
|
|
35
|
-
groupDoc.delete = async () => {
|
|
36
|
-
const deleteResult = await originalDelete();
|
|
37
|
-
userContext.defaultDataContext(userContext.userDataContext);
|
|
38
|
-
await (0, peers_sdk_1.sleep)(100);
|
|
39
|
-
await peers_sdk_1.rpcServerCalls.flushDatabases();
|
|
40
|
-
window.location.reload();
|
|
41
|
-
return deleteResult;
|
|
42
|
-
};
|
|
43
36
|
return groupDoc;
|
|
44
37
|
}, undefined, [props.groupId]);
|
|
45
38
|
if (!group) {
|
|
46
39
|
return (0, jsx_runtime_1.jsx)(loading_indicator_1.LoadingIndicator, {});
|
|
47
40
|
}
|
|
48
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "container-xxl p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex", children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)("i", { className: `${(0, peers_sdk_1.getIconClassName)((0, peers_sdk_1.Groups)())} me-2` }) }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1", children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)(input_1.Input, { className: "border border-0", style: { width: "100%", outline: "none", backgroundColor: "transparent" }, value: group.qs.name }, group.groupId) }) }), (0, jsx_runtime_1.jsx)(save_button_1.SaveButton, { doc: group
|
|
41
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "container-xxl p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex", children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)("i", { className: `${(0, peers_sdk_1.getIconClassName)((0, peers_sdk_1.Groups)())} me-2` }) }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1", children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)(input_1.Input, { className: "border border-0", style: { width: "100%", outline: "none", backgroundColor: "transparent" }, value: group.qs.name }, group.groupId) }) }), (0, jsx_runtime_1.jsx)(save_button_1.SaveButton, { doc: group, deleteLabel: "Remove", onDelete: async () => {
|
|
42
|
+
await (0, peers_sdk_1.removeGroup)(await (0, peers_sdk_1.getUserContext)(), group.groupId);
|
|
43
|
+
} }, group.groupId)] }), (0, jsx_runtime_1.jsx)(tabs_1.Tabs, { tabs: [
|
|
49
44
|
{
|
|
50
45
|
name: "Info",
|
|
51
46
|
content: ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(GroupInfo, { group: group }) })),
|
|
@@ -65,7 +60,36 @@ exports.GroupDetails = GroupDetails;
|
|
|
65
60
|
const GroupInfo = (props) => {
|
|
66
61
|
const { group } = props;
|
|
67
62
|
group.description = group.description || "";
|
|
68
|
-
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("small", { children: "Name:" }), (0, jsx_runtime_1.jsx)(input_1.Input, { value: group.qs.name, className: "form-control mb-3 p-0 ps-2", placeholder: "Group name", title: "Group name" }), (0, jsx_runtime_1.jsx)("small", { children: "Icon Class Name:" }), (0, jsx_runtime_1.jsx)(input_1.Input, { value: group.qs.iconClassName, className: "form-control mb-3 p-0 ps-2", placeholder: "bi-people-fill", title: "Icon class name (e.g., bi-people-fill, bi-house-fill, bi-star-fill)" }), (0, jsx_runtime_1.jsx)("small", { children: "Group ID:" }), (0, jsx_runtime_1.jsx)("div", { className: "form-control mb-3 p-2 bg-body-secondary text-body-secondary", style: { fontFamily: "monospace", fontSize: "0.9em" }, children: group.groupId }), (0, jsx_runtime_1.jsx)("
|
|
63
|
+
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("small", { children: "Name:" }), (0, jsx_runtime_1.jsx)(input_1.Input, { value: group.qs.name, className: "form-control mb-3 p-0 ps-2", placeholder: "Group name", title: "Group name" }), (0, jsx_runtime_1.jsx)("small", { children: "Icon Class Name:" }), (0, jsx_runtime_1.jsx)(input_1.Input, { value: group.qs.iconClassName, className: "form-control mb-3 p-0 ps-2", placeholder: "bi-people-fill", title: "Icon class name (e.g., bi-people-fill, bi-house-fill, bi-star-fill)" }), (0, jsx_runtime_1.jsx)("small", { children: "Group ID:" }), (0, jsx_runtime_1.jsx)("div", { className: "form-control mb-3 p-2 bg-body-secondary text-body-secondary", style: { fontFamily: "monospace", fontSize: "0.9em" }, children: group.groupId }), (0, jsx_runtime_1.jsx)("small", { className: "mt-2", children: "Description:" }), (0, jsx_runtime_1.jsx)(editor_inline_1.MarkdownEditorInline, { value: group.qs.description }), (0, jsx_runtime_1.jsx)(RemoveGroupButton, { group: group })] }));
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Remove the group from the user's groups on all their devices, after one confirmation, and go
|
|
67
|
+
* back to Groups, which lists it under Removed groups to restore.
|
|
68
|
+
*/
|
|
69
|
+
const RemoveGroupButton = (props) => {
|
|
70
|
+
const { group } = props;
|
|
71
|
+
const [busy, setBusy] = (0, react_1.useState)(false);
|
|
72
|
+
const [error, setError] = (0, react_1.useState)("");
|
|
73
|
+
if (group.disabled) {
|
|
74
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-secondary mt-4", children: "This group is removed. Restore it from the Removed groups list on Groups." }));
|
|
75
|
+
}
|
|
76
|
+
async function remove() {
|
|
77
|
+
const name = group.name || "this group";
|
|
78
|
+
if (!window.confirm(`Remove ${name} from your groups on all your devices? Other members keep it, and you can restore it from Groups.`)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
setBusy(true);
|
|
82
|
+
setError("");
|
|
83
|
+
try {
|
|
84
|
+
await (0, peers_sdk_1.removeGroup)(await (0, peers_sdk_1.getUserContext)(), group.groupId);
|
|
85
|
+
(0, globals_1.mainContentPath)(identity_routes_1.IDENTITY_GROUPS_PATH);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
setError(err.message || "Could not remove the group.");
|
|
89
|
+
setBusy(false);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mt-4", children: [error ? (0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger", children: error }) : null, (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-danger btn-sm", disabled: busy, onClick: () => void remove(), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-x-circle me-1" }), busy ? "Removing…" : "Remove group"] }), (0, jsx_runtime_1.jsx)("div", { className: "small text-muted mt-1", children: "Hides it on all your devices. Other members keep it, and its data stays on your devices." })] }));
|
|
69
93
|
};
|
|
70
94
|
const GroupMembersWrapper = (props) => {
|
|
71
95
|
const userContext = (0, hooks_1.usePromise)(() => (0, peers_sdk_1.getUserContext)());
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { type GroupMemberRole, type IGroup } from "@peers-app/peers-sdk";
|
|
1
|
+
import { type GroupMemberRole, type IGroup, type UserContext } from "@peers-app/peers-sdk";
|
|
2
2
|
/** Search, summarize, and create groups owned by the signed-in user. */
|
|
3
3
|
export declare function GroupList(props?: {
|
|
4
4
|
creating?: boolean;
|
|
5
5
|
}): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
/** Groups the user removed, collapsed under the list, each with a Restore button. */
|
|
7
|
+
export declare function RemovedGroups(props: {
|
|
8
|
+
userContext: UserContext;
|
|
9
|
+
revision: number;
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
6
11
|
/** Data shown for one group in the Identity list. */
|
|
7
12
|
export interface IGroupSummary {
|
|
8
13
|
/** Signed group record. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupList = GroupList;
|
|
4
|
+
exports.RemovedGroups = RemovedGroups;
|
|
4
5
|
exports.GroupSummaryRow = GroupSummaryRow;
|
|
5
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
7
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
@@ -136,7 +137,52 @@ function GroupList(props = {}) {
|
|
|
136
137
|
void confirmCreate();
|
|
137
138
|
}, children: [(0, jsx_runtime_1.jsx)("input", { id: "new-group-name", className: "form-control", value: draftName, onChange: (event) => setDraftName(event.target.value), placeholder: "Group name", "aria-label": "Group name" }), (0, jsx_runtime_1.jsx)("button", { type: "submit", className: "btn btn-primary", disabled: !draftName.trim() || creatingBusy, children: creatingBusy ? "Creating…" : "Create" }), (0, jsx_runtime_1.jsx)("a", { href: `#${identity_routes_1.IDENTITY_GROUPS_PATH}`, className: "btn btn-outline-secondary", children: "Cancel" })] })] }) })) : null, (0, jsx_runtime_1.jsx)(activity_view_1.PendingWorkLink, { type: "group" }), (0, jsx_runtime_1.jsxs)("div", { className: "position-relative my-3", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-search position-absolute text-muted", style: { left: 12, top: "50%", transform: "translateY(-50%)" } }), (0, jsx_runtime_1.jsx)("input", { type: "search", className: "form-control ps-5", value: searchText, onChange: (event) => setSearchText(event.target.value), placeholder: "Search groups", "aria-label": "Search groups" })] }), error ? (0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger", children: error }) : null, !summaries && !error ? (0, jsx_runtime_1.jsx)(loading_indicator_1.LoadingIndicator, {}) : null, summaries && filtered.length === 0 ? ((0, jsx_runtime_1.jsxs)("div", { className: "border rounded p-4 text-center", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-people fs-2 text-muted" }), (0, jsx_runtime_1.jsx)("h6", { className: "mt-2", children: searchText ? "No matching groups" : "No groups yet" }), (0, jsx_runtime_1.jsx)("p", { className: "small text-muted", children: searchText
|
|
138
139
|
? "Try a different name or description."
|
|
139
|
-
: "Create a shared space or use an invite to join one." }), !searchText ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary btn-sm", onClick: startCreate, children: "Create your first group" })) : null] })) : null, filtered.length > 0 ? ((0, jsx_runtime_1.jsx)("div", { className: "list-group", children: filtered.map((summary) => ((0, jsx_runtime_1.jsx)(GroupSummaryRow, { summary: summary }, summary.group.groupId))) })) : null] }));
|
|
140
|
+
: "Create a shared space or use an invite to join one." }), !searchText ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary btn-sm", onClick: startCreate, children: "Create your first group" })) : null] })) : null, filtered.length > 0 ? ((0, jsx_runtime_1.jsx)("div", { className: "list-group", children: filtered.map((summary) => ((0, jsx_runtime_1.jsx)(GroupSummaryRow, { summary: summary }, summary.group.groupId))) })) : null, userContext ? (0, jsx_runtime_1.jsx)(RemovedGroups, { userContext: userContext, revision: groupRevision }) : null] }));
|
|
141
|
+
}
|
|
142
|
+
/** Groups the user removed, collapsed under the list, each with a Restore button. */
|
|
143
|
+
function RemovedGroups(props) {
|
|
144
|
+
const { userContext, revision } = props;
|
|
145
|
+
const [groups, setGroups] = (0, react_1.useState)([]);
|
|
146
|
+
const [restoringId, setRestoringId] = (0, react_1.useState)();
|
|
147
|
+
const [error, setError] = (0, react_1.useState)("");
|
|
148
|
+
(0, react_1.useEffect)(() => {
|
|
149
|
+
let disposed = false;
|
|
150
|
+
// `revision` changes when a Groups row does, so the list follows removes and restores.
|
|
151
|
+
void revision;
|
|
152
|
+
(0, peers_sdk_1.Groups)(userContext.userDataContext)
|
|
153
|
+
.list({ disabled: true })
|
|
154
|
+
.then((rows) => {
|
|
155
|
+
if (!disposed) {
|
|
156
|
+
setGroups(rows.sort((left, right) => left.name.localeCompare(right.name)));
|
|
157
|
+
setError("");
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
.catch((err) => {
|
|
161
|
+
if (!disposed) {
|
|
162
|
+
setError(err.message || "Could not load removed groups.");
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return () => {
|
|
166
|
+
disposed = true;
|
|
167
|
+
};
|
|
168
|
+
}, [userContext, revision]);
|
|
169
|
+
async function restore(groupId) {
|
|
170
|
+
setRestoringId(groupId);
|
|
171
|
+
setError("");
|
|
172
|
+
try {
|
|
173
|
+
await (0, peers_sdk_1.restoreGroup)(userContext, groupId);
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
setError(err.message || "Could not restore the group.");
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
setRestoringId(undefined);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!groups.length && !error) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
return ((0, jsx_runtime_1.jsxs)("details", { className: "mt-4", children: [(0, jsx_runtime_1.jsxs)("summary", { className: "small text-muted", children: ["Removed groups (", groups.length, ")"] }), error ? (0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger mt-2", children: error }) : null, (0, jsx_runtime_1.jsx)("div", { className: "list-group mt-2", children: groups.map((group) => ((0, jsx_runtime_1.jsxs)("div", { className: "list-group-item d-flex align-items-center gap-3", children: [(0, jsx_runtime_1.jsx)("i", { className: group.iconClassName || "bi bi-people-fill", "aria-hidden": "true" }), (0, jsx_runtime_1.jsxs)("span", { className: "flex-grow-1 overflow-hidden", children: [(0, jsx_runtime_1.jsx)("span", { className: "d-block text-truncate", children: group.name || "Unnamed group" }), (0, jsx_runtime_1.jsx)("span", { className: "small text-muted d-block text-truncate font-monospace", children: group.groupId })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary btn-sm", disabled: restoringId === group.groupId, onClick: () => void restore(group.groupId), children: restoringId === group.groupId ? "Restoring…" : "Restore" })] }, group.groupId))) })] }));
|
|
140
186
|
}
|
|
141
187
|
async function loadGroupSummaries(userContext) {
|
|
142
188
|
const groups = await (0, peers_sdk_1.Groups)(userContext.userDataContext).list({ disabled: { $ne: true } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "biome check --write ."
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@peers-app/peers-sdk": "^0.
|
|
39
|
+
"@peers-app/peers-sdk": "^0.32.1",
|
|
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.
|
|
50
|
+
"@peers-app/peers-sdk": "0.32.1",
|
|
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",
|