@@ -6,77 +6,89 @@ const emit = defineEmits<{
66 remove: [module : Module ]
77}>()
88
9- const { module, showBadge = true , isAdded, showAddButton = true } = defineProps <{
10- module: Module
11- showBadge? : boolean
12- isAdded: boolean
13- showAddButton? : boolean
14- }>()
9+ const props = withDefaults (
10+ defineProps <{
11+ module: Module
12+ showBadge? : boolean
13+ isAdded: boolean
14+ showAddButton? : boolean
15+ }>(),
16+ {
17+ showBadge: true ,
18+ showAddButton: true
19+ }
20+ )
1521
1622const { copy } = useClipboard ()
1723const { selectedSort } = useModules ()
1824const { track } = useAnalytics ()
19- const date = computed (() => {
20- if (selectedSort .value .key === ' publishedAt' ) {
21- return useTimeAgo (module .stats .publishedAt )
22- }
2325
24- return useTimeAgo (module .stats .createdAt )
25- })
26+ const publishedAgo = useTimeAgo (() => props .module .stats .publishedAt )
27+ const createdAgo = useTimeAgo (() => props .module .stats .createdAt )
28+
29+ const relativeDate = computed (() =>
30+ selectedSort .value .key === ' publishedAt' ? publishedAgo .value : createdAgo .value
31+ )
32+
33+ const staticModuleDate = computed (() =>
34+ selectedSort .value .key === ' publishedAt'
35+ ? formatDateByLocale (' en' , props .module .stats .publishedAt )
36+ : formatDateByLocale (' en' , props .module .stats .createdAt )
37+ )
2638
2739function copyInstallCommand(moduleName : string ) {
2840 track (' Module Install Command Copied' , { module: moduleName })
2941 const command = ` npx nuxt@latest module add ${moduleName } `
3042 copy (command , { title: ' Command copied to clipboard:' , description: command })
3143}
3244
33- function toggleModule(module : Module ) {
34- const action = isAdded ? ' remove' : ' add'
35- track (' Module Toggled' , { module: module .name , action })
36- if (isAdded ) {
37- emit (' remove' , module )
45+ function toggleModule(m : Module ) {
46+ const action = props . isAdded ? ' remove' : ' add'
47+ track (' Module Toggled' , { module: m .name , action })
48+ if (props . isAdded ) {
49+ emit (' remove' , m )
3850 } else {
39- emit (' add' , module )
51+ emit (' add' , m )
4052 }
4153}
4254
4355function handleCardClick(event : MouseEvent ) {
4456 if (event .shiftKey ) {
4557 event .preventDefault ()
46- toggleModule (module )
58+ toggleModule (props . module )
4759 }
4860}
4961
5062const items = computed (() => [
5163 [
5264 {
53- label: isAdded ? ' Remove module' : ' Add module' ,
54- icon: isAdded ? ' i-lucide-minus' : ' i-lucide-plus' ,
55- onSelect : () => toggleModule (module )
65+ label: props . isAdded ? ' Remove module' : ' Add module' ,
66+ icon: props . isAdded ? ' i-lucide-minus' : ' i-lucide-plus' ,
67+ onSelect : () => toggleModule (props . module )
5668 },
5769 {
5870 label: ' Copy install command' ,
5971 icon: ' i-lucide-terminal' ,
60- onSelect : () => copyInstallCommand (module .name )
72+ onSelect : () => copyInstallCommand (props . module .name )
6173 }
6274 ],
6375 [
6476 {
6577 icon: ' i-lucide-book' ,
6678 label: ' Documentation' ,
67- to: ` ${module .website }?utm_source=nuxt.com&utm_medium=aside-module&utm_campaign=nuxt.com ` ,
79+ to: ` ${props . module .website }?utm_source=nuxt.com&utm_medium=aside-module&utm_campaign=nuxt.com ` ,
6880 target: ' _blank'
6981 },
7082 {
7183 label: ' View on GitHub' ,
7284 icon: ' i-lucide-github' ,
73- to: ` https://github.com/${module .repo } ` ,
85+ to: ` https://github.com/${props . module .repo } ` ,
7486 target: ' _blank'
7587 },
7688 {
7789 label: ' View on npm' ,
7890 icon: ' i-lucide-package' ,
79- to: ` https://npm.chart.dev/${module .npm } ` ,
91+ to: ` https://npm.chart.dev/${props . module .npm } ` ,
8092 target: ' _blank'
8193 }
8294 ]
@@ -112,15 +124,15 @@ const items = computed(() => [
112124 </template >
113125
114126 <UBadge
115- v-if =" showBadge && module.type === 'official'"
127+ v-show =" showBadge && module.type === 'official'"
116128 class =" shine absolute top-4 right-4 sm:top-6 sm:right-6"
117129 variant =" subtle"
118130 color =" primary"
119131 label =" Official"
120132 />
121133
122134 <UBadge
123- v-if =" showBadge && module.sponsor"
135+ v-show =" showBadge && module.sponsor"
124136 class =" shine absolute top-4 right-4 sm:top-6 sm:right-6"
125137 variant =" subtle"
126138 color =" important"
@@ -161,7 +173,14 @@ const items = computed(() => [
161173 target =" _blank"
162174 >
163175 <UIcon name =" i-lucide-radio" class =" size-4 shrink-0" />
164- <span class =" text-sm font-medium whitespace-normal" >{{ date }}</span >
176+ <span class =" text-sm font-medium whitespace-normal" >
177+ <ClientOnly >
178+ {{ relativeDate }}
179+ <template #fallback >
180+ {{ staticModuleDate }}
181+ </template >
182+ </ClientOnly >
183+ </span >
165184 </NuxtLink >
166185 </UTooltip >
167186
@@ -172,7 +191,14 @@ const items = computed(() => [
172191 target =" _blank"
173192 >
174193 <UIcon name =" i-lucide-package" class =" size-4 shrink-0" />
175- <span class =" text-sm font-medium whitespace-normal" >{{ date }}</span >
194+ <span class =" text-sm font-medium whitespace-normal" >
195+ <ClientOnly >
196+ {{ relativeDate }}
197+ <template #fallback >
198+ {{ staticModuleDate }}
199+ </template >
200+ </ClientOnly >
201+ </span >
176202 </NuxtLink >
177203 </UTooltip >
178204 </div >
0 commit comments