11<script setup lang="ts">
22import type { NpmSearchResult } from ' ~~/shared/types/npm-registry'
3- import type { ColumnConfig , SortKey , SortOption } from ' ~~/shared/types/preferences'
3+ import type { ColumnConfig , ColumnId , SortKey , SortOption } from ' ~~/shared/types/preferences'
44import { buildSortOption , parseSortOption , toggleDirection } from ' ~~/shared/types/preferences'
55
66const props = defineProps <{
@@ -84,7 +84,7 @@ function toggleSort(id: string) {
8484const { t } = useI18n ()
8585
8686// Map column IDs to i18n keys
87- const columnLabelKey : Record <string , string > = {
87+ const columnLabelKeys : Record <ColumnId , string > = {
8888 name: ' filters.columns.name' ,
8989 version: ' filters.columns.version' ,
9090 description: ' filters.columns.description' ,
@@ -98,6 +98,10 @@ const columnLabelKey: Record<string, string> = {
9898 combinedScore: ' filters.columns.combined_score' ,
9999 security: ' filters.columns.security' ,
100100}
101+
102+ function getColumnLabelKey(id : ColumnId ): string {
103+ return columnLabelKeys [id ]
104+ }
101105 </script >
102106
103107<template >
@@ -126,7 +130,7 @@ const columnLabelKey: Record<string, string> = {
126130 @keydown.space.prevent =" toggleSort('name')"
127131 >
128132 <span class =" inline-flex items-center gap-1" >
129- {{ $t(columnLabelKey[ 'name'] ) }}
133+ {{ $t(getColumnLabelKey( 'name') ) }}
130134 <template v-if =" isSortable (' name' )" >
131135 <span
132136 v-if =" isColumnSorted('name')"
@@ -144,15 +148,15 @@ const columnLabelKey: Record<string, string> = {
144148 scope =" col"
145149 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider"
146150 >
147- {{ $t(columnLabelKey[ 'version'] ) }}
151+ {{ $t(getColumnLabelKey( 'version') ) }}
148152 </th >
149153
150154 <th
151155 v-if =" isColumnVisible('description')"
152156 scope =" col"
153157 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider"
154158 >
155- {{ $t(columnLabelKey[ 'description'] ) }}
159+ {{ $t(getColumnLabelKey( 'description') ) }}
156160 </th >
157161
158162 <th
@@ -177,7 +181,7 @@ const columnLabelKey: Record<string, string> = {
177181 @keydown.space.prevent =" toggleSort('downloads')"
178182 >
179183 <span class =" inline-flex items-center gap-1 justify-end" >
180- {{ $t(columnLabelKey[ 'downloads'] ) }}
184+ {{ $t(getColumnLabelKey( 'downloads') ) }}
181185 <template v-if =" isSortable (' downloads' )" >
182186 <span
183187 v-if =" isColumnSorted('downloads')"
@@ -211,7 +215,7 @@ const columnLabelKey: Record<string, string> = {
211215 @keydown.space.prevent =" toggleSort('updated')"
212216 >
213217 <span class =" inline-flex items-center gap-1" >
214- {{ $t(columnLabelKey[ 'updated'] ) }}
218+ {{ $t(getColumnLabelKey( 'updated') ) }}
215219 <template v-if =" isSortable (' updated' )" >
216220 <span
217221 v-if =" isColumnSorted('updated')"
@@ -229,55 +233,55 @@ const columnLabelKey: Record<string, string> = {
229233 scope =" col"
230234 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider"
231235 >
232- {{ $t(columnLabelKey[ 'maintainers'] ) }}
236+ {{ $t(getColumnLabelKey( 'maintainers') ) }}
233237 </th >
234238
235239 <th
236240 v-if =" isColumnVisible('keywords')"
237241 scope =" col"
238242 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider"
239243 >
240- {{ $t(columnLabelKey[ 'keywords'] ) }}
244+ {{ $t(getColumnLabelKey( 'keywords') ) }}
241245 </th >
242246
243247 <th
244248 v-if =" isColumnVisible('qualityScore')"
245249 scope =" col"
246250 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider text-right"
247251 >
248- {{ $t(columnLabelKey[ 'qualityScore'] ) }}
252+ {{ $t(getColumnLabelKey( 'qualityScore') ) }}
249253 </th >
250254
251255 <th
252256 v-if =" isColumnVisible('popularityScore')"
253257 scope =" col"
254258 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider text-right"
255259 >
256- {{ $t(columnLabelKey[ 'popularityScore'] ) }}
260+ {{ $t(getColumnLabelKey( 'popularityScore') ) }}
257261 </th >
258262
259263 <th
260264 v-if =" isColumnVisible('maintenanceScore')"
261265 scope =" col"
262266 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider text-right"
263267 >
264- {{ $t(columnLabelKey[ 'maintenanceScore'] ) }}
268+ {{ $t(getColumnLabelKey( 'maintenanceScore') ) }}
265269 </th >
266270
267271 <th
268272 v-if =" isColumnVisible('combinedScore')"
269273 scope =" col"
270274 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider text-right"
271275 >
272- {{ $t(columnLabelKey[ 'combinedScore'] ) }}
276+ {{ $t(getColumnLabelKey( 'combinedScore') ) }}
273277 </th >
274278
275279 <th
276280 v-if =" isColumnVisible('security')"
277281 scope =" col"
278282 class =" py-3 px-3 text-xs font-mono font-medium text-fg-muted uppercase tracking-wider"
279283 >
280- {{ $t(columnLabelKey[ 'security'] ) }}
284+ {{ $t(getColumnLabelKey( 'security') ) }}
281285 </th >
282286 </tr >
283287 </thead >
0 commit comments