blixify-ui-web 1.3.0 → 1.3.2
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.
- package/lib/components/data/dataTemplate/activityModal.d.ts.map +1 -1
- package/lib/components/data/dataTemplate/activityModal.js +67 -10
- package/lib/components/data/dataTemplate/activityModal.js.map +1 -1
- package/lib/components/data/dataTemplate/activityPerson.d.ts +28 -0
- package/lib/components/data/dataTemplate/activityPerson.d.ts.map +1 -0
- package/lib/components/data/dataTemplate/activityPerson.js +227 -0
- package/lib/components/data/dataTemplate/activityPerson.js.map +1 -0
- package/lib/components/data/dataTemplate/activityViews.d.ts +62 -0
- package/lib/components/data/dataTemplate/activityViews.d.ts.map +1 -0
- package/lib/components/data/dataTemplate/activityViews.js +583 -0
- package/lib/components/data/dataTemplate/activityViews.js.map +1 -0
- package/lib/components/data/dataTemplate/dataStateModel.d.ts +23 -0
- package/lib/components/data/dataTemplate/dataStateModel.d.ts.map +1 -1
- package/lib/components/data/dataTemplate/dataStateModel.js.map +1 -1
- package/lib/components/data/dataTemplate/model.d.ts +2 -0
- package/lib/components/data/dataTemplate/model.d.ts.map +1 -1
- package/lib/tail.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activityPerson.js","sourceRoot":"","sources":["../../../../src/components/data/dataTemplate/activityPerson.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2D;AAC3D,uCAAyC;AACzC,mDAAkD;AAClD,yDAAuD;AAevD,IAAM,UAAU,GAAG,GAAG,CAAC;AACvB,8EAA8E;AAC9E,IAAM,WAAW,GAAG,QAAQ,CAAC;AAC7B,4EAA4E;AAC5E,IAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,2EAA2E;AAC3E,IAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,4EAA4E;AAC5E,2DAA2D;AAC3D,IAAM,cAAc,GAAG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AE,eAAe,EAC7B,YAAY,EAAE,gBAAgB,EAC9B,OAAO,EAAE,UAAC,KAAK;gBACb,KAAK,CAAC,eAAe,EAAE,CAAC;gBACxB,YAAY,EAAE,CAAC;YACjB,CAAC,EACD,SAAS,EAAE,UAAC,KAAK;gBACf,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG;oBAAE,OAAO;gBACvD,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,KAAK,CAAC,eAAe,EAAE,CAAC;gBACxB,YAAY,EAAE,CAAC;YACjB,CAAC,IAEA,KAAK,CAAC,QAAQ,CACV;QACN,UAAU,EAAE,CACZ,CACJ,CAAC;AACJ,CAAC,CAAC;AArKW,QAAA,kBAAkB,sBAqK7B"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ActivityView } from "./dataStateModel";
|
|
3
|
+
import { DevSettings } from "./model";
|
|
4
|
+
export declare const VIEW_VISIBLE_RATIO = 0.5;
|
|
5
|
+
export declare const VIEW_DWELL_MS = 1000;
|
|
6
|
+
export declare const VIEW_FLUSH_MS = 2000;
|
|
7
|
+
/**
|
|
8
|
+
* Whether an observed comment is "on screen": half of it is visible, or, for a
|
|
9
|
+
* comment taller than twice the view (many photos), it fills half the view —
|
|
10
|
+
* a ratio of its own height alone could never be reached.
|
|
11
|
+
*/
|
|
12
|
+
export declare const handleIsOnScreen: (entry: {
|
|
13
|
+
intersectionRatio: number;
|
|
14
|
+
intersectionRect?: {
|
|
15
|
+
height: number;
|
|
16
|
+
};
|
|
17
|
+
rootBounds?: {
|
|
18
|
+
height: number;
|
|
19
|
+
} | null;
|
|
20
|
+
}) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* One document per comment and person. The id says both, so seeing a comment
|
|
23
|
+
* again is the same document and never a second view.
|
|
24
|
+
*/
|
|
25
|
+
export declare const handleViewId: (commentId: string, userId: string) => string;
|
|
26
|
+
/** The people who saw a comment, newest first, never its author. */
|
|
27
|
+
export declare const handleListViewers: (views: ActivityView[], authorId?: string | null) => ActivityView[];
|
|
28
|
+
interface HookOptions {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
devSettings: DevSettings;
|
|
31
|
+
viewCollectionId?: string;
|
|
32
|
+
collectionId: string;
|
|
33
|
+
currentUserId?: string;
|
|
34
|
+
itemId?: string;
|
|
35
|
+
commentIds: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface SeenComment {
|
|
38
|
+
id: string;
|
|
39
|
+
itemId: string | null;
|
|
40
|
+
authorId?: string | null;
|
|
41
|
+
}
|
|
42
|
+
/** The views of a page's comments, read in one list, and the saving of the current person's. */
|
|
43
|
+
export declare const useActivityViews: (options: HookOptions) => {
|
|
44
|
+
byComment: Record<string, ActivityView[]>;
|
|
45
|
+
handleSeen: (comment: SeenComment) => void;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Calls onSeen once a watched element has been at least half on screen for
|
|
49
|
+
* VIEW_DWELL_MS while the page is in the foreground. Works inside any scroll
|
|
50
|
+
* container (drawer, modal, the app's WebView), not only the window.
|
|
51
|
+
*/
|
|
52
|
+
export declare const useSeenObserver: (enabled: boolean, onSeen: (key: string) => void) => (key: string) => (element: Element | null) => void;
|
|
53
|
+
interface SeenByProps {
|
|
54
|
+
viewers: ActivityView[];
|
|
55
|
+
authorName: (id?: string) => string;
|
|
56
|
+
authorImage?: (id?: string) => string | undefined;
|
|
57
|
+
darkMode?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** The eye and count under a comment, opening who saw it and when. */
|
|
60
|
+
export declare const ActivitySeenBy: (props: SeenByProps) => React.JSX.Element | null;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=activityViews.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activityViews.d.ts","sourceRoot":"","sources":["../../../../src/components/data/dataTemplate/activityViews.tsx"],"names":[],"mappings":"AAAA,OAAO,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M,KAAK,IAAI,WAqEH,MAAM,eA9DJ,OAAO,GAAG,IAAI,KAAK,IAqFhD,CAAC;AAEF,UAAU,WAAW;IACnB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,UAAU,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,sEAAsE;AACtE,eAAO,MAAM,cAAc,UAAW,WAAW,6BAiIhD,CAAC"}
|
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
+
switch (op[0]) {
|
|
55
|
+
case 0: case 1: t = op; break;
|
|
56
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
+
default:
|
|
60
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
+
if (t[2]) _.ops.pop();
|
|
65
|
+
_.trys.pop(); continue;
|
|
66
|
+
}
|
|
67
|
+
op = body.call(thisArg, _);
|
|
68
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
73
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
74
|
+
if (ar || !(i in from)) {
|
|
75
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
76
|
+
ar[i] = from[i];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
80
|
+
};
|
|
81
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
82
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
83
|
+
};
|
|
84
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
85
|
+
exports.ActivitySeenBy = exports.useSeenObserver = exports.useActivityViews = exports.handleListViewers = exports.handleViewId = exports.handleIsOnScreen = exports.VIEW_FLUSH_MS = exports.VIEW_DWELL_MS = exports.VIEW_VISIBLE_RATIO = void 0;
|
|
86
|
+
var react_1 = __importStar(require("react"));
|
|
87
|
+
var react_dom_1 = require("react-dom");
|
|
88
|
+
var axios_1 = __importDefault(require("axios"));
|
|
89
|
+
var dayjs_1 = __importDefault(require("dayjs"));
|
|
90
|
+
var outline_1 = require("@heroicons/react/24/outline");
|
|
91
|
+
var readQuery_1 = require("../readQuery");
|
|
92
|
+
var writeQuery_1 = require("../writeQuery");
|
|
93
|
+
var utils_1 = require("../utils");
|
|
94
|
+
var activityAvatar_1 = require("./activityAvatar");
|
|
95
|
+
var activityReactions_1 = require("./activityReactions");
|
|
96
|
+
// INFO: half the comment on screen for a second, so scrolling past is not seeing it
|
|
97
|
+
exports.VIEW_VISIBLE_RATIO = 0.5;
|
|
98
|
+
exports.VIEW_DWELL_MS = 1000;
|
|
99
|
+
// INFO: seen comments are saved together a moment later, not one request per scroll step
|
|
100
|
+
exports.VIEW_FLUSH_MS = 2000;
|
|
101
|
+
var VIEW_LIST_LIMIT = 2000;
|
|
102
|
+
var SEEN_BY_WIDTH = 288;
|
|
103
|
+
// INFO: drawn on the body like the reaction pop-ups, above the Drawer and Modal
|
|
104
|
+
var POPUP_LAYER = "z-[60]";
|
|
105
|
+
/**
|
|
106
|
+
* Whether an observed comment is "on screen": half of it is visible, or, for a
|
|
107
|
+
* comment taller than twice the view (many photos), it fills half the view —
|
|
108
|
+
* a ratio of its own height alone could never be reached.
|
|
109
|
+
*/
|
|
110
|
+
var handleIsOnScreen = function (entry) {
|
|
111
|
+
var _a, _b, _c;
|
|
112
|
+
if (entry.intersectionRatio >= exports.VIEW_VISIBLE_RATIO)
|
|
113
|
+
return true;
|
|
114
|
+
var view = ((_a = entry.rootBounds) === null || _a === void 0 ? void 0 : _a.height) ||
|
|
115
|
+
(typeof window !== "undefined" ? window.innerHeight : 0);
|
|
116
|
+
return (!!view && ((_c = (_b = entry.intersectionRect) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 0) >= view * exports.VIEW_VISIBLE_RATIO);
|
|
117
|
+
};
|
|
118
|
+
exports.handleIsOnScreen = handleIsOnScreen;
|
|
119
|
+
/**
|
|
120
|
+
* One document per comment and person. The id says both, so seeing a comment
|
|
121
|
+
* again is the same document and never a second view.
|
|
122
|
+
*/
|
|
123
|
+
var handleViewId = function (commentId, userId) {
|
|
124
|
+
return "".concat(commentId, ":").concat(userId);
|
|
125
|
+
};
|
|
126
|
+
exports.handleViewId = handleViewId;
|
|
127
|
+
/** The people who saw a comment, newest first, never its author. */
|
|
128
|
+
var handleListViewers = function (views, authorId) {
|
|
129
|
+
var time = function (view) {
|
|
130
|
+
return new Date(view.viewedAt).getTime() || 0;
|
|
131
|
+
};
|
|
132
|
+
var latest = new Map();
|
|
133
|
+
views.forEach(function (view) {
|
|
134
|
+
if (!view.userId || view.userId === authorId)
|
|
135
|
+
return;
|
|
136
|
+
var known = latest.get(view.userId);
|
|
137
|
+
if (!known || time(view) > time(known))
|
|
138
|
+
latest.set(view.userId, view);
|
|
139
|
+
});
|
|
140
|
+
return Array.from(latest.values()).sort(function (a, b) { return time(b) - time(a); });
|
|
141
|
+
};
|
|
142
|
+
exports.handleListViewers = handleListViewers;
|
|
143
|
+
// INFO: ids a query asks for; the "in" limit of Firestore, which a backend may
|
|
144
|
+
// sit on whatever server type the panel is told
|
|
145
|
+
var VIEW_IDS_PER_QUERY = 30;
|
|
146
|
+
// INFO: a save that keeps failing with no answer, or a server fault, is given up
|
|
147
|
+
var VIEW_SAVE_ATTEMPTS = 3;
|
|
148
|
+
/** The views of a page's comments, read in one list, and the saving of the current person's. */
|
|
149
|
+
var useActivityViews = function (options) {
|
|
150
|
+
var _a = (0, react_1.useState)({}), byComment = _a[0], setByComment = _a[1];
|
|
151
|
+
var latest = (0, react_1.useRef)(0);
|
|
152
|
+
var mounted = (0, react_1.useRef)(true);
|
|
153
|
+
// INFO: the latest settings, so a save retried later (back online, or the
|
|
154
|
+
// panel closing) carries the sign-in renewed since, not the first one
|
|
155
|
+
var current = (0, react_1.useRef)(options);
|
|
156
|
+
current.current = options;
|
|
157
|
+
// INFO: views waiting to be saved, with how often each was tried
|
|
158
|
+
var queue = (0, react_1.useRef)(new Map());
|
|
159
|
+
var recorded = (0, react_1.useRef)(new Set());
|
|
160
|
+
// INFO: comments seen before the reader's own views were read; held so a
|
|
161
|
+
// view already saved is not sent again with a new time
|
|
162
|
+
var loaded = (0, react_1.useRef)(false);
|
|
163
|
+
var early = (0, react_1.useRef)([]);
|
|
164
|
+
var flushTimer = (0, react_1.useRef)(null);
|
|
165
|
+
var flushing = (0, react_1.useRef)(false);
|
|
166
|
+
var devSettings = options.devSettings;
|
|
167
|
+
var idsKey = JSON.stringify(Array.from(new Set(options.commentIds)).sort());
|
|
168
|
+
var handleLoad = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
169
|
+
var ids, request, query_1, chunks, index, results, grouped_1, err_1, held;
|
|
170
|
+
return __generator(this, function (_a) {
|
|
171
|
+
switch (_a.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
ids = JSON.parse(idsKey);
|
|
174
|
+
request = ++latest.current;
|
|
175
|
+
if (!options.enabled || !options.viewCollectionId || !ids.length) {
|
|
176
|
+
setByComment({});
|
|
177
|
+
return [2 /*return*/];
|
|
178
|
+
}
|
|
179
|
+
_a.label = 1;
|
|
180
|
+
case 1:
|
|
181
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
182
|
+
query_1 = new readQuery_1.ReadQuery({
|
|
183
|
+
dbModule: axios_1.default,
|
|
184
|
+
dbType: devSettings.server,
|
|
185
|
+
dbCollection: options.viewCollectionId,
|
|
186
|
+
dbEndpoint: devSettings.dbEndpoint,
|
|
187
|
+
dbAPIToken: devSettings.dbAPIToken,
|
|
188
|
+
dbUserToken: devSettings.dbUserToken,
|
|
189
|
+
});
|
|
190
|
+
chunks = [];
|
|
191
|
+
for (index = 0; index < ids.length; index += VIEW_IDS_PER_QUERY)
|
|
192
|
+
chunks.push(ids.slice(index, index + VIEW_IDS_PER_QUERY));
|
|
193
|
+
return [4 /*yield*/, Promise.all(chunks.map(function (chunk) {
|
|
194
|
+
return query_1.call({
|
|
195
|
+
type: "list",
|
|
196
|
+
query: __spreadArray(__spreadArray([
|
|
197
|
+
{
|
|
198
|
+
type: "=",
|
|
199
|
+
queryId: "collectionId",
|
|
200
|
+
value: options.collectionId,
|
|
201
|
+
}
|
|
202
|
+
], (options.itemId
|
|
203
|
+
? [
|
|
204
|
+
{
|
|
205
|
+
type: "=",
|
|
206
|
+
queryId: "itemId",
|
|
207
|
+
value: options.itemId,
|
|
208
|
+
},
|
|
209
|
+
]
|
|
210
|
+
: []), true), [
|
|
211
|
+
{ type: "in", queryId: "commentId", value: chunk },
|
|
212
|
+
], false),
|
|
213
|
+
sort: { sortId: "createdAt", type: "desc" },
|
|
214
|
+
limit: VIEW_LIST_LIMIT,
|
|
215
|
+
});
|
|
216
|
+
}))];
|
|
217
|
+
case 2:
|
|
218
|
+
results = _a.sent();
|
|
219
|
+
// INFO: a later request (the page changed) wins over a slower earlier one
|
|
220
|
+
if (!mounted.current || request !== latest.current)
|
|
221
|
+
return [2 /*return*/];
|
|
222
|
+
grouped_1 = {};
|
|
223
|
+
results
|
|
224
|
+
.flatMap(function (result) {
|
|
225
|
+
return Array.isArray(result === null || result === void 0 ? void 0 : result.data) ? result.data : [];
|
|
226
|
+
})
|
|
227
|
+
.forEach(function (row) {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
var commentId = String((_a = row === null || row === void 0 ? void 0 : row.commentId) !== null && _a !== void 0 ? _a : "");
|
|
230
|
+
if (ids.includes(commentId))
|
|
231
|
+
((_b = grouped_1[commentId]) !== null && _b !== void 0 ? _b : (grouped_1[commentId] = [])).push(row);
|
|
232
|
+
if ((row === null || row === void 0 ? void 0 : row.userId) === options.currentUserId)
|
|
233
|
+
recorded.current.add(commentId);
|
|
234
|
+
});
|
|
235
|
+
// INFO: a view saved here but not yet listed by the backend stays shown
|
|
236
|
+
queue.current.forEach(function (_a) {
|
|
237
|
+
var _b;
|
|
238
|
+
var _c;
|
|
239
|
+
var view = _a.view;
|
|
240
|
+
if (ids.includes(view.commentId))
|
|
241
|
+
((_b = grouped_1[_c = view.commentId]) !== null && _b !== void 0 ? _b : (grouped_1[_c] = [])).push(view);
|
|
242
|
+
});
|
|
243
|
+
setByComment(grouped_1);
|
|
244
|
+
return [3 /*break*/, 5];
|
|
245
|
+
case 3:
|
|
246
|
+
err_1 = _a.sent();
|
|
247
|
+
// INFO: views are extra; a failed read leaves the comments as they are
|
|
248
|
+
if (mounted.current && request === latest.current)
|
|
249
|
+
setByComment({});
|
|
250
|
+
return [3 /*break*/, 5];
|
|
251
|
+
case 4:
|
|
252
|
+
if (mounted.current && request === latest.current) {
|
|
253
|
+
loaded.current = true;
|
|
254
|
+
held = early.current;
|
|
255
|
+
early.current = [];
|
|
256
|
+
held.forEach(function (comment) { return handleSeen(comment); });
|
|
257
|
+
}
|
|
258
|
+
return [7 /*endfinally*/];
|
|
259
|
+
case 5: return [2 /*return*/];
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}); }, [
|
|
263
|
+
idsKey,
|
|
264
|
+
options.enabled,
|
|
265
|
+
options.viewCollectionId,
|
|
266
|
+
options.collectionId,
|
|
267
|
+
options.currentUserId,
|
|
268
|
+
options.itemId,
|
|
269
|
+
devSettings.server,
|
|
270
|
+
devSettings.dbEndpoint,
|
|
271
|
+
devSettings.dbAPIToken,
|
|
272
|
+
devSettings.dbUserToken,
|
|
273
|
+
]);
|
|
274
|
+
/* eslint-enable */
|
|
275
|
+
var handleScheduleFlush = function () {
|
|
276
|
+
if (flushTimer.current || !queue.current.size)
|
|
277
|
+
return;
|
|
278
|
+
flushTimer.current = setTimeout(handleFlush, exports.VIEW_FLUSH_MS);
|
|
279
|
+
};
|
|
280
|
+
var handleFlush = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
281
|
+
var settings, query, offline, _i, _a, _b, id, entry, result, err_2, status_1;
|
|
282
|
+
var _c;
|
|
283
|
+
var _d, _e;
|
|
284
|
+
return __generator(this, function (_f) {
|
|
285
|
+
switch (_f.label) {
|
|
286
|
+
case 0:
|
|
287
|
+
flushTimer.current = null;
|
|
288
|
+
settings = current.current;
|
|
289
|
+
if (!settings.viewCollectionId)
|
|
290
|
+
return [2 /*return*/];
|
|
291
|
+
// INFO: a flush still running picks this one up when it ends
|
|
292
|
+
if (flushing.current)
|
|
293
|
+
return [2 /*return*/];
|
|
294
|
+
flushing.current = true;
|
|
295
|
+
query = new writeQuery_1.WriteQuery({
|
|
296
|
+
dbModule: axios_1.default,
|
|
297
|
+
dbType: settings.devSettings.server,
|
|
298
|
+
dbCollection: settings.viewCollectionId,
|
|
299
|
+
dbEndpoint: settings.devSettings.dbEndpoint,
|
|
300
|
+
dbAPIToken: settings.devSettings.dbAPIToken,
|
|
301
|
+
dbUserToken: settings.devSettings.dbUserToken,
|
|
302
|
+
});
|
|
303
|
+
offline = false;
|
|
304
|
+
_f.label = 1;
|
|
305
|
+
case 1:
|
|
306
|
+
_f.trys.push([1, , 8, 9]);
|
|
307
|
+
_i = 0, _a = Array.from(queue.current.entries());
|
|
308
|
+
_f.label = 2;
|
|
309
|
+
case 2:
|
|
310
|
+
if (!(_i < _a.length)) return [3 /*break*/, 7];
|
|
311
|
+
_b = _a[_i], id = _b[0], entry = _b[1];
|
|
312
|
+
_f.label = 3;
|
|
313
|
+
case 3:
|
|
314
|
+
_f.trys.push([3, 5, , 6]);
|
|
315
|
+
return [4 /*yield*/, query.call("create", {
|
|
316
|
+
id: id,
|
|
317
|
+
data: __assign((_c = {}, _c[(0, utils_1.parseServerId)(settings.devSettings.server)] = id, _c), entry.view),
|
|
318
|
+
})];
|
|
319
|
+
case 4:
|
|
320
|
+
result = _f.sent();
|
|
321
|
+
if (result === false)
|
|
322
|
+
throw new Error("View was not saved");
|
|
323
|
+
queue.current.delete(id);
|
|
324
|
+
return [3 /*break*/, 6];
|
|
325
|
+
case 5:
|
|
326
|
+
err_2 = _f.sent();
|
|
327
|
+
status_1 = Number((_e = (_d = err_2 === null || err_2 === void 0 ? void 0 : err_2.response) === null || _d === void 0 ? void 0 : _d.status) !== null && _e !== void 0 ? _e : 0);
|
|
328
|
+
// INFO: offline: everything waits for the online event
|
|
329
|
+
if (!status_1 && !navigator.onLine) {
|
|
330
|
+
offline = true;
|
|
331
|
+
return [3 /*break*/, 7];
|
|
332
|
+
}
|
|
333
|
+
// INFO: refused (already saved from another tab, or not allowed) is final
|
|
334
|
+
if (status_1 >= 400 && status_1 < 500) {
|
|
335
|
+
queue.current.delete(id);
|
|
336
|
+
return [3 /*break*/, 6];
|
|
337
|
+
}
|
|
338
|
+
// INFO: no answer or a server fault is tried again, a few times
|
|
339
|
+
entry.tries += 1;
|
|
340
|
+
if (entry.tries >= VIEW_SAVE_ATTEMPTS)
|
|
341
|
+
queue.current.delete(id);
|
|
342
|
+
return [3 /*break*/, 6];
|
|
343
|
+
case 6:
|
|
344
|
+
_i++;
|
|
345
|
+
return [3 /*break*/, 2];
|
|
346
|
+
case 7: return [3 /*break*/, 9];
|
|
347
|
+
case 8:
|
|
348
|
+
flushing.current = false;
|
|
349
|
+
if (!offline && queue.current.size)
|
|
350
|
+
handleScheduleFlush();
|
|
351
|
+
return [7 /*endfinally*/];
|
|
352
|
+
case 9: return [2 /*return*/];
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}); };
|
|
356
|
+
/** Records that the current person saw a comment: once, and never their own. */
|
|
357
|
+
var handleSeen = function (comment) {
|
|
358
|
+
var userId = current.current.currentUserId;
|
|
359
|
+
var settings = current.current;
|
|
360
|
+
if (!settings.enabled || !settings.viewCollectionId || !userId)
|
|
361
|
+
return;
|
|
362
|
+
if (!comment.id || comment.authorId === userId)
|
|
363
|
+
return;
|
|
364
|
+
if (!loaded.current) {
|
|
365
|
+
early.current.push(comment);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (recorded.current.has(comment.id))
|
|
369
|
+
return;
|
|
370
|
+
recorded.current.add(comment.id);
|
|
371
|
+
var id = (0, exports.handleViewId)(comment.id, userId);
|
|
372
|
+
var now = new Date();
|
|
373
|
+
var view = {
|
|
374
|
+
commentId: comment.id,
|
|
375
|
+
userId: userId,
|
|
376
|
+
collectionId: settings.collectionId,
|
|
377
|
+
itemId: comment.itemId,
|
|
378
|
+
viewedAt: now,
|
|
379
|
+
createdAt: now,
|
|
380
|
+
};
|
|
381
|
+
queue.current.set(id, { view: view, tries: 0 });
|
|
382
|
+
setByComment(function (previous) {
|
|
383
|
+
var _a;
|
|
384
|
+
var _b;
|
|
385
|
+
return (__assign(__assign({}, previous), (_a = {}, _a[comment.id] = __spreadArray(__spreadArray([], ((_b = previous[comment.id]) !== null && _b !== void 0 ? _b : []), true), [view], false), _a)));
|
|
386
|
+
});
|
|
387
|
+
handleScheduleFlush();
|
|
388
|
+
};
|
|
389
|
+
(0, react_1.useEffect)(function () {
|
|
390
|
+
mounted.current = true;
|
|
391
|
+
var handleOnline = function () { return handleScheduleFlush(); };
|
|
392
|
+
window.addEventListener("online", handleOnline);
|
|
393
|
+
return function () {
|
|
394
|
+
mounted.current = false;
|
|
395
|
+
window.removeEventListener("online", handleOnline);
|
|
396
|
+
if (flushTimer.current)
|
|
397
|
+
clearTimeout(flushTimer.current);
|
|
398
|
+
// INFO: what was seen before the panel closed is still saved
|
|
399
|
+
if (queue.current.size)
|
|
400
|
+
handleFlush();
|
|
401
|
+
};
|
|
402
|
+
/* eslint-disable-next-line */
|
|
403
|
+
}, []);
|
|
404
|
+
(0, react_1.useEffect)(function () {
|
|
405
|
+
handleLoad();
|
|
406
|
+
}, [handleLoad]);
|
|
407
|
+
return { byComment: byComment, handleSeen: handleSeen };
|
|
408
|
+
};
|
|
409
|
+
exports.useActivityViews = useActivityViews;
|
|
410
|
+
/**
|
|
411
|
+
* Calls onSeen once a watched element has been at least half on screen for
|
|
412
|
+
* VIEW_DWELL_MS while the page is in the foreground. Works inside any scroll
|
|
413
|
+
* container (drawer, modal, the app's WebView), not only the window.
|
|
414
|
+
*/
|
|
415
|
+
var useSeenObserver = function (enabled, onSeen) {
|
|
416
|
+
var observer = (0, react_1.useRef)(null);
|
|
417
|
+
var keys = (0, react_1.useRef)(new Map());
|
|
418
|
+
var visible = (0, react_1.useRef)(new Set());
|
|
419
|
+
var timers = (0, react_1.useRef)(new Map());
|
|
420
|
+
var callbacks = (0, react_1.useRef)(new Map());
|
|
421
|
+
var seen = (0, react_1.useRef)(onSeen);
|
|
422
|
+
seen.current = onSeen;
|
|
423
|
+
var handleStop = function (element) {
|
|
424
|
+
var timer = timers.current.get(element);
|
|
425
|
+
if (timer)
|
|
426
|
+
clearTimeout(timer);
|
|
427
|
+
timers.current.delete(element);
|
|
428
|
+
};
|
|
429
|
+
var handleStart = function (element) {
|
|
430
|
+
if (timers.current.has(element) || document.visibilityState !== "visible")
|
|
431
|
+
return;
|
|
432
|
+
timers.current.set(element, setTimeout(function () {
|
|
433
|
+
var _a;
|
|
434
|
+
timers.current.delete(element);
|
|
435
|
+
var key = keys.current.get(element);
|
|
436
|
+
if (!key || !visible.current.has(element))
|
|
437
|
+
return;
|
|
438
|
+
seen.current(key);
|
|
439
|
+
(_a = observer.current) === null || _a === void 0 ? void 0 : _a.unobserve(element);
|
|
440
|
+
visible.current.delete(element);
|
|
441
|
+
}, exports.VIEW_DWELL_MS));
|
|
442
|
+
};
|
|
443
|
+
(0, react_1.useEffect)(function () {
|
|
444
|
+
if (!enabled || typeof IntersectionObserver === "undefined")
|
|
445
|
+
return;
|
|
446
|
+
observer.current = new IntersectionObserver(function (entries) {
|
|
447
|
+
return entries.forEach(function (entry) {
|
|
448
|
+
if ((0, exports.handleIsOnScreen)(entry)) {
|
|
449
|
+
visible.current.add(entry.target);
|
|
450
|
+
handleStart(entry.target);
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
visible.current.delete(entry.target);
|
|
454
|
+
handleStop(entry.target);
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
},
|
|
458
|
+
// INFO: finer steps, so a tall comment filling the view is noticed as it scrolls
|
|
459
|
+
{ threshold: [0, 0.1, 0.2, 0.3, 0.4, exports.VIEW_VISIBLE_RATIO, 0.75, 1] });
|
|
460
|
+
keys.current.forEach(function (_, element) { var _a; return (_a = observer.current) === null || _a === void 0 ? void 0 : _a.observe(element); });
|
|
461
|
+
// INFO: a hidden tab or a backgrounded app pauses the count; back in front,
|
|
462
|
+
// what is still on screen starts again
|
|
463
|
+
var handleVisibility = function () {
|
|
464
|
+
if (document.visibilityState === "visible")
|
|
465
|
+
visible.current.forEach(handleStart);
|
|
466
|
+
else
|
|
467
|
+
Array.from(timers.current.keys()).forEach(handleStop);
|
|
468
|
+
};
|
|
469
|
+
document.addEventListener("visibilitychange", handleVisibility);
|
|
470
|
+
return function () {
|
|
471
|
+
var _a;
|
|
472
|
+
document.removeEventListener("visibilitychange", handleVisibility);
|
|
473
|
+
(_a = observer.current) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
474
|
+
observer.current = null;
|
|
475
|
+
Array.from(timers.current.keys()).forEach(handleStop);
|
|
476
|
+
visible.current.clear();
|
|
477
|
+
};
|
|
478
|
+
/* eslint-disable-next-line */
|
|
479
|
+
}, [enabled]);
|
|
480
|
+
/** A stable ref callback per key, so a re-render does not observe again. */
|
|
481
|
+
var handleWatch = function (key) {
|
|
482
|
+
var callback = callbacks.current.get(key);
|
|
483
|
+
if (!callback) {
|
|
484
|
+
var current_1 = null;
|
|
485
|
+
callback = function (element) {
|
|
486
|
+
var _a, _b;
|
|
487
|
+
if (current_1) {
|
|
488
|
+
(_a = observer.current) === null || _a === void 0 ? void 0 : _a.unobserve(current_1);
|
|
489
|
+
keys.current.delete(current_1);
|
|
490
|
+
visible.current.delete(current_1);
|
|
491
|
+
handleStop(current_1);
|
|
492
|
+
}
|
|
493
|
+
current_1 = element;
|
|
494
|
+
if (element) {
|
|
495
|
+
keys.current.set(element, key);
|
|
496
|
+
(_b = observer.current) === null || _b === void 0 ? void 0 : _b.observe(element);
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
callbacks.current.set(key, callback);
|
|
500
|
+
}
|
|
501
|
+
return callback;
|
|
502
|
+
};
|
|
503
|
+
return handleWatch;
|
|
504
|
+
};
|
|
505
|
+
exports.useSeenObserver = useSeenObserver;
|
|
506
|
+
/** The eye and count under a comment, opening who saw it and when. */
|
|
507
|
+
var ActivitySeenBy = function (props) {
|
|
508
|
+
var _a = (0, react_1.useState)(null), rect = _a[0], setRect = _a[1];
|
|
509
|
+
var buttonRef = (0, react_1.useRef)(null);
|
|
510
|
+
var panelRef = (0, react_1.useRef)(null);
|
|
511
|
+
var muted = props.darkMode ? "text-gray-400" : "text-gray-500";
|
|
512
|
+
var divider = props.darkMode ? "border-gray-700" : "border-gray-100";
|
|
513
|
+
(0, react_1.useEffect)(function () {
|
|
514
|
+
if (!rect)
|
|
515
|
+
return;
|
|
516
|
+
var handleOutside = function (event) {
|
|
517
|
+
var _a, _b;
|
|
518
|
+
var target = event.target;
|
|
519
|
+
if (!((_a = panelRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) &&
|
|
520
|
+
!((_b = buttonRef.current) === null || _b === void 0 ? void 0 : _b.contains(target)))
|
|
521
|
+
setRect(null);
|
|
522
|
+
};
|
|
523
|
+
var handleKey = function (event) {
|
|
524
|
+
if (event.key === "Escape") {
|
|
525
|
+
event.stopPropagation();
|
|
526
|
+
setRect(null);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
// INFO: fixed against the button, so a scroll outside the list closes it
|
|
530
|
+
var handleScroll = function (event) {
|
|
531
|
+
var _a;
|
|
532
|
+
if (!((_a = panelRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target)))
|
|
533
|
+
setRect(null);
|
|
534
|
+
};
|
|
535
|
+
document.addEventListener("mousedown", handleOutside, true);
|
|
536
|
+
document.addEventListener("touchstart", handleOutside, true);
|
|
537
|
+
document.addEventListener("keydown", handleKey, true);
|
|
538
|
+
window.addEventListener("scroll", handleScroll, true);
|
|
539
|
+
return function () {
|
|
540
|
+
document.removeEventListener("mousedown", handleOutside, true);
|
|
541
|
+
document.removeEventListener("touchstart", handleOutside, true);
|
|
542
|
+
document.removeEventListener("keydown", handleKey, true);
|
|
543
|
+
window.removeEventListener("scroll", handleScroll, true);
|
|
544
|
+
};
|
|
545
|
+
}, [rect]);
|
|
546
|
+
if (!props.viewers.length)
|
|
547
|
+
return null;
|
|
548
|
+
var count = props.viewers.length;
|
|
549
|
+
var renderPanel = function () {
|
|
550
|
+
return rect &&
|
|
551
|
+
(0, react_dom_1.createPortal)(react_1.default.createElement("div", { ref: panelRef, role: "dialog", "aria-label": "Seen by", "data-testid": "seen-by-details", onClick: function (event) { return event.stopPropagation(); }, className: "fixed ".concat(POPUP_LAYER, " overflow-y-auto rounded-md shadow-lg ring-1 focus:outline-none ").concat(props.darkMode ? "bg-gray-800 text-white ring-gray-700" : "bg-white ring-black ring-opacity-5"), style: __assign({ width: SEEN_BY_WIDTH, maxWidth: "calc(100vw - 3rem)" }, (0, activityReactions_1.handlePlacePopup)(rect, SEEN_BY_WIDTH, {
|
|
552
|
+
width: window.innerWidth,
|
|
553
|
+
height: window.innerHeight,
|
|
554
|
+
})) },
|
|
555
|
+
react_1.default.createElement("div", { className: "p-3 text-left text-sm" },
|
|
556
|
+
react_1.default.createElement("div", { className: "mb-3 border-b pb-2 ".concat(divider) },
|
|
557
|
+
react_1.default.createElement("p", { className: "flex items-center gap-2 font-semibold" },
|
|
558
|
+
react_1.default.createElement(outline_1.EyeIcon, { "aria-hidden": "true", className: "h-4 w-4 ".concat(muted) }),
|
|
559
|
+
"Seen by"),
|
|
560
|
+
react_1.default.createElement("p", { className: "mt-1 text-xs ".concat(muted) },
|
|
561
|
+
count,
|
|
562
|
+
" ",
|
|
563
|
+
count === 1 ? "person" : "people")),
|
|
564
|
+
react_1.default.createElement("ul", { className: "space-y-2" }, props.viewers.map(function (view) {
|
|
565
|
+
var _a;
|
|
566
|
+
var when = (0, dayjs_1.default)(view.viewedAt);
|
|
567
|
+
return (react_1.default.createElement("li", { key: view.userId, "data-testid": "seen-by-person", className: "flex min-w-0 items-center gap-2" },
|
|
568
|
+
react_1.default.createElement(activityAvatar_1.ActivityAvatar, { id: view.userId, name: props.authorName(view.userId), image: (_a = props.authorImage) === null || _a === void 0 ? void 0 : _a.call(props, view.userId), className: "h-6 w-6 shrink-0 text-[10px]", darkMode: props.darkMode }),
|
|
569
|
+
react_1.default.createElement("span", { className: "min-w-0 flex-1 truncate" }, props.authorName(view.userId)),
|
|
570
|
+
when.isValid() && (react_1.default.createElement("time", { className: "shrink-0 text-xs ".concat(muted), dateTime: when.toISOString(), title: when.format("YYYY-MM-DD HH:mm:ss") }, when.format("D MMM, HH:mm")))));
|
|
571
|
+
})))), document.body);
|
|
572
|
+
};
|
|
573
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
574
|
+
react_1.default.createElement("button", { ref: buttonRef, type: "button", "aria-label": "Seen by ".concat(count, " ").concat(count === 1 ? "person" : "people"), "aria-expanded": !!rect, "data-testid": "seen-by", onClick: function (event) {
|
|
575
|
+
event.stopPropagation();
|
|
576
|
+
setRect(function (open) { var _a, _b; return open ? null : ((_b = (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) !== null && _b !== void 0 ? _b : null); });
|
|
577
|
+
}, className: "inline-flex items-center gap-1 hover:underline" },
|
|
578
|
+
react_1.default.createElement(outline_1.EyeIcon, { "aria-hidden": "true", className: "h-4 w-4" }),
|
|
579
|
+
count),
|
|
580
|
+
renderPanel()));
|
|
581
|
+
};
|
|
582
|
+
exports.ActivitySeenBy = ActivitySeenBy;
|
|
583
|
+
//# sourceMappingURL=activityViews.js.map
|