-
-
Notifications
You must be signed in to change notification settings - Fork 427
feat: add dependents sorted by download #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| <script setup lang="ts"> | ||
| import { usePackageDependents } from '~/composables/useNpmRegistry' | ||
| import { formatCompactNumber } from '~/utils/formatters' | ||
|
|
||
| const props = defineProps<{ | ||
| packageName: string | ||
| }>() | ||
|
|
||
| const { data, status } = usePackageDependents(() => props.packageName) | ||
|
|
||
| const dependents = computed(() => data.value?.objects ?? []) | ||
| const total = computed(() => data.value?.total ?? 0) | ||
|
|
||
| // Expanded state for showing all dependents | ||
| const expanded = ref(false) | ||
|
|
||
| // Show first 10 by default, all when expanded | ||
| const visibleDependents = computed(() => { | ||
| if (expanded.value) { | ||
| return dependents.value | ||
| } | ||
| return dependents.value.slice(0, 10) | ||
| }) | ||
|
|
||
| // Show section only when we have dependents or are loading | ||
| const showSection = computed(() => { | ||
| return status.value === 'pending' || dependents.value.length > 0 | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <section v-if="showSection" aria-labelledby="dependents-heading"> | ||
| <h2 id="dependents-heading" class="text-xs text-fg-subtle uppercase tracking-wider mb-3"> | ||
| Dependents | ||
| <span v-if="status === 'success' && total > 0">({{ total.toLocaleString() }})</span> | ||
| </h2> | ||
|
|
||
| <!-- Loading state --> | ||
| <div v-if="status === 'pending'" class="space-y-2"> | ||
| <div v-for="i in 5" :key="i" class="flex items-center justify-between py-1"> | ||
| <div class="skeleton h-4 rounded" :style="{ width: `${60 + (i % 3) * 20}px` }" /> | ||
| <div class="skeleton h-3 w-12 rounded" /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Dependents list --> | ||
| <ul | ||
| v-else-if="dependents.length > 0" | ||
| class="space-y-1 list-none m-0 p-0" | ||
| aria-label="Packages that depend on this package" | ||
| > | ||
| <li | ||
| v-for="dependent in visibleDependents" | ||
| :key="dependent.package.name" | ||
| class="flex items-center justify-between py-1 text-sm gap-2" | ||
| > | ||
| <NuxtLink | ||
| :to="{ name: 'package', params: { package: dependent.package.name.split('/') } }" | ||
| class="font-mono text-fg-muted hover:text-fg transition-colors duration-200 truncate min-w-0" | ||
| > | ||
| {{ dependent.package.name }} | ||
| </NuxtLink> | ||
| <span | ||
| v-if="dependent.downloads?.weekly" | ||
| class="font-mono text-xs text-fg-subtle shrink-0 flex items-center gap-1" | ||
| :title="`${dependent.downloads.weekly.toLocaleString()} weekly downloads`" | ||
| > | ||
| <span class="i-carbon-download w-3 h-3" aria-hidden="true" /> | ||
| {{ formatCompactNumber(dependent.downloads.weekly, { decimals: 1 }) }} | ||
| </span> | ||
| </li> | ||
| </ul> | ||
|
|
||
| <!-- Expand button --> | ||
| <button | ||
| v-if="dependents.length > 10 && !expanded" | ||
| type="button" | ||
| class="mt-2 font-mono text-xs text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50" | ||
| @click="expanded = true" | ||
| > | ||
| show top {{ dependents.length }} | ||
| </button> | ||
| </section> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this pulls in correct data:
https://www.npmjs.com/search?q=depends-on%3Anuxt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in e18e we have a whole other database to do this query because the npm one wasn't capable. so when i saw this, i was very surprised and hoped it was true so we could switch 😂
but im pretty sure the npm api doesn't do what you think here, or it does, but very poorly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Darn, back to the drawing board! Thought the data was correct 🥲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about this one https://www.npmjs.com/browse/depended/nuxt ?