@mundogamernetwork/shared-ui 1.18.2 → 1.19.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.
@@ -0,0 +1,124 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Host of the "Novidades" history: the side drawer and the announcement dialog reopened from it. Mounted once by
4
+ * <MgHeaderComponent /> (outside the user dropdown, which unmounts when it closes) so both survive the menu.
5
+ * Also loads the unread number for the badge, once per login identity.
6
+ *
7
+ * Off with `mgSharedUi.whatsNew.history: false` (or `whatsNew.enabled: false`); the backend decides the content.
8
+ */
9
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
10
+ import { storeToRefs } from "pinia";
11
+ import type { WnHistoryItem } from "../../utils/whatsNew";
12
+
13
+ const store = useWhatsNewStore();
14
+ const authStore = useAuthStore();
15
+ const { user, signedIn } = storeToRefs(authStore);
16
+ const router = useRouter();
17
+
18
+ const i18nLocale = (() => {
19
+ try {
20
+ return useI18n().locale;
21
+ } catch {
22
+ return ref("en");
23
+ }
24
+ })();
25
+ const localePath: ((p: string) => string) | null = (() => {
26
+ try {
27
+ return useLocalePath() as any;
28
+ } catch {
29
+ return null;
30
+ }
31
+ })();
32
+
33
+ const shared: any = useRuntimeConfig().public.mgSharedUi ?? {};
34
+ const cfg: any = shared.whatsNew ?? {};
35
+ // Same two values the store needs to call the API: without them there is nothing to open, so no entry is offered.
36
+ const configured = !!(shared.networkBaseUrl || import.meta.env.VITE_BASE_URL_NETWORK) && !!(shared.systemId || import.meta.env.VITE_SYSTEM_ID);
37
+ const enabled = cfg.enabled !== false && cfg.history !== false && configured;
38
+ const uiLocale = computed(() => i18nLocale.value || "en");
39
+ const identity = computed(() => (signedIn.value ? String(user.value?.uuid ?? user.value?.id ?? "user") : null));
40
+
41
+ const hostId = Math.random().toString(36).slice(2, 10);
42
+ // Only the first mounted host renders: a layout switch (or two layouts) must never open two drawers.
43
+ const isOwner = computed(() => store.hosts[0] === hostId);
44
+
45
+ onMounted(() => {
46
+ if (!enabled) return;
47
+ store.registerHost(hostId);
48
+ if (identity.value) store.fetchUnread(identity.value);
49
+ });
50
+
51
+ onBeforeUnmount(() => {
52
+ store.unregisterHost(hostId);
53
+ });
54
+
55
+ watch(identity, (id) => {
56
+ if (!enabled) return;
57
+ if (id) store.fetchUnread(id);
58
+ else store.resetHistory();
59
+ });
60
+
61
+ /** In-app path → final route, or null when this front has no such route (the link then renders as text). */
62
+ function resolveInternal(path: string): string | null {
63
+ if (!path.startsWith("/") || path.startsWith("//")) return null;
64
+ const target = localePath ? localePath(path) : path;
65
+ try {
66
+ const resolved = router.resolve(target);
67
+ const real = resolved.matched.some((m) => !/\(\.\*\)|:pathMatch|\*\*/.test(m.path));
68
+ return real ? target : null;
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+
74
+ function onOpen(item: WnHistoryItem) {
75
+ void store.openItem(item, uiLocale.value);
76
+ }
77
+
78
+ // ── the reopened announcement (same dialog as the modal) ───────────────────
79
+ function onCta() {
80
+ if (store.viewing) store.trackFor(store.viewing, "cta_click");
81
+ store.closeViewing();
82
+ }
83
+
84
+ function onNavigate(path: string) {
85
+ // A link click is neither "seen" nor "dismissed": get out of the way and go.
86
+ store.closeViewing(false);
87
+ store.closeDrawer();
88
+ router.push(path);
89
+ }
90
+
91
+ function onLink(target: string) {
92
+ if (store.viewing) store.trackFor(store.viewing, "link_click", target);
93
+ }
94
+
95
+ function onVideoPlay() {
96
+ if (store.viewing) store.trackFor(store.viewing, "video_play");
97
+ }
98
+ </script>
99
+
100
+ <template>
101
+ <ClientOnly>
102
+ <Teleport to="body">
103
+ <MgWhatsNewDrawer
104
+ v-if="enabled && signedIn && isOwner && store.drawerOpen"
105
+ :locale="uiLocale"
106
+ @close="store.closeDrawer()"
107
+ @open="onOpen"
108
+ @more="store.loadMoreHistory(uiLocale)"
109
+ @retry="store.fetchHistory(uiLocale, 1)"
110
+ />
111
+ <MgWhatsNewDialog
112
+ v-if="enabled && signedIn && isOwner && store.viewing"
113
+ :post="store.viewing"
114
+ :locale="uiLocale"
115
+ :resolve-internal="resolveInternal"
116
+ @close="store.closeViewing()"
117
+ @cta="onCta"
118
+ @navigate="onNavigate"
119
+ @link="onLink"
120
+ @video-play="onVideoPlay"
121
+ />
122
+ </Teleport>
123
+ </ClientOnly>
124
+ </template>
@@ -0,0 +1,92 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * "Novidades" entry of the user menu: opens the history drawer and shows how many announcements the
4
+ * user has not seen yet. The drawer itself lives in <MgWhatsNewHistory /> (mounted by the header, outside the
5
+ * dropdown, so it survives the menu closing).
6
+ */
7
+ import { computed } from "vue";
8
+ import { formatBadge } from "../../utils/whatsNew";
9
+ import { wnText } from "../../utils/whatsNewText";
10
+
11
+ const emit = defineEmits<{ (e: "opened"): void }>();
12
+
13
+ const store = useWhatsNewStore();
14
+ const { locale } = useI18n();
15
+
16
+ const badge = computed(() => formatBadge(store.unread));
17
+ const label = computed(() => {
18
+ const base = wnText(locale.value, "menu_title");
19
+ return store.unread > 0 ? `${base}, ${store.unread} ${wnText(locale.value, "history_unread")}` : base;
20
+ });
21
+
22
+ function open() {
23
+ void store.openDrawer(locale.value);
24
+ emit("opened");
25
+ }
26
+ </script>
27
+
28
+ <template>
29
+ <button type="button" class="mg-wn-menu-item" :aria-label="label" aria-haspopup="dialog" @click="open">
30
+ <span class="mg-wn-menu-item__icon" aria-hidden="true">
31
+ <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="square">
32
+ <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9L12 3z" />
33
+ <path d="M19 16l.8 2.2L22 19l-2.2.8L19 22l-.8-2.2L16 19l2.2-.8L19 16z" />
34
+ </svg>
35
+ </span>
36
+ <span class="mg-wn-menu-item__label">{{ wnText(locale, "menu_title") }}</span>
37
+ <span v-if="badge" class="mg-wn-menu-item__badge" aria-hidden="true">{{ badge }}</span>
38
+ </button>
39
+ </template>
40
+
41
+ <style lang="scss" scoped>
42
+ .mg-wn-menu-item {
43
+ display: flex;
44
+ align-items: center;
45
+ gap: 8px;
46
+ width: 100%;
47
+ padding: 6px 0;
48
+ font: inherit;
49
+ font-size: 0.8125rem;
50
+ text-align: start;
51
+ color: var(--secondary-info-fg, var(--inactive));
52
+ background: transparent;
53
+ border: 0;
54
+ cursor: pointer;
55
+
56
+ &:hover,
57
+ &:focus-visible {
58
+ color: var(--active);
59
+ }
60
+
61
+ &:focus-visible {
62
+ outline: 2px solid var(--mg-wn-accent);
63
+ outline-offset: 2px;
64
+ }
65
+
66
+ &__icon {
67
+ display: inline-flex;
68
+ flex: none;
69
+ }
70
+
71
+ &__label {
72
+ flex: 1;
73
+ min-width: 0;
74
+ }
75
+
76
+ &__badge {
77
+ flex: none;
78
+ min-width: 20px;
79
+ height: 20px;
80
+ padding: 0 6px;
81
+ display: inline-flex;
82
+ align-items: center;
83
+ justify-content: center;
84
+ font-size: 0.6875rem;
85
+ font-weight: 700;
86
+ line-height: 1;
87
+ color: var(--mg-wn-on-accent);
88
+ background: var(--mg-wn-accent);
89
+ border-radius: 0;
90
+ }
91
+ }
92
+ </style>
package/error.vue CHANGED
@@ -12,7 +12,7 @@ interface CustomError {
12
12
  }
13
13
 
14
14
  const error = useError();
15
- const statusCodeError = Number((error.value as CustomError)?.statusCode) || 404;
15
+ const statusCodeError = Number((error.value as unknown as CustomError)?.statusCode) || 404;
16
16
 
17
17
  // Do NOT call getUser() on error page — causes infinite loop when API is down or token expired
18
18
 
package/nuxt.config.ts CHANGED
@@ -141,6 +141,8 @@ export default defineNuxtConfig({
141
141
  agencyBaseUrl: "", // VITE_BASE_URL_AGENCY — used for "create your press kit" CTA link
142
142
  accountsBaseUrl: "", // VITE_BASE_ACCOUNTS_URL
143
143
  networkBaseUrl: "", // VITE_BASE_URL_NETWORK (institutional APIs)
144
+ communityApiUrl: "", // VITE_BASE_URL_COMMUNITY (community API)
145
+ communitySiteUrl: "", // VITE_BASE_URL_COMMUNITY_FRONT (community frontend)
144
146
  // Per-platform pricing/plans page. Left empty, the account menu's
145
147
  // "Plans & Pricing" link is hidden — set it per front (e.g.
146
148
  // `${localePath}/pricing`) since each front's plans page lives at a
@@ -158,8 +160,8 @@ export default defineNuxtConfig({
158
160
  gamification: true,
159
161
  },
160
162
  // Presence: pings the API every couple of minutes while a signed-in user has a tab open, so the admin can
161
- // show who is online and who stopped coming back. Off until a front opts in (the front's API must run the
162
- // api-main version that buffers the heartbeat). Env: NUXT_PUBLIC_MG_SHARED_UI_PRESENCE_ENABLED=true.
163
+ // show who is online and who stopped coming back. Off until a front opts in; the platform is the front's VITE_SYSTEM_ID.
164
+ // Turn on, no rebuild needed: NUXT_PUBLIC_MG_SHARED_UI_PRESENCE_ENABLED=true.
163
165
  presence: {
164
166
  enabled: false,
165
167
  intervalSeconds: 120, // never below 60
@@ -170,6 +172,8 @@ export default defineNuxtConfig({
170
172
  // (login, signup, checkout, payment, create/publish/upload...).
171
173
  whatsNew: {
172
174
  enabled: true,
175
+ // "Novidades" entry in the user menu + side drawer with the past announcements (needs a signed-in user).
176
+ history: true,
173
177
  allowedRoutes: [] as string[],
174
178
  blockedRoutes: [] as string[],
175
179
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mundogamernetwork/shared-ui",
3
- "version": "1.18.2",
3
+ "version": "1.19.1",
4
4
  "description": "Mundo Gamer Network - Shared UI Layer (Nuxt 3)",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -69,7 +69,7 @@
69
69
  <FormAppSelect
70
70
  id="keyCampaignsPlatformFilter"
71
71
  :model="activePlatformFilter ?? ''"
72
- @update:model="(val) => setPlatformFilter(val ? Number(val) : null)"
72
+ @update:model="(val: string | number) => setPlatformFilter(val ? Number(val) : null)"
73
73
  :label="$t('keys.campaigns.all')"
74
74
  :options="platformList.map((p) => [p.id, platformAbbr(p.name)])"
75
75
  />
@@ -88,7 +88,7 @@ onMounted(async () => {
88
88
  fetchKeyRegions(keyId),
89
89
  fetchAvailableOptions(keyId).catch(() => null),
90
90
  ])
91
- campaign.value = campaignRes?.data?.data || campaignRes?.data || null
91
+ campaign.value = (campaignRes as any)?.data?.data || (campaignRes as any)?.data || null
92
92
  const allPlatforms = platformsRes?.data?.data || platformsRes?.data || []
93
93
  const allRegions = regionsRes?.data?.data || regionsRes?.data || []
94
94
 
@@ -158,7 +158,7 @@ const flipbookPages = computed<PageData[]>(() => {
158
158
  page,
159
159
  flipbookCode: magazine.value.data?.flipbook_code,
160
160
  }),
161
- }));
161
+ })) as PageData[];
162
162
  });
163
163
 
164
164
  // Determine if lead capture modal should show
@@ -134,13 +134,13 @@ export function mgApiUrl(endpoint: string, usePrefix = true) {
134
134
  case "login":
135
135
  case "logout":
136
136
  case "register":
137
- return [apiBaseURL, usePrefix ? locale : "", endpoint]
137
+ return ([apiBaseURL, usePrefix ? locale : "", endpoint] as string[])
138
138
  .filter((v) => v)
139
139
  .map((part) => part.replace(/^\//, ""))
140
140
  .map((part) => part.replace(/\/api\/v1$/, ""))
141
141
  .join("/");
142
142
  default:
143
- return [apiBaseURL, usePrefix ? locale : "", endpoint]
143
+ return ([apiBaseURL, usePrefix ? locale : "", endpoint] as string[])
144
144
  .filter((v) => v)
145
145
  .map((part) => part.replace(/^\//, ""))
146
146
  .join("/");
@@ -31,7 +31,7 @@ export const complexSerialize = function (obj: SerializeObject): string {
31
31
  if (typeof value === "object" && value !== null) {
32
32
  appendObject(`${baseKey}[${key}]`, value);
33
33
  } else {
34
- searchParams.append(`${baseKey}[${key}]`, value.toString());
34
+ searchParams.append(`${baseKey}[${key}]`, String(value));
35
35
  }
36
36
  });
37
37
  };
@@ -1,16 +1,21 @@
1
1
  import { defineStore } from "pinia";
2
2
  import {
3
+ WN_HISTORY_PAGE,
3
4
  WN_MAX_BATCH,
4
5
  chunkEvents,
5
6
  newDeviceId,
6
7
  toApiLang,
7
8
  type WnEventName,
9
+ type WnHistoryItem,
10
+ type WnHistoryMeta,
8
11
  type WnPost,
9
12
  type WnReceiptEvent,
10
13
  } from "../utils/whatsNew";
11
14
 
12
15
  const DEVICE_KEY = "mg_wn_device_id";
13
16
  const LAST_SHOWN_KEY = "mg_wn_last_shown_at";
17
+ /** The list in the drawer is reloaded when it is older than this on open. */
18
+ const HISTORY_STALE_MS = 60_000;
14
19
 
15
20
  function readStorage(key: string): string | null {
16
21
  try {
@@ -59,6 +64,25 @@ export const useWhatsNewStore = defineStore("whats-new-store", {
59
64
  loading: false,
60
65
  shownThisSession: false,
61
66
  open: false,
67
+ // ── history (menu entry + side drawer) ──
68
+ unread: 0,
69
+ unreadFor: null as string | null,
70
+ drawerOpen: false,
71
+ // <MgWhatsNewHistory /> is mounted: the menu entry only shows when something can open the drawer.
72
+ hostMounted: false,
73
+ // ids of the mounted hosts, first = the one that renders the drawer (a layout switch can briefly mount two)
74
+ hosts: [] as string[],
75
+ // language the list was last loaded in, so a silent refresh can reload it the same way
76
+ historyLocale: "" as string,
77
+ history: [] as WnHistoryItem[],
78
+ historyMeta: null as WnHistoryMeta | null,
79
+ historyStatus: "idle" as "idle" | "loading" | "loadingMore" | "error",
80
+ historyLoadedAt: 0,
81
+ // A post reopened from the history. Separate from `post`, which belongs to the one-per-session queue.
82
+ viewing: null as WnPost | null,
83
+ viewingWasNew: false,
84
+ openingId: null as number | null,
85
+ openError: false,
62
86
  }),
63
87
 
64
88
  actions: {
@@ -108,6 +132,8 @@ export const useWhatsNewStore = defineStore("whats-new-store", {
108
132
  this.shownThisSession = true;
109
133
  writeStorage(LAST_SHOWN_KEY, String(Date.now()));
110
134
  this.track("view");
135
+ this.markSeenLocal(this.post.id);
136
+ this.refreshUnreadSoon();
111
137
  },
112
138
 
113
139
  hide() {
@@ -120,15 +146,19 @@ export const useWhatsNewStore = defineStore("whats-new-store", {
120
146
  this.remaining = 0;
121
147
  this.fetchedFor = null;
122
148
  this.open = false;
149
+ this.resetHistory();
123
150
  },
124
151
 
125
152
  track(event: WnEventName, target?: string) {
126
- if (!this.post) return;
153
+ if (this.post) this.trackFor(this.post, event, target);
154
+ },
155
+
156
+ trackFor(post: WnPost, event: WnEventName, target?: string) {
127
157
  const { platformId } = getConfig();
128
158
  if (!platformId) return;
129
159
  const entry: WnReceiptEvent = {
130
- post_id: this.post.id,
131
- post_version: this.post.version,
160
+ post_id: post.id,
161
+ post_version: post.version,
132
162
  event,
133
163
  platform_id: platformId,
134
164
  surface: "web",
@@ -141,6 +171,199 @@ export const useWhatsNewStore = defineStore("whats-new-store", {
141
171
  else if (!flushTimer) flushTimer = setTimeout(() => this.flush(), 1500);
142
172
  },
143
173
 
174
+ // ── history ───────────────────────────────────────────────────────────
175
+
176
+ registerHost(id: string) {
177
+ if (!this.hosts.includes(id)) this.hosts.push(id);
178
+ this.hostMounted = true;
179
+ },
180
+
181
+ unregisterHost(id: string) {
182
+ this.hosts = this.hosts.filter((h) => h !== id);
183
+ this.hostMounted = this.hosts.length > 0;
184
+ },
185
+
186
+ resetHistory() {
187
+ this.unread = 0;
188
+ this.unreadFor = null;
189
+ this.drawerOpen = false;
190
+ this.history = [];
191
+ this.historyMeta = null;
192
+ this.historyStatus = "idle";
193
+ this.historyLoadedAt = 0;
194
+ this.viewing = null;
195
+ this.viewingWasNew = false;
196
+ this.openingId = null;
197
+ this.openError = false;
198
+ },
199
+
200
+ /** Badge number. One light call per login identity; `force` re-reads it (after a view or closing the drawer). */
201
+ async fetchUnread(identity: string, force = false) {
202
+ if (!force && this.unreadFor === identity) return;
203
+ const { networkBaseUrl, platformId } = getConfig();
204
+ if (!networkBaseUrl || !platformId) return;
205
+ this.unreadFor = identity;
206
+ try {
207
+ const params = new URLSearchParams({ platform_id: String(platformId), surface: "web" });
208
+ const res: any = await $fetch(`${networkBaseUrl}/whats-new/unread-count?${params.toString()}`, {
209
+ credentials: "include",
210
+ timeout: 8000,
211
+ retry: 0,
212
+ });
213
+ if (this.unreadFor !== identity) return; // user switched meanwhile
214
+ this.unread = Math.max(0, Number(res?.data?.count ?? 0));
215
+ } catch {
216
+ // Non-critical: no badge is better than a broken menu.
217
+ if (force) return;
218
+ this.unreadFor = null;
219
+ }
220
+ },
221
+
222
+ /**
223
+ * A moment after a `view` the server may have retired older announcements too: re-read the badge and, when the
224
+ * list is loaded, the list itself, so no row keeps a "new" mark the badge no longer counts.
225
+ */
226
+ refreshUnreadSoon() {
227
+ const identity = this.unreadFor;
228
+ if (!identity || typeof window === "undefined") return;
229
+ setTimeout(async () => {
230
+ await this.fetchUnread(identity, true);
231
+ await this.refreshHistorySilently();
232
+ }, 2500);
233
+ },
234
+
235
+ /** Reloads the pages already shown without flipping the drawer to its loading state. */
236
+ async refreshHistorySilently() {
237
+ const { networkBaseUrl, platformId } = getConfig();
238
+ if (!networkBaseUrl || !platformId || !this.history.length || !this.historyLocale) return;
239
+ if (this.historyStatus !== "idle") return;
240
+ const pages = Math.max(1, this.historyMeta?.page ?? 1);
241
+ const rows: WnHistoryItem[] = [];
242
+ let meta: WnHistoryMeta | null = null;
243
+ try {
244
+ for (let page = 1; page <= pages; page++) {
245
+ const res: any = await this.requestHistoryPage(this.historyLocale, page);
246
+ rows.push(...(Array.isArray(res?.data) ? res.data : []));
247
+ meta = res?.meta ?? meta;
248
+ }
249
+ } catch {
250
+ return; // keep what is on screen
251
+ }
252
+ if (this.historyStatus !== "idle") return;
253
+ this.history = rows;
254
+ this.historyMeta = meta;
255
+ if (meta) this.unread = Math.max(0, Number(meta.unread_count ?? 0));
256
+ },
257
+
258
+ requestHistoryPage(locale: string, page: number) {
259
+ const { networkBaseUrl, platformId } = getConfig();
260
+ const params = new URLSearchParams({
261
+ platform_id: String(platformId),
262
+ surface: "web",
263
+ lang: toApiLang(locale),
264
+ page: String(page),
265
+ per_page: String(WN_HISTORY_PAGE),
266
+ });
267
+ return $fetch(`${networkBaseUrl}/whats-new?${params.toString()}`, {
268
+ credentials: "include",
269
+ timeout: 10000,
270
+ retry: 0,
271
+ });
272
+ },
273
+
274
+ /** The user has just seen post `id`: update the list row and the badge without waiting for the server. */
275
+ markSeenLocal(id: number) {
276
+ const row = this.history.find((h) => h.id === id);
277
+ if (row) {
278
+ if (!row.is_new) return; // already counted
279
+ row.is_new = false;
280
+ row.seen_at = new Date().toISOString();
281
+ }
282
+ this.unread = Math.max(0, this.unread - 1);
283
+ },
284
+
285
+ async fetchHistory(locale: string, page = 1) {
286
+ const { networkBaseUrl, platformId } = getConfig();
287
+ if (!networkBaseUrl || !platformId) return;
288
+ const append = page > 1;
289
+ this.historyStatus = append ? "loadingMore" : "loading";
290
+ this.historyLocale = locale;
291
+ try {
292
+ const res: any = await this.requestHistoryPage(locale, page);
293
+ const rows: WnHistoryItem[] = Array.isArray(res?.data) ? res.data : [];
294
+ if (append) {
295
+ const known = new Set(this.history.map((h) => h.id));
296
+ this.history = [...this.history, ...rows.filter((r) => !known.has(r.id))];
297
+ } else {
298
+ this.history = rows;
299
+ }
300
+ this.historyMeta = res?.meta ?? null;
301
+ if (this.historyMeta) this.unread = Math.max(0, Number(this.historyMeta.unread_count ?? 0));
302
+ this.historyLoadedAt = Date.now();
303
+ this.historyStatus = "idle";
304
+ } catch {
305
+ this.historyStatus = "error";
306
+ }
307
+ },
308
+
309
+ async openDrawer(locale: string) {
310
+ this.drawerOpen = true;
311
+ this.openError = false;
312
+ const stale = Date.now() - this.historyLoadedAt > HISTORY_STALE_MS;
313
+ if (this.historyStatus === "idle" && (!this.history.length || stale)) await this.fetchHistory(locale, 1);
314
+ else if (this.historyStatus === "error") await this.fetchHistory(locale, 1);
315
+ },
316
+
317
+ closeDrawer() {
318
+ this.drawerOpen = false;
319
+ },
320
+
321
+ async loadMoreHistory(locale: string) {
322
+ const meta = this.historyMeta;
323
+ if (!meta || this.historyStatus !== "idle" || meta.page >= meta.last_page) return;
324
+ await this.fetchHistory(locale, meta.page + 1);
325
+ },
326
+
327
+ /** Reopens one announcement from the list. Only the first time (`is_new`) counts as a `view`. */
328
+ async openItem(item: WnHistoryItem, locale: string) {
329
+ const { networkBaseUrl, platformId } = getConfig();
330
+ if (!networkBaseUrl || !platformId || this.openingId !== null) return;
331
+ this.openingId = item.id;
332
+ this.openError = false;
333
+ try {
334
+ const params = new URLSearchParams({
335
+ platform_id: String(platformId),
336
+ surface: "web",
337
+ lang: toApiLang(locale),
338
+ });
339
+ const res: any = await $fetch(`${networkBaseUrl}/whats-new/${item.id}?${params.toString()}`, {
340
+ credentials: "include",
341
+ timeout: 10000,
342
+ retry: 0,
343
+ });
344
+ if (!res?.data) throw new Error("empty");
345
+ this.viewing = res.data as WnPost;
346
+ this.viewingWasNew = item.is_new;
347
+ if (item.is_new) {
348
+ this.trackFor(this.viewing, "view");
349
+ this.markSeenLocal(item.id);
350
+ this.refreshUnreadSoon();
351
+ }
352
+ } catch {
353
+ this.openError = true;
354
+ } finally {
355
+ this.openingId = null;
356
+ }
357
+ },
358
+
359
+ /** Closing a reopened announcement. If it was new, the user has now dealt with it: `dismiss`. */
360
+ closeViewing(dismiss = true) {
361
+ if (dismiss && this.viewing && this.viewingWasNew) this.trackFor(this.viewing, "dismiss");
362
+ this.viewing = null;
363
+ this.viewingWasNew = false;
364
+ this.flush();
365
+ },
366
+
144
367
  /** Sends queued events in batches of ≤20. keepalive lets it survive a page unload. */
145
368
  flush() {
146
369
  if (flushTimer) {
package/types/index.ts CHANGED
@@ -114,6 +114,8 @@ export interface MgSharedUiConfig {
114
114
  systemId: string;
115
115
  apiBaseURL: string;
116
116
  accountsBaseUrl: string;
117
+ communityApiUrl?: string;
118
+ communitySiteUrl?: string;
117
119
  features: {
118
120
  chat: boolean;
119
121
  notifications: boolean;
@@ -121,6 +123,7 @@ export interface MgSharedUiConfig {
121
123
  darkMode: boolean;
122
124
  search: boolean;
123
125
  statusOnline: boolean;
126
+ gamification?: boolean;
124
127
  };
125
128
  languages: string[];
126
129
  protectedRoutes: string[];
package/utils/whatsNew.ts CHANGED
@@ -45,6 +45,37 @@ export interface WnPost {
45
45
  history_url: string | null;
46
46
  }
47
47
 
48
+ /** One row of the history list (GET /whats-new). `is_new` = the user has not seen it yet. */
49
+ export interface WnHistoryItem {
50
+ id: number;
51
+ version: number;
52
+ kind: WnPost["kind"];
53
+ title: string;
54
+ summary: string | null;
55
+ published_at: string | null;
56
+ thumb_url: string | null;
57
+ seen_at: string | null;
58
+ is_new: boolean;
59
+ }
60
+
61
+ export interface WnHistoryMeta {
62
+ total: number;
63
+ page: number;
64
+ per_page: number;
65
+ last_page: number;
66
+ unread_count: number;
67
+ }
68
+
69
+ /** Page size of the drawer list. */
70
+ export const WN_HISTORY_PAGE = 20;
71
+
72
+ /** Badge text: nothing at 0, "9+" from ten up so it never outgrows the menu row. */
73
+ export function formatBadge(count: number | null | undefined): string {
74
+ const n = Math.floor(Number(count) || 0);
75
+ if (n <= 0) return "";
76
+ return n > 9 ? "9+" : String(n);
77
+ }
78
+
48
79
  // ─── Inline markup: **bold** and [text](url) ────────────────────────────────
49
80
 
50
81
  /** The single link regex shared with every other client (see the contract). */