Skip to content

Commit f98a5f2

Browse files
committed
fix(ui): hide awkward empty state for weekly downloads for new packages
Closes #1044
1 parent 50ed1cd commit f98a5f2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const hasChartModalTransitioned = shallowRef(false)
1313
const isChartModalOpen = shallowRef(false)
1414
1515
async function openChartModal() {
16+
if (!hasWeeklyDownloads.value) return
17+
1618
isChartModalOpen.value = true
1719
hasChartModalTransitioned.value = false
1820
// ensure the component renders before opening the dialog
@@ -96,10 +98,13 @@ const pulseColor = computed(() => {
9698
})
9799
98100
const weeklyDownloads = shallowRef<WeeklyDownloadPoint[]>([])
101+
const isLoadingWeeklyDownloads = shallowRef(false)
102+
const hasWeeklyDownloads = computed(() => weeklyDownloads.value.length > 0)
99103
100104
async function loadWeeklyDownloads() {
101105
if (!import.meta.client) return
102106
107+
isLoadingWeeklyDownloads.value = true
103108
try {
104109
const result = await fetchPackageDownloadEvolution(
105110
() => props.packageName,
@@ -109,6 +114,8 @@ async function loadWeeklyDownloads() {
109114
weeklyDownloads.value = (result as WeeklyDownloadPoint[]) ?? []
110115
} catch {
111116
weeklyDownloads.value = []
117+
} finally {
118+
isLoadingWeeklyDownloads.value = false
112119
}
113120
}
114121
@@ -208,10 +215,11 @@ const config = computed(() => {
208215
</script>
209216

210217
<template>
211-
<div class="space-y-8">
218+
<div v-if="isLoadingWeeklyDownloads || hasWeeklyDownloads" class="space-y-8">
212219
<CollapsibleSection id="downloads" :title="$t('package.downloads.title')">
213220
<template #actions>
214221
<ButtonBase
222+
v-if="hasWeeklyDownloads"
215223
type="button"
216224
@click="openChartModal"
217225
class="text-fg-subtle hover:text-fg transition-colors duration-200 inline-flex items-center justify-center min-w-6 min-h-6 -m-1 p-1 focus-visible:outline-accent/70 rounded"
@@ -260,7 +268,11 @@ const config = computed(() => {
260268
</CollapsibleSection>
261269
</div>
262270

263-
<PackageChartModal @close="handleModalClose" @transitioned="handleModalTransitioned">
271+
<PackageChartModal
272+
v-if="isChartModalOpen && hasWeeklyDownloads"
273+
@close="handleModalClose"
274+
@transitioned="handleModalTransitioned"
275+
>
264276
<!-- The Chart is mounted after the dialog has transitioned -->
265277
<!-- This avoids flaky behavior that hides the chart's minimap half of the time -->
266278
<Transition name="opacity" mode="out-in">

0 commit comments

Comments
 (0)