cautpartener / client / src / app / views / activities.ts
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
/**
 * Activities UI (P1): the "Activități" section of the feed tab, the activity
 * card (title, time range, location, organizer, going-list, Join/Leave,
 * cancelled badge, organizer edit/cancel), the create/edit composer
 * (datetime-local pickers, visibility: Public / contacts-only / group) and
 * the detail sheet (full description, attendee list, share permalink).
 *
 * Restricted activities: the TITLE stays public (the discoverable shell);
 * desc/loc are sealed for the chosen group — members render them with the
 * audience badge, everyone else gets the honest lock chip. Joins are PUBLIC
 * metadata either way (stated on the card).
 *
 * All wire strings render through text nodes (XSS-safe).
 */

import { ALL_CONTACTS_GID, activeGroups, clampName } from "../../core/contacts";
import { Session } from "../../core/session";
import {
  publishActivity,
  type ActivityInput,
  type FeedActivity,
  type FeedHandle,
  type FeedView,
} from "../../public/feed-service";
import { cachedProfile } from "../../public/profile-service";
import { ACT_DESC_MAX, ACT_LOC_MAX, ACT_TITLE_MAX, ACT_TS_MAX } from "../../public/public-doc";
import { dateLocales, t } from "../i18n";
import { h, sheet, toast } from "../ui-kit";
import { fpSpan } from "./contacts-tab";

const ACT_BASE = "https://cautpartener.ro/#/a/";
/** Attendees rendered in the detail sheet; beyond it, an honest "+N" count. */
const GOING_RENDER_CAP = 100;
/** Attendee avatars shown inline on the card. */
const GOING_AVATARS = 5;

export interface ActCardHooks {
  /** Re-render whatever list holds this card from the handle's LOCAL state. */
  refresh: () => void;
  /**
   * Re-replay from the mailbox, then re-render — needed after edit/cancel
   * (publishActivity deposits but does not mutate the open handle's fold).
   * Falls back to `refresh` when absent.
   */
  remoteRefresh?: () => void;
}

// ---- helpers --------------------------------------------------------------------

/** Contacts-first display name for a pub (profile cache fallback), or null. */
function displayName(pub: string): string | null {
  const c = Session.contacts?.state.contacts.get(pub);
  if (c && c.status === "active" && c.name) return c.name;
  const cached = cachedProfile(pub);
  return cached ? clampName(cached.profile.name) || null : null;
}

/** RO/HU/EN time-range label via Intl.DateTimeFormat (no date library). */
export function fmtRange(start: number, end: number): string {
  const locale = dateLocales();
  const s = new Date(start);
  const e = new Date(end);
  const thisYear = new Date().getFullYear();
  const withYear = s.getFullYear() !== thisYear || e.getFullYear() !== thisYear;
  const dFmt = new Intl.DateTimeFormat(locale, {
    weekday: "short",
    day: "numeric",
    month: "short",
    ...(withYear ? { year: "numeric" } : {}),
  });
  const tFmt = new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit" });
  return s.toDateString() === e.toDateString()
    ? `${dFmt.format(s)}, ${tFmt.format(s)} – ${tFmt.format(e)}`
    : `${dFmt.format(s)}, ${tFmt.format(s)} → ${dFmt.format(e)}, ${tFmt.format(e)}`;
}

/** ms → the local "YYYY-MM-DDTHH:MM" form <input type="datetime-local"> takes. */
function toLocalInput(ms: number): string {
  const d = new Date(ms);
  const p = (n: number): string => String(n).padStart(2, "0");
  return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}T${p(d.getHours())}:${p(d.getMinutes())}`;
}

/** In-app hash route of one activity permalink. */
export function activityHash(shard: string, org: string, aid: string): string {
  return `#/a/${encodeURIComponent(shard)}/${org}/${aid}`;
}

/** Shareable permalink of one activity (resolved by walking the shard's rooms). */
export function activityLink(shard: string, org: string, aid: string): string {
  return `${ACT_BASE}${encodeURIComponent(shard)}/${org}/${aid}`;
}

/** My own gid behind a gidHint (owner-local knowledge), or null. */
function gidForHint(gidHint: string): string | null {
  for (const k of Session.selfroom?.state.gkeys.values() ?? []) {
    if (k.hint === gidHint) return k.gid;
  }
  return null;
}

function multiline(text: string, cls: string, testid: string): HTMLElement {
  const el = h("p", { class: cls, "data-testid": testid });
  text.split("\n").forEach((line, i) => {
    if (i > 0) el.append(h("br"));
    el.append(document.createTextNode(line));
  });
  return el;
}

// ---- the card -------------------------------------------------------------------

/** One activity card. Exported for the feed tab and the permalink view. */
export function activityCard(handle: FeedHandle, act: FeedActivity, hooks: ActCardHooks): HTMLElement {
  const card = h("article", {
    class: "act-card",
    "data-testid": "act-card",
    "data-aid": act.aid,
    "data-org": act.org,
    "data-seq": String(act.seq),
  });

  // ---- organizer header ----
  const avatar = h("div", { class: "feed-avatar" }, fpSpan(act.org, "fp-small"));
  const orgName = displayName(act.org);
  const nameEl = h(
    "a",
    { class: "feed-author", href: `#/u/${act.org}`, "data-testid": "act-organizer" },
    orgName ?? `${act.org.slice(0, 10)}…`,
  );
  const cachedAv = cachedProfile(act.org)?.avatarUrl;
  if (cachedAv) avatar.replaceChildren(h("img", { src: cachedAv, alt: "" }));
  card.append(
    h(
      "header",
      { class: "feed-head" },
      avatar,
      h("div", { class: "feed-head-main" }, nameEl, h("span", { class: "muted feed-time" }, t("actOrganizer"))),
      fpSpan(act.org, "fp-small feed-head-fp"),
    ),
  );

  // ---- title + status badges ----
  const titleRow = h("div", { class: "act-title-row" }, h("h3", { class: "act-title", "data-testid": "act-title" }, act.title));
  if (act.cancelled) titleRow.append(h("span", { class: "chip act-badge-cancelled", "data-testid": "act-cancelled" }, t("actCancelledBadge")));
  card.append(titleRow);

  // ---- when / where ----
  card.append(h("p", { class: "act-when", "data-testid": "act-when" }, `📅 ${fmtRange(act.start, act.end)}`));
  if (act.loc) card.append(h("p", { class: "act-where", "data-testid": "act-where" }, `📍 ${act.loc}`));

  // ---- audience restriction ----
  if (act.restricted?.locked) {
    card.append(h("div", { class: "feed-locked", "data-testid": "act-locked" }, `🔒 ${t("actLockedNote")}`));
  } else if (act.restricted) {
    card.append(
      h(
        "div",
        { class: "chip-row feed-aud-row" },
        h(
          "span",
          { class: "chip chip-strong", "data-testid": "act-aud-badge" },
          `🔓 ${act.restricted.label ?? t("audVisibleToYou")}`,
        ),
      ),
    );
  }
  if (act.restricted) {
    card.append(h("p", { class: "muted small-note feed-aud-note", "data-testid": "act-join-note" }, t("actJoinPublicNote")));
  }

  // ---- description (unsealed for members / own; clamped, tap to expand) ----
  if (act.desc) {
    const descEl = multiline(act.desc, "feed-caption clamped act-desc", "act-desc");
    if (act.desc.length > 140 || act.desc.includes("\n")) {
      descEl.addEventListener("click", () => descEl.classList.toggle("clamped"));
    }
    card.append(descEl);
  }

  // ---- going row + join/leave ----
  const goingRow = h("div", { class: "act-going-row" });
  const avatars = h("div", { class: "act-going-avatars" });
  for (const pub of act.going.slice(0, GOING_AVATARS)) avatars.append(fpSpan(pub, "fp-small act-going-fp"));
  goingRow.append(
    avatars,
    h(
      "button",
      {
        type: "button",
        class: "act-going-count-btn",
        "data-testid": "act-going-count",
        "data-n": String(act.going.length),
        onclick: () => openDetailSheet(handle, act, hooks),
      },
      act.going.length > 0 ? t("actGoingCount", { n: act.going.length }) : t("actGoingNone"),
    ),
  );
  card.append(goingRow);

  const actions = h("div", { class: "feed-actions act-actions" });
  const expired = act.end < Date.now();
  let joining = false;
  const setStatus = (status: "going" | "out", btn: HTMLButtonElement): void => {
    if (joining) return;
    if (!Session.identity) {
      toast(t("upNoIdentity"));
      return;
    }
    joining = true;
    btn.disabled = true;
    void handle
      .joinActivity(act.org, act.aid, status)
      .then((r) => {
        if (r.ok) hooks.refresh();
        else toast(t("actJoinFailed"));
      })
      .catch(() => toast(t("actJoinFailed")))
      .finally(() => {
        joining = false;
        btn.disabled = false;
      });
  };
  if (act.myStatus === "going") {
    const leaveBtn = h("button", { type: "button", class: "btn ghost small", "data-testid": "act-leave" }, t("actLeave")) as HTMLButtonElement;
    leaveBtn.addEventListener("click", () => setStatus("out", leaveBtn));
    actions.append(leaveBtn);
  } else if (!act.cancelled && !expired && !act.own) {
    const joinBtn = h("button", { type: "button", class: "btn small", "data-testid": "act-join" }, t("actJoin")) as HTMLButtonElement;
    joinBtn.addEventListener("click", () => setStatus("going", joinBtn));
    actions.append(joinBtn);
  }

  const shareBtn = h(
    "button",
    {
      type: "button",
      class: "btn ghost small",
      "data-testid": "act-share",
      title: t("actShare"),
      onclick: () => {
        void navigator.clipboard?.writeText(activityLink(act.shard, act.org, act.aid)).then(
          () => toast(t("linkCopied")),
          () => toast(t("copyFailed")),
        );
      },
    },
    t("actShare"),
  );
  actions.append(shareBtn);

  if (act.own && !act.cancelled) {
    actions.append(
      h(
        "button",
        {
          type: "button",
          class: "btn ghost small",
          "data-testid": "act-edit",
          onclick: () => openActivityComposer(act.shard, act, hooks.remoteRefresh ?? hooks.refresh),
        },
        t("actEdit"),
      ),
      h(
        "button",
        {
          type: "button",
          class: "btn ghost small danger-ghost",
          "data-testid": "act-cancel",
          onclick: () => openCancelSheet(act, hooks),
        },
        t("actCancelAct"),
      ),
    );
  }
  card.append(actions);

  return card;
}

// ---- cancel confirmation --------------------------------------------------------

function openCancelSheet(act: FeedActivity, hooks: ActCardHooks): void {
  const yes = h("button", { type: "button", class: "btn danger", "data-testid": "act-cancel-yes" }, t("actCancelYes")) as HTMLButtonElement;
  const no = h("button", { type: "button", class: "btn ghost" }, t("cancel"));
  const body = h(
    "div",
    { "data-testid": "act-cancel-sheet" },
    h("h2", { class: "sheet-title" }, t("actCancelAct")),
    h("p", {}, t("actCancelConfirm", { title: act.title })),
    h("div", { class: "btn-row" }, no, yes),
  );
  const s = sheet(body);
  no.addEventListener("click", () => s.close());
  yes.addEventListener("click", () => {
    yes.disabled = true;
    const input = buildInput(act, { cancelled: true });
    if (!input) {
      toast(t("actPublishFailed"));
      s.close();
      return;
    }
    void publishActivity(input)
      .then((r) => {
        if (r.ok) {
          toast(t("actCancelledToast"));
          s.close();
          (hooks.remoteRefresh ?? hooks.refresh)();
        } else {
          toast(t("actPublishFailed"));
          yes.disabled = false;
        }
      })
      .catch(() => {
        toast(t("actPublishFailed"));
        yes.disabled = false;
      });
  });
}

/** Re-publish input for an OWN activity (edit/cancel): same aid, seq bump. */
function buildInput(act: FeedActivity, patch: Partial<ActivityInput>): ActivityInput | null {
  let aud: { gid: string } | undefined;
  if (act.restricted) {
    const gid = gidForHint(act.restricted.gidHint);
    if (!gid) return null; // not the owner (or key lost) — cannot re-seal
    aud = { gid };
  }
  return {
    shard: act.shard,
    title: act.title,
    desc: act.desc,
    start: act.start,
    end: act.end,
    ...(act.loc ? { loc: act.loc } : {}),
    aid: act.aid,
    prevSeq: act.seq,
    ...(act.cancelled ? { cancelled: true } : {}),
    ...(aud ? { aud } : {}),
    replacesCid: act.cidStr,
    ...patch,
  };
}

// ---- detail sheet ---------------------------------------------------------------

function openDetailSheet(handle: FeedHandle, act: FeedActivity, hooks: ActCardHooks): void {
  const fresh = handle.activity(act.org, act.aid) ?? act;
  const body = h(
    "div",
    { "data-testid": "act-detail" },
    h("h2", { class: "sheet-title" }, fresh.title),
    h("p", { class: "act-when" }, `📅 ${fmtRange(fresh.start, fresh.end)}`),
    fresh.loc ? h("p", { class: "act-where" }, `📍 ${fresh.loc}`) : null,
    fresh.cancelled ? h("p", { class: "chip act-badge-cancelled" }, t("actCancelledBadge")) : null,
    fresh.desc ? multiline(fresh.desc, "act-desc-full", "act-detail-desc") : null,
    fresh.restricted?.locked ? h("p", { class: "feed-locked" }, `🔒 ${t("actLockedNote")}`) : null,
    h("h3", { class: "act-going-title" }, `${t("actDetailGoing")} (${fresh.going.length})`),
  );
  const list = h("div", { class: "act-going-list", "data-testid": "act-going-list" });
  if (fresh.going.length === 0) {
    list.append(h("p", { class: "muted empty-note" }, t("actGoingNone")));
  }
  for (const pub of fresh.going.slice(0, GOING_RENDER_CAP)) {
    const name = displayName(pub);
    list.append(
      h(
        "div",
        { class: "act-going-item", "data-testid": "act-going-item", "data-pub": pub },
        fpSpan(pub, "fp-small"),
        h("a", { class: name ? "act-going-name" : "mono act-going-name", href: `#/u/${pub}` }, name ?? `${pub.slice(0, 10)}…`),
      ),
    );
  }
  if (fresh.going.length > GOING_RENDER_CAP) {
    list.append(
      h("p", { class: "muted small-note", "data-testid": "act-going-more" }, t("actGoingMore", { n: fresh.going.length - GOING_RENDER_CAP })),
    );
  }
  body.append(list);
  if (fresh.restricted) body.append(h("p", { class: "muted small-note" }, t("actJoinPublicNote")));
  sheet(body);
  void hooks; // joins happen on the card; the sheet is read-only
}

// ---- composer (create + edit) ---------------------------------------------------

const CONTACTS_VALUE = "__contacts__";

export function openActivityComposer(shard: string, existing: FeedActivity | null, onDone: () => void): void {
  if (!Session.identity) {
    toast(t("upNoIdentity"));
    return;
  }
  const titleIn = h("input", {
    type: "text",
    class: "text-input",
    maxlength: ACT_TITLE_MAX,
    placeholder: t("actTitlePh"),
    value: existing?.title ?? "",
    "data-testid": "act-title-input",
  }) as HTMLInputElement;
  const descIn = h("textarea", {
    class: "seed-input",
    rows: 3,
    maxlength: ACT_DESC_MAX,
    placeholder: t("actDescPh"),
    "data-testid": "act-desc-input",
  }) as HTMLTextAreaElement;
  if (existing) descIn.value = existing.desc;
  const now = Date.now();
  const defStart = existing?.start ?? now + 3_600_000 - (now % 3_600_000) + 3_600_000; // next full hour + 1 h
  const defEnd = existing?.end ?? defStart + 2 * 3_600_000;
  // max = the §3 receiver ceiling (year 2100) — publishActivity re-validates
  const maxLocal = toLocalInput(ACT_TS_MAX);
  const startIn = h("input", { type: "datetime-local", class: "text-input", value: toLocalInput(defStart), max: maxLocal, "data-testid": "act-start" }) as HTMLInputElement;
  const endIn = h("input", { type: "datetime-local", class: "text-input", value: toLocalInput(defEnd), max: maxLocal, "data-testid": "act-end" }) as HTMLInputElement;
  const locIn = h("input", {
    type: "text",
    class: "text-input",
    maxlength: ACT_LOC_MAX,
    placeholder: t("actLocPh"),
    value: existing?.loc ?? "",
    "data-testid": "act-loc",
  }) as HTMLInputElement;

  // visibility: Public / contacts-only (implicit auto-group) / one of MY groups
  const visSel = h("select", { class: "text-input", "data-testid": "act-vis" }) as HTMLSelectElement;
  visSel.append(h("option", { value: "" }, t("actVisPublic")));
  visSel.append(h("option", { value: CONTACTS_VALUE }, t("actVisContacts")));
  const groups = Session.selfroom ? activeGroups(Session.selfroom.state) : [];
  for (const g of groups) {
    if (g.gid === ALL_CONTACTS_GID) continue; // the dedicated option above
    visSel.append(h("option", { value: g.gid }, g.name));
  }
  if (existing?.restricted) {
    const gid = gidForHint(existing.restricted.gidHint);
    if (gid) visSel.value = gid === ALL_CONTACTS_GID ? CONTACTS_VALUE : gid;
  }
  const visNote = h("p", { class: "muted small-note", "data-testid": "act-vis-note" });
  const updateVisNote = (): void => {
    const v = visSel.value;
    visNote.textContent = v === "" ? "" : v === CONTACTS_VALUE ? `${t("actAudNote")} ${t("actContactsNote")}` : t("actAudNote");
    visNote.style.display = v === "" ? "none" : "";
  };
  visSel.addEventListener("change", updateVisNote);
  updateVisNote();

  const publishBtn = h(
    "button",
    { type: "button", class: "btn", "data-testid": "act-publish" },
    existing ? t("actSave") : t("actPublish"),
  ) as HTMLButtonElement;
  const cancelBtn = h("button", { type: "button", class: "btn ghost" }, t("cancel"));
  const body = h(
    "div",
    { "data-testid": "act-compose-sheet" },
    h("h2", { class: "sheet-title" }, existing ? t("actEditTitle") : t("actCompose")),
    h("label", { class: "field-label" }, t("actTitleLabel")),
    titleIn,
    h("label", { class: "field-label" }, t("actDescLabel")),
    descIn,
    h("label", { class: "field-label" }, t("actStartLabel")),
    startIn,
    h("label", { class: "field-label" }, t("actEndLabel")),
    endIn,
    h("label", { class: "field-label" }, t("actLocLabel")),
    locIn,
    h("label", { class: "field-label" }, t("actVisLabel")),
    visSel,
    visNote,
    h("div", { class: "btn-row spaced-top" }, cancelBtn, publishBtn),
  );
  const s = sheet(body);
  cancelBtn.addEventListener("click", () => s.close());

  publishBtn.addEventListener("click", () => {
    // Editing a RESTRICTED activity whose gid this device cannot resolve
    // (not the owner's key, or the key was lost): BLOCK the save — mirrors
    // buildInput's null → cancel-path toast. Falling through would silently
    // republish the activity as public/empty, leaking the fact of the edit
    // and dropping the restriction the author chose.
    if (existing?.restricted && !gidForHint(existing.restricted.gidHint)) {
      toast(t("actPublishFailed"));
      return;
    }
    const start = startIn.value ? new Date(startIn.value).getTime() : NaN;
    const end = endIn.value ? new Date(endIn.value).getTime() : NaN;
    if (!titleIn.value.trim() || !Number.isFinite(start) || !Number.isFinite(end) || start >= end || end <= Date.now()) {
      toast(t("actPublishInvalid"));
      return;
    }
    publishBtn.disabled = true;
    void (async () => {
      let aud: { gid: string } | undefined;
      if (visSel.value === CONTACTS_VALUE) {
        if (!Session.contacts) throw new Error("offline");
        aud = { gid: await Session.contacts.ensureAllContactsGroup() };
      } else if (visSel.value) {
        aud = { gid: visSel.value };
      }
      const input: ActivityInput = {
        shard,
        title: titleIn.value,
        desc: descIn.value,
        start,
        end,
        ...(locIn.value.trim() ? { loc: locIn.value } : {}),
        ...(existing ? { aid: existing.aid, prevSeq: existing.seq, replacesCid: existing.cidStr } : {}),
        ...(aud ? { aud } : {}),
      };
      const r = await publishActivity(input);
      if (r.ok) {
        toast(existing ? t("actSaved") : t("actPublished"));
        s.close();
        onDone();
      } else if (r.reason === "invalid") {
        toast(t("actPublishInvalid"));
        publishBtn.disabled = false;
      } else {
        toast(t("actPublishFailed"));
        publishBtn.disabled = false;
      }
    })().catch(() => {
      toast(t("actPublishFailed"));
      publishBtn.disabled = false;
    });
  });
}

// ---- the feed-tab section -------------------------------------------------------

/** Rendered activity cards per chunk (posts-style RENDER_CAP): a Sybil flood
 * of organizers can grow the MODEL, but never blow up the DOM in one pass —
 * further cards render only on explicit "load more" taps. */
const ACT_RENDER_CAP = 100;

/** Render the activities list of one shard view into `listBox`. */
export function renderActivitiesList(listBox: HTMLElement, handle: FeedHandle, view: FeedView, hooks: ActCardHooks): void {
  listBox.replaceChildren();
  if (view.activities.length === 0) {
    listBox.append(h("p", { class: "muted empty-note", "data-testid": "act-empty" }, t("actEmpty")));
    return;
  }
  const appendChunk = (from: number, anchor: HTMLElement | null): void => {
    const frag = document.createDocumentFragment();
    for (const act of view.activities.slice(from, from + ACT_RENDER_CAP)) {
      frag.append(activityCard(handle, act, hooks));
    }
    const next = from + ACT_RENDER_CAP;
    if (view.activities.length > next) {
      const more = h(
        "button",
        { type: "button", class: "btn ghost small act-load-more", "data-testid": "act-load-more" },
        t("actLoadMore"),
      ) as HTMLButtonElement;
      more.addEventListener("click", () => appendChunk(next, more));
      frag.append(more);
    }
    if (anchor) anchor.replaceWith(frag);
    else listBox.append(frag);
  };
  appendChunk(0, null);
}

static mirror of HEAD · about · clone: git clone https://cod-sursa.cautpartener.ro/cautpartener.git