fix: add npmPublishedAt to API response and add null safety for dates

This commit is contained in:
Ajax Davis 2025-12-16 12:49:53 +10:00
parent ad694e27e1
commit 6ccb5fbd79
3 changed files with 10 additions and 4 deletions

1
apps/web/.gitignore vendored
View file

@ -1 +1,2 @@
.vercel
.env*.local

View file

@ -301,6 +301,7 @@ export async function GET(request: NextRequest) {
npmHomepage: true,
npmLicense: true,
npmKeywords: true,
npmPublishedAt: true,
category: true,
env: true,
frameworks: true,

View file

@ -51,7 +51,9 @@ function sortTools(tools: Tool[], sortBy: SortOption): Tool[] {
return bDownloads - aDownloads;
}
// Sort by recent (createdAt descending)
return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
const aTime = a.createdAt ? new Date(a.createdAt).getTime() : 0;
const bTime = b.createdAt ? new Date(b.createdAt).getTime() : 0;
return bTime - aTime;
});
}
@ -336,9 +338,11 @@ export default function ToolSearchPage(): React.ReactElement {
showCopy={true}
/>
</div>
<div className="text-xs text-foreground-tertiary">
Published {formatTimeAgo(tool.package.npmPublishedAt)}
</div>
{tool.package.npmPublishedAt && (
<div className="text-xs text-foreground-tertiary">
Published {formatTimeAgo(tool.package.npmPublishedAt)}
</div>
)}
</div>
</CardContent>
</Card>