Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/composables/useRecentlyViewed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useLocalStorage } from '@vueuse/core'
import { computed } from 'vue'

const MAX_RECENT_ITEMS = 5
const STORAGE_KEY = 'npmx-recent'

export type RecentItemType = 'package' | 'org' | 'user'

export interface RecentItem {
type: RecentItemType
/** Canonical identifier: package name, org name (without @), or username */
name: string
/** Display label shown on homepage (e.g. "@nuxt", "~sindresorhus") */
label: string
/** Unix timestamp (ms) of most recent view */
viewedAt: number
}

export function useRecentlyViewed() {
const items = useLocalStorage<RecentItem[]>(STORAGE_KEY, [])

function trackRecentView(item: Omit<RecentItem, 'viewedAt'>) {
if (import.meta.server) return
const filtered = items.value.filter(
existing => !(existing.type === item.type && existing.name === item.name),
)
filtered.unshift({ ...item, viewedAt: Date.now() })
items.value = filtered.slice(0, MAX_RECENT_ITEMS)
}

return { items: computed(() => items.value), trackRecentView }
}
67 changes: 40 additions & 27 deletions app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { SHOWCASED_FRAMEWORKS } from '~/utils/frameworks'
import type { RecentItem } from '~/composables/useRecentlyViewed'
import type { RouteLocationRaw } from 'vue-router'

const { model: searchQuery, flushUpdateUrlQuery } = useGlobalSearch()
const isSearchFocused = shallowRef(false)
Expand All @@ -24,6 +25,19 @@ defineOgImageComponent('Default', {
title: 'npmx',
description: 'a fast, modern browser for the **npm registry**',
})

const { items: recentItems } = useRecentlyViewed()

function recentItemRoute(item: RecentItem): RouteLocationRaw {
switch (item.type) {
case 'package':
return packageRoute(item.name)
case 'org':
return { name: 'org', params: { org: item.name } }
case 'user':
return { name: '~username', params: { username: item.name } }
}
}
</script>

<template>
Expand Down Expand Up @@ -107,22 +121,31 @@ defineOgImageComponent('Default', {
<BuildEnvironment class="mt-4" />
</header>

<nav
:aria-label="$t('nav.popular_packages')"
class="pt-4 pb-36 sm:pb-40 text-center motion-safe:animate-fade-in motion-safe:animate-fill-both max-w-xl mx-auto"
style="animation-delay: 0.3s"
>
<ul class="flex flex-wrap items-center justify-center gap-x-6 gap-y-3 list-none m-0 p-0">
<li v-for="framework in SHOWCASED_FRAMEWORKS" :key="framework.name">
<LinkBase :to="packageRoute(framework.package)" class="gap-2 text-sm">
<span
class="home-tag-dot w-1 h-1 rounded-full bg-accent group-hover:bg-fg transition-colors duration-200"
/>
{{ framework.name }}
</LinkBase>
</li>
</ul>
</nav>
<div class="pt-4 pb-36 sm:pb-40 max-w-xl mx-auto">
<ClientOnly>
<nav
v-if="recentItems.length > 0"
aria-labelledby="recently-viewed-label"
class="text-center motion-safe:animate-fade-in motion-safe:animate-fill-both"
style="animation-delay: 0.3s"
>
<div class="flex flex-wrap items-center justify-center gap-x-2 gap-y-3">
<span id="recently-viewed-label" class="text-xs text-fg-subtle tracking-wider">
{{ $t('nav.recently_viewed') }}:
</span>
<ul
class="flex flex-wrap items-center justify-center gap-x-4 gap-y-3 list-none m-0 p-0"
>
<li v-for="item in recentItems" :key="`${item.type}-${item.name}`">
<LinkBase :to="recentItemRoute(item)" class="text-sm">
{{ item.label }}
</LinkBase>
</li>
</ul>
</div>
</nav>
</ClientOnly>
</div>
</section>

<section class="border-t border-border py-24 bg-bg-subtle/10">
Expand All @@ -132,13 +155,3 @@ defineOgImageComponent('Default', {
</section>
</main>
</template>

<style scoped>
/* Windows High Contrast Mode support */
@media (forced-colors: active) {
.home-tag-dot {
forced-color-adjust: none;
background-color: CanvasText;
}
}
</style>
13 changes: 13 additions & 0 deletions app/pages/org/[org].vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ watch(orgName, () => {
currentPage.value = 1
})

if (import.meta.client) {
const { trackRecentView } = useRecentlyViewed()
watch(
() => [status.value, orgName.value] as const,
([s, name]) => {
if (s === 'success') {
trackRecentView({ type: 'org', name, label: `@${name}` })
}
},
{ immediate: true },
)
}

// Handle filter chip removal
function handleClearFilter(chip: FilterChip) {
clearFilter(chip)
Expand Down
13 changes: 13 additions & 0 deletions app/pages/package/[[org]]/[name].vue
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,19 @@ onKeyStroke(
)

const showSkeleton = shallowRef(false)

if (import.meta.client) {
const { trackRecentView } = useRecentlyViewed()
watch(
() => [status.value, packageName.value] as const,
([s, name]) => {
if (s === 'success') {
trackRecentView({ type: 'package', name, label: name })
}
},
{ immediate: true },
)
}
</script>

<template>
Expand Down
13 changes: 13 additions & 0 deletions app/pages/~[username]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ watch(username, () => {
sortOption.value = 'downloads'
})

if (import.meta.client) {
const { trackRecentView } = useRecentlyViewed()
watch(
() => [status.value, username.value] as const,
([s, name]) => {
if (s === 'success') {
trackRecentView({ type: 'user', name, label: `~${name}` })
}
},
{ immediate: true },
)
}

useSeoMeta({
title: () => `~${username.value} - npmx`,
ogTitle: () => `~${username.value} - npmx`,
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "الصفحة الرئيسية",
"popular_packages": "الحزم الشائعة",
"settings": "الإعدادات",
"compare": "مقارنة",
"back": "عودة",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/az-AZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"nav": {
"main_navigation": "Əsas",
"popular_packages": "Populyar paketlər",
"settings": "tənzimləmələr",
"back": "geri"
},
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/bg-BG.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "Главна",
"popular_packages": "Популярни пакети",
"settings": "настройки",
"compare": "сравняване",
"back": "назад",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/bn-IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
},
"nav": {
"main_navigation": "প্রধান",
"popular_packages": "জনপ্রিয় প্যাকেজগুলি",
"settings": "সেটিংস",
"compare": "তুলনা করুন",
"back": "পিছনে",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/cs-CZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "Hlavní",
"popular_packages": "Populární balíčky",
"settings": "nastavení",
"compare": "porovnat",
"back": "zpět",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "Hauptnavigation",
"popular_packages": "Beliebte Pakete",
"settings": "Einstellungen",
"compare": "Vergleichen",
"back": "Zurück",
Expand Down
2 changes: 1 addition & 1 deletion i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"nav": {
"main_navigation": "Main",
"popular_packages": "Popular packages",
"recently_viewed": "recently viewed",
"settings": "settings",
"compare": "compare",
"back": "back",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "Principal",
"popular_packages": "Paquetes populares",
"settings": "configuración",
"compare": "comparar",
"back": "atrás",
Expand Down
2 changes: 1 addition & 1 deletion i18n/locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"nav": {
"main_navigation": "Barre de navigation",
"popular_packages": "Paquets populaires",
"recently_viewed": "consultés récemment",
"settings": "paramètres",
"compare": "comparer",
"back": "Retour",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/hi-IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
},
"nav": {
"main_navigation": "मुख्य",
"popular_packages": "लोकप्रिय पैकेज",
"settings": "सेटिंग्स",
"compare": "तुलना करें",
"back": "वापस",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/hu-HU.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"nav": {
"main_navigation": "Főmenü",
"popular_packages": "Népszerű csomagok",
"settings": "beállítások",
"back": "vissza"
},
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/id-ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
},
"nav": {
"main_navigation": "Utama",
"popular_packages": "Paket populer",
"settings": "pengaturan",
"compare": "bandingkan",
"back": "kembali",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
},
"nav": {
"main_navigation": "Principale",
"popular_packages": "Pacchetti popolari",
"settings": "impostazioni",
"compare": "confronta",
"back": "indietro",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "メイン",
"popular_packages": "人気のパッケージ",
"settings": "設定",
"compare": "比較",
"back": "戻る",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/mr-IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"nav": {
"main_navigation": "मुख्य",
"popular_packages": "लोकप्रिय पॅकेजेस",
"settings": "सेटिंग्ज",
"compare": "तुलना करा",
"back": "मागे",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/nb-NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "Hovedmeny",
"popular_packages": "Populære pakker",
"settings": "innstillinger",
"compare": "sammenlign",
"back": "tilbake",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/ne-NP.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
},
"nav": {
"main_navigation": "मुख्य",
"popular_packages": "लोकप्रिय प्याकेजहरू",
"settings": "सेटिङ्स",
"compare": "तुलना",
"back": "पछाडि",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "Główne",
"popular_packages": "Popularne pakiety",
"settings": "ustawienia",
"compare": "porównaj",
"back": "wstecz",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
},
"nav": {
"main_navigation": "Principal",
"popular_packages": "Pacotes populares",
"settings": "configurações",
"compare": "comparar",
"back": "voltar",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"nav": {
"main_navigation": "Главное",
"popular_packages": "Популярные пакеты",
"settings": "настройки",
"back": "назад"
},
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/ta-IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "முதன்மை",
"popular_packages": "பிரபலமான தொகுப்புகள்",
"settings": "அமைப்புகள்",
"compare": "ஒப்பிடு",
"back": "பின்செல்",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/te-IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
},
"nav": {
"main_navigation": "ప్రధాన",
"popular_packages": "జనాదరణ ప్యాకేజ్‌లు",
"settings": "సెట్టింగ్‌లు",
"compare": "పోల్చండి",
"back": "వెనక్కి",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/uk-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "Головна",
"popular_packages": "Популярні пакети",
"settings": "параметри",
"compare": "порівняти",
"back": "назад",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "主页",
"popular_packages": "热门软件包",
"settings": "设置",
"compare": "比较包",
"back": "返回",
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
"nav": {
"main_navigation": "首頁",
"popular_packages": "熱門套件",
"settings": "設定",
"compare": "比較",
"back": "返回",
Expand Down
2 changes: 1 addition & 1 deletion i18n/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"main_navigation": {
"type": "string"
},
"popular_packages": {
"recently_viewed": {
"type": "string"
},
"settings": {
Expand Down
Loading
Loading