|
1 | 1 | import { readGameJourneyCompletionMetrics } from "/src/api/game-journey-completion-api-client.js"; |
2 | 2 | import { createServerRepositoryClient } from "/src/api/server-api-client.js"; |
3 | 3 | import { getToolBySlug } from "/src/shared/toolbox/tool-metadata-inventory.js"; |
| 4 | +import { createThemeIcon } from "/assets/theme-v2/js/theme-icons.js"; |
4 | 5 |
|
5 | 6 | const EXCLUDED_SELECTED_GAME_TOOLS = new Set(["idea-board"]); |
6 | 7 | const STATUS_BAR_SELECTOR = "[data-toolbox-status-bar]"; |
| 8 | +const STATUS_ICON_BY_CONTEXT_KIND = Object.freeze({ |
| 9 | + action: "add", |
| 10 | + delete: "delete", |
| 11 | + error: "error", |
| 12 | + info: "info", |
| 13 | + save: "save", |
| 14 | + validation: "validation", |
| 15 | + warning: "warning", |
| 16 | +}); |
7 | 17 | const TOOL_PROGRESS_BUCKET_BY_SLUG = Object.freeze({ |
8 | 18 | "achievements": "Progression", |
9 | 19 | "assets": "Graphics", |
@@ -262,10 +272,31 @@ function classifyToolContext(messageText, state, required) { |
262 | 272 | if (/\b(validation|requirement|requirements|missing|required|open or seed)\b/i.test(text)) { |
263 | 273 | return { kind: "validation" }; |
264 | 274 | } |
265 | | - if (/\b(saved|created|deleted|updated|loaded|save changes)\b/i.test(text)) { |
| 275 | + if (/\b(deleted)\b/i.test(text)) { |
| 276 | + return { kind: "delete" }; |
| 277 | + } |
| 278 | + if (/\b(saved|created|updated|loaded|save changes)\b/i.test(text)) { |
266 | 279 | return { kind: "save" }; |
267 | 280 | } |
268 | | - return { kind: "action" }; |
| 281 | + return { kind: "info" }; |
| 282 | +} |
| 283 | + |
| 284 | +function statusIconNameForKind(kind) { |
| 285 | + return STATUS_ICON_BY_CONTEXT_KIND[kind] || STATUS_ICON_BY_CONTEXT_KIND.info; |
| 286 | +} |
| 287 | + |
| 288 | +function renderStatusMessage(message, text, context) { |
| 289 | + if (!message) { |
| 290 | + return; |
| 291 | + } |
| 292 | + const kind = context?.kind || "info"; |
| 293 | + const iconName = statusIconNameForKind(kind); |
| 294 | + const icon = createThemeIcon(iconName, { |
| 295 | + className: ["status-icon", `status-icon--${kind}`, "toolbox-status-bar__status-icon"], |
| 296 | + }); |
| 297 | + message.dataset.toolboxStatusIcon = iconName; |
| 298 | + message.dataset.toolboxStatusKind = kind; |
| 299 | + message.replaceChildren(icon, document.createTextNode(text)); |
269 | 300 | } |
270 | 301 |
|
271 | 302 | function normalizeTextKey(value) { |
@@ -387,24 +418,24 @@ function renderSelectedGame(bar, selectedGame, state, messageText) { |
387 | 418 |
|
388 | 419 | if (selectedGame) { |
389 | 420 | name.textContent = selectedGame.name; |
390 | | - message.textContent = nextMessage; |
| 421 | + renderStatusMessage(message, nextMessage, context); |
391 | 422 | return; |
392 | 423 | } |
393 | 424 |
|
394 | 425 | if (!required) { |
395 | 426 | name.textContent = "No game selected"; |
396 | | - message.textContent = nextMessage; |
| 427 | + renderStatusMessage(message, nextMessage, context); |
397 | 428 | return; |
398 | 429 | } |
399 | 430 |
|
400 | 431 | if (state === "error") { |
401 | 432 | name.textContent = "Unavailable"; |
402 | | - message.textContent = nextMessage; |
| 433 | + renderStatusMessage(message, nextMessage, context); |
403 | 434 | return; |
404 | 435 | } |
405 | 436 |
|
406 | 437 | name.textContent = "No game selected"; |
407 | | - message.textContent = "Select or create a game in Game Hub before using this toolbox page."; |
| 438 | + renderStatusMessage(message, "Select or create a game in Game Hub before using this toolbox page.", context); |
408 | 439 | } |
409 | 440 |
|
410 | 441 | export function refreshToolboxStatusBar() { |
|
0 commit comments