All files / src/components PackSidebar.vue

94.73% Statements 216/228
86.53% Branches 135/156
89.13% Functions 41/46
97.58% Lines 202/207

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643                      2x       2x                                                 2x 2x                           2x                                                                 2x             2x     2x           3x                   1x                 2x                     2x 2x               2x           2x       202x     1x     202x                                                                                               1x                           1x                                                                                 50x                   50x   50x 50x 50x 50x 50x 50x 50x 50x   50x 50x 50x 50x 50x 50x 50x 50x     50x 105x 53x 53x     50x   52x 52x               64x   64x 2x 2x 2x 2x 2x 2x   62x 62x 62x   2x 2x 1x   2x   60x     58x 58x 57x       2x 2x 2x   2x 2x 2x 2x   1x 1x 1x             2x       50x   3x 3x 3x 3x 3x 3x 2x 2x   1x   3x         2x 2x 2x 2x 2x 2x 1x 1x 1x     1x 1x   2x           50x                                   50x 50x     50x 8x       4x 4x 4x 4x         3x 3x 3x 3x 3x 2x   1x   3x         6x 6x 6x 6x 6x 6x   6x 6x     13x                 4x   4x 2x 2x 2x 2x 2x 2x     2x   1x 1x 1x   1x 1x     6x         3x           1x 1x       1x 1x         50x                                   50x 50x     50x 4x           59x 59x 58x 58x 58x   57x   1x         6x 6x 6x       8x 8x 8x 8x 8x 8x   8x 8x 2x   2x 1x 1x 1x 1x 1x     6x 6x   4x 4x 4x 2x   1x   1x 1x     8x         1x 1x         1x 1x 1x             1x 1x 1x 1x           2x 2x 2x 2x 2x 1x 1x   1x       58x                  
<template>
  <!-- A pack over the Store, as an item over its list (UC-STORE-002.1): the
       Store keeps its search, sort and scroll behind it -->
  <BaseFormSidebar
    :is-open="!!packId"
    storage-key="pack-sidebar"
    :title="title"
    icon="fa-solid fa-store"
    panel-width="1100px"
    @close="emit('close')"
  >
    <div class="pack-sidebar">
      <LoadingSpinner v-if="loading" :grid="false" :padding="5" :message="t('common.loading')" />
 
      <EmptyState v-else-if="!pack" variant="info" icon="fa-solid fa-info-circle" :grid="false">
        {{ t('store.notFound') }}
      </EmptyState>
 
      <div v-else class="pack-sidebar-content">
        <!-- Its picture, on its card too; those who may delete the pack change it -->
        <div v-if="pack.canDelete || pack.picture" class="pack-picture mb-3">
          <label v-if="pack.canDelete" class="form-label pack-picture-label">
            {{ t('store.pictureLabel') }}
          </label>
          <!-- While the new picture is attached, a spinner rather than the old one -->
          <div v-if="savingPicture" class="text-muted small pack-picture-saving">
            <font-awesome-icon icon="fa-solid fa-spinner" spin class="me-1" />
            {{ t('common.uploading') }}
          </div>
          <ImageField
            v-else
            :model-value="pack.picture ?? null"
            :field="{ name: 'picture', type: 'image', fieldId: 'pack-picture' }"
            :is-editing="pack.canDelete"
            :pack-id="pack.id"
            object-fit="contain"
            @update:model-value="changePicture"
          />
        </div>
 
        <div class="d-flex flex-wrap align-items-center gap-2 mb-2">
          <span class="badge bg-secondary pack-version">
            {{ t('store.versionLabel').replace('{version}', String(pack.version)) }}
          </span>
          <span v-if="pack.flow.name" class="text-muted small pack-flow">{{ pack.flow.name }}</span>
          <span class="text-muted small pack-imports" :title="t('store.importsCount')">
            <font-awesome-icon icon="fa-solid fa-download" class="me-1" />
            {{ pack.importsCount }}
          </span>
        </div>
 
        <p v-if="getTranslation(pack.description)" class="pack-description">
          {{ getTranslation(pack.description) }}
        </p>
 
        <div class="d-flex flex-wrap gap-2 mb-4">
          <button
            v-if="canInstall"
            type="button"
            class="btn btn-primary pack-install"
            :disabled="preparingInstall"
            @click="openInstall"
          >
            <font-awesome-icon icon="fa-solid fa-download" class="me-2" />
            {{ t('store.install') }}
          </button>
          <button
            v-if="upgrade.preview && upgrade.preview.copies.length > 0"
            type="button"
            class="btn btn-outline-secondary pack-upgrade"
            @click="openUpgrade"
          >
            <font-awesome-icon icon="fa-solid fa-arrows-rotate" class="me-2" />
            {{
              t('store.upgradeAction')
                .replace('{from}', String(upgrade.preview.fromVersion))
                .replace('{to}', String(upgrade.preview.toVersion))
            }}
          </button>
          <button
            type="button"
            class="btn pack-like"
            :class="pack.likedByMe ? 'btn-danger' : 'btn-outline-secondary'"
            :aria-pressed="pack.likedByMe"
            :aria-label="t('store.like')"
            @click="toggleLike"
          >
            <font-awesome-icon icon="fa-solid fa-heart" class="me-1" />
            <span class="pack-like-count">{{ pack.likesCount }}</span>
          </button>
          <button
            v-if="pack.commentsEnabled"
            type="button"
            class="btn btn-outline-secondary pack-comments"
            :aria-label="t('comment.openWithCount').replace('{count}', String(pack.commentsCount))"
            @click="commentsOpen = true"
          >
            <font-awesome-icon icon="fa-solid fa-comment" class="me-1" />
            <span class="pack-comments-count">{{ pack.commentsCount }}</span>
          </button>
          <button
            v-if="pack.canPublishVersion"
            type="button"
            class="btn btn-outline-secondary pack-publish-version"
            @click="publishOpen = true"
          >
            <font-awesome-icon icon="fa-solid fa-store" class="me-2" />
            {{ t('store.publishVersionAction') }}
          </button>
          <!-- Packs are not moderated: a report is how abuse reaches the platform admins -->
          <button
            v-if="!pack.canDelete"
            type="button"
            class="btn btn-outline-secondary pack-report"
            @click="reporting = true"
          >
            <font-awesome-icon icon="fa-solid fa-flag" class="me-2" />
            {{ t('report.action') }}
          </button>
          <button
            v-if="pack.canDelete"
            type="button"
            class="btn btn-outline-danger pack-delete"
            @click="confirmingDelete = true"
          >
            <font-awesome-icon icon="fa-solid fa-trash" class="me-2" />
            {{ t('store.delete') }}
          </button>
        </div>
 
        <PackSchemaView :entities="schemaEntities" />
 
        <!-- Those who may delete the pack manage its comments -->
        <section v-if="pack.canDelete" class="pack-comment-settings mt-4">
          <h2 class="h6">{{ t('store.commentSettings') }}</h2>
          <div class="form-check form-switch mb-1">
            <input
              id="pack-comments-enabled"
              class="form-check-input pack-comments-toggle"
              type="checkbox"
              role="switch"
              :checked="pack.commentsEnabled"
              :disabled="savingComments"
              @change="toggleComments($event.target as HTMLInputElement)"
            />
            <label class="form-check-label" for="pack-comments-enabled">
              {{ t('store.commentsToggle') }}
            </label>
          </div>
          <div class="form-text mb-3">{{ t('store.commentsToggleHelp') }}</div>
          <CommentBlocksList :pack-id="pack.id" />
        </section>
      </div>
    </div>
 
    <template #footer>
      <button type="button" class="btn btn-secondary pack-sidebar-close" @click="emit('close')">
        <font-awesome-icon icon="fa-solid fa-times" class="me-1" />
        {{ t('common.close') }}
      </button>
    </template>
  </BaseFormSidebar>
 
  <ItemCommentsSidebar
    v-if="pack"
    :is-open="commentsOpen"
    :pack-id="pack.id"
    :can-manage="pack.canDelete"
    @close="commentsOpen = false"
    @count-change="onCommentCountChange"
  />
 
  <ImportPreviewSidebar
    :is-open="install.open"
    :bundle="pack?.bundle ?? null"
    :check-results="install.checkResults"
    :loading="install.loading"
    :error="install.error"
    :results="install.results"
    :status="install.status"
    :progress="install.progress"
    schema-only
    :balance="creditsStore.balanceLoaded ? creditsStore.balance : undefined"
    :title="t('store.installTitle').replace('{name}', pack ? getTranslation(pack.name) : '')"
    :submit-label="t('store.install')"
    @confirm="confirmInstall"
    @cancel="cancelInstall"
    @close="closeInstall"
  />
 
  <UpgradePackSidebar
    :is-open="upgrade.open"
    :preview="upgrade.preview"
    :loading="upgrade.loading"
    :error="upgrade.error"
    :result="upgrade.result"
    :status="upgrade.status"
    :progress="upgrade.progress"
    @confirm="confirmUpgrade"
    @cancel="cancelUpgrade"
    @close="closeUpgrade"
  />
 
  <!-- Its next version, starting from what the current one was published from -->
  <PublishPackSidebar
    :is-open="publishOpen"
    :pack="pack"
    @cancel="publishOpen = false"
    @published="onVersionPublished"
  />
 
  <ConfirmModal
    :is-open="confirmingDelete"
    :title="t('store.deleteTitle')"
    :message="t('store.deleteMessage')"
    @confirm="deletePack"
    @cancel="confirmingDelete = false"
  />
 
  <ReportModal
    :target="reporting && pack ? { type: 'pack', packId: pack.id } : null"
    @close="reporting = false"
  />
</template>
 
<script setup lang="ts">
// @implements UC-STORE-002.1, UC-STORE-005.1, UC-STORE-006.1, UC-STORE-007.1, UC-STORE-008.2, UC-STORE-009.1, UC-STORE-013.1, UC-STORE-015.1, UC-REPORT-003.1
import { computed, reactive, ref, watch } from 'vue'
import BaseFormSidebar from '@/components/BaseFormSidebar.vue'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
import EmptyState from '@/components/EmptyState.vue'
import ConfirmModal from '@/components/ConfirmModal.vue'
import ReportModal from '@/components/ReportModal.vue'
import ImportPreviewSidebar from '@/components/ImportPreviewSidebar.vue'
import UpgradePackSidebar from '@/components/UpgradePackSidebar.vue'
import PackSchemaView from '@/components/PackSchemaView.vue'
import ImageField from '@/components/ImageField.vue'
import PublishPackSidebar from '@/components/PublishPackSidebar.vue'
import ItemCommentsSidebar from '@/components/ItemCommentsSidebar.vue'
import CommentBlocksList from '@/components/CommentBlocksList.vue'
import { useUILanguage } from '@/composables/useUILanguage'
import { useLanguage } from '@/composables/useLanguage'
import { usePermissions } from '@/composables/usePermissions'
import { usePollUntilComplete } from '@/composables/usePollUntilComplete'
import { useAuthStore } from '@/stores/auth'
import { useCreditsStore } from '@/stores/credits'
import {
  useEntitiesStore,
  type ImportBundleEntry,
  type ImportBundleResult,
  type ImportCheckResult
} from '@/stores/entities'
import {
  usePacksStore,
  type PackDetail,
  type PackUpgradeChoices,
  type PackUpgradePreview,
  type PackUpgradeResult
} from '@/stores/packs'
import { useToastStore } from '@/stores/toast'
import { getErrorMessage } from '@/utils/errors'
 
const props = withDefaults(
  defineProps<{
    // The pack shown; none closes the sidebar
    packId: string | null
    // `update` opens the update of the flow's copies once loaded, when one is behind
    section?: string | null
  }>(),
  { section: null }
)
// `published`: a new version replaced the one listed
const emit = defineEmits<{ close: []; published: [] }>()
 
const { t } = useUILanguage()
const { getTranslation } = useLanguage()
const { hasPermission } = usePermissions()
const authStore = useAuthStore()
const creditsStore = useCreditsStore()
const entitiesStore = useEntitiesStore()
const packsStore = usePacksStore()
const toastStore = useToastStore()
 
const pack = ref<PackDetail | null>(null)
const loading = ref(true)
const preparingInstall = ref(false)
const confirmingDelete = ref(false)
const reporting = ref(false)
const commentsOpen = ref(false)
const savingComments = ref(false)
const publishOpen = ref(false)
 
// Opened from a list, its name shows at once; it comes with the pack otherwise
const title = computed(() => {
  if (pack.value) return getTranslation(pack.value.name)
  const listed = [...packsStore.packs, ...packsStore.myPacks].find((p) => p.id === props.packId)
  return listed ? getTranslation(listed.name) : ''
})
 
const canInstall = computed(() => !!authStore.currentFlow && hasPermission('entities:create'))
 
const schemaEntities = computed(() =>
  (pack.value?.bundle.entities ?? []).map((entry) => ({
    tempId: entry.tempId,
    ...entry.entity,
    items: entry.items
  }))
)
 
async function load() {
  const id = props.packId
  // Closed: what was shown goes with it, and so do its panels
  if (!id) {
    pack.value = null
    commentsOpen.value = false
    publishOpen.value = false
    install.open = false
    upgrade.open = false
    return
  }
  loading.value = true
  try {
    pack.value = await packsStore.getPack(id)
  } catch (err: any) {
    pack.value = null
    if (err.response?.status !== 404) {
      toastStore.error(getErrorMessage(err, t('store.loadError'), t))
    }
    return
  } finally {
    loading.value = false
  }
  // The pack shows at once: its upgrade button follows, as it waits on another call
  await loadUpgrade()
  if (props.packId !== id) return
  if (props.section === 'update' && upgrade.preview?.copies.length) openUpgrade()
}
 
async function toggleLike() {
  const current = pack.value
  Iif (!current) return
  const liked = current.likedByMe
  // Followed here too: this page holds its own copy of the pack
  current.likedByMe = !liked
  current.likesCount = Math.max(0, current.likesCount + (liked ? -1 : 1))
  try {
    await packsStore.toggleLike(current.id, liked)
  } catch (err) {
    current.likedByMe = liked
    current.likesCount = Math.max(0, current.likesCount + (liked ? 1 : -1))
    toastStore.error(getErrorMessage(err, t('store.likeError'), t))
  }
}
 
// ─── Comments ───────────────────────────────────────────────────────────────
 
function onCommentCountChange(delta: number) {
  Eif (pack.value) pack.value.commentsCount = Math.max(0, pack.value.commentsCount + delta)
}
 
// The pack's picture, uploaded under the pack by ImageField, then attached (UC-STORE-014.1)
const savingPicture = ref(false)
async function changePicture(value: string | string[] | null) {
  const current = pack.value
  Iif (!current) return
  const picture = typeof value === 'string' && value ? value : null
  savingPicture.value = true
  try {
    await packsStore.setPicture(current.id, picture)
    current.picture = picture
    toastStore.success(t('store.pictureSuccess'))
  } catch (err) {
    toastStore.error(getErrorMessage(err, t('store.pictureError'), t))
  } finally {
    savingPicture.value = false
  }
}
 
async function toggleComments(input: HTMLInputElement) {
  const current = pack.value
  Iif (!current) return
  const enabled = input.checked
  savingComments.value = true
  try {
    await packsStore.setCommentsEnabled(current.id, enabled)
    current.commentsEnabled = enabled
    Eif (!enabled) commentsOpen.value = false
    toastStore.success(t('store.commentsToggleSuccess'))
  } catch (err) {
    // The switch goes back to the setting the pack still has
    input.checked = current.commentsEnabled
    toastStore.error(getErrorMessage(err, t('store.commentsToggleError'), t))
  } finally {
    savingComments.value = false
  }
}
 
// ─── Install ────────────────────────────────────────────────────────────────
 
const install = reactive<{
  open: boolean
  checkResults: ImportCheckResult[]
  loading: boolean
  error: string
  results: ImportBundleResult[] | null
  status?: 'pending' | 'processing' | 'completed' | 'failed'
  progress: { done: number; total: number } | null
}>({
  open: false,
  checkResults: [],
  loading: false,
  error: '',
  results: null,
  status: undefined,
  progress: null
})
 
const installJob = usePollUntilComplete<{ results: ImportBundleResult[] }>()
watch(installJob.progress, (progress) => {
  install.progress = progress
})
watch(installJob.status, (status) => {
  install.status = status === 'idle' ? undefined : status
})
 
async function checkNames() {
  const current = pack.value
  Iif (!current) return
  install.checkResults = await entitiesStore.checkImportBundle(
    current.bundle.entities.map((entry) => ({ tempId: entry.tempId, entity: entry.entity }))
  )
}
 
async function openInstall() {
  preparingInstall.value = true
  install.error = ''
  install.results = null
  try {
    await Promise.all([checkNames(), creditsStore.fetchCredits()])
    install.open = true
  } catch (err) {
    toastStore.error(getErrorMessage(err, t('store.installError'), t))
  } finally {
    preparingInstall.value = false
  }
}
 
async function confirmInstall(entries: ImportBundleEntry[]) {
  const current = pack.value
  Iif (!current) return
  install.loading = true
  install.error = ''
  install.status = undefined
  install.progress = null
 
  try {
    const { jobId } = await packsStore.install(
      current.id,
      current.version,
      entries.map((entry) => ({
        tempId: entry.tempId,
        mode: entry.mode === 'create' ? 'create' : 'skip',
        ...(entry.mode === 'create' && { name: entry.name }),
        // The pack's items come with the entity unless Bob unchecks them
        ...(entry.mode === 'create' &&
          (entry.items?.length ?? 0) > 0 && { includeItems: entry.includeItems })
      }))
    )
    await installJob.start(() => entitiesStore.getImportJobStatus(jobId))
 
    if (installJob.status.value === 'completed' && installJob.result.value) {
      install.results = installJob.result.value.results
      current.importsCount += current.flow.id === authStore.currentFlow ? 0 : 1
      toastStore.success(t('store.installSuccess'))
    } else Eif (installJob.status.value === 'failed') {
      install.error = installFailure(installJob.error.value)
      toastStore.error(t('store.installError'))
    }
  } catch (err: any) {
    if (err.response?.data?.error === 'PACK_VERSION_OUTDATED') {
      // A new version was published meanwhile: show it, nothing was installed
      await load()
      await checkNames()
      install.error = t('store.errors.PACK_VERSION_OUTDATED')
    } else {
      install.error = getErrorMessage(err, t('store.installError'), t)
      toastStore.error(t('store.installError'))
    }
  } finally {
    install.loading = false
  }
}
 
function installFailure(error: string | null | undefined): string {
  return error === 'PACK_VERSION_REPLACED'
    ? t('store.errors.PACK_VERSION_REPLACED')
    : error || t('store.installError')
}
 
function cancelInstall() {
  installJob.stop()
  install.open = false
}
 
function closeInstall() {
  install.open = false
  install.results = null
}
 
// ─── Upgrade ────────────────────────────────────────────────────────────────
 
const upgrade = reactive<{
  preview: PackUpgradePreview | null
  open: boolean
  loading: boolean
  error: string
  result: PackUpgradeResult | null
  status?: 'pending' | 'processing' | 'completed' | 'failed'
  progress: { done: number; total: number } | null
}>({
  preview: null,
  open: false,
  loading: false,
  error: '',
  result: null,
  status: undefined,
  progress: null
})
 
const upgradeJob = usePollUntilComplete<PackUpgradeResult>()
watch(upgradeJob.progress, (progress) => {
  upgrade.progress = progress
})
watch(upgradeJob.status, (status) => {
  upgrade.status = status === 'idle' ? undefined : status
})
 
// Whether the active flow has copies to bring to the current version: the
// button shows only then. Quiet when it fails: the page works without it.
async function loadUpgrade() {
  upgrade.preview = null
  if (!authStore.currentFlow || !pack.value) return
  const id = pack.value.id
  try {
    const preview = await packsStore.getUpgrade(id)
    // Another pack opened meanwhile: this preview is not its own
    if (pack.value?.id === id) upgrade.preview = preview
  } catch {
    upgrade.preview = null
  }
}
 
function openUpgrade() {
  upgrade.error = ''
  upgrade.result = null
  upgrade.open = true
}
 
async function confirmUpgrade(choices: PackUpgradeChoices) {
  const current = pack.value
  Iif (!current) return
  upgrade.loading = true
  upgrade.error = ''
  upgrade.status = undefined
  upgrade.progress = null
 
  try {
    const { jobId } = await packsStore.upgrade(current.id, current.version, choices)
    await upgradeJob.start(() => packsStore.getUpgradeJob(jobId))
 
    if (upgradeJob.status.value === 'completed' && upgradeJob.result.value) {
      upgrade.result = upgradeJob.result.value
      toastStore.success(t('store.upgradeSuccess'))
    } else Eif (upgradeJob.status.value === 'failed') {
      upgrade.error = installFailure(upgradeJob.error.value)
      toastStore.error(t('store.upgradeError'))
    }
  } catch (err: any) {
    const code = err.response?.data?.error
    if (code === 'PACK_VERSION_OUTDATED' || code === 'PACK_UPGRADE_UNAVAILABLE') {
      // What the panel showed is no longer offered: show what is now
      await load()
      upgrade.error = t(`store.errors.${code}`)
      if (!upgrade.preview?.copies.length) upgrade.open = false
    } else if (code === 'PACK_FIELD_NAME_TAKEN') {
      // A name Bob chose is still taken: the panel stays, for another one
      upgrade.error = t('store.errors.PACK_FIELD_NAME_TAKEN')
    } else {
      upgrade.error = getErrorMessage(err, t('store.upgradeError'), t)
      toastStore.error(t('store.upgradeError'))
    }
  } finally {
    upgrade.loading = false
  }
}
 
function cancelUpgrade() {
  upgradeJob.stop()
  upgrade.open = false
}
 
// Done reviewing: the button goes once every copy is at the version
async function closeUpgrade() {
  upgrade.open = false
  upgrade.result = null
  await loadUpgrade()
}
 
// ─── New version ────────────────────────────────────────────────────────────
 
// The pack shows the version just published
async function onVersionPublished({ version }: { id: string; version: number }) {
  publishOpen.value = false
  toastStore.success(t('store.publishSuccess').replace('{version}', String(version)))
  emit('published')
  await load()
}
 
// ─── Manage ─────────────────────────────────────────────────────────────────
 
async function deletePack() {
  confirmingDelete.value = false
  const current = pack.value
  Iif (!current) return
  try {
    await packsStore.deletePack(current.id)
    toastStore.success(t('store.deleteSuccess'))
    emit('close')
  } catch (err) {
    toastStore.error(getErrorMessage(err, t('store.deleteError'), t))
  }
}
// Last: loading uses every panel's state above
watch(() => props.packId, load, { immediate: true })
</script>
 
<style scoped>
.pack-description {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
</style>