Skip to content

Commit

Permalink
Add glossary stats to /cms
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed Jun 16, 2024
1 parent 60507c1 commit 49cf7b6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export default {
articles: "Total Articles",
likes: "Total Likes",
tutorials: "Total Tutorials",
glossary: "Total Glossary Terms",
},
viewAll: "View all",
},
Expand Down
25 changes: 14 additions & 11 deletions app/routes/_.cms._index/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ import { Tables, database } from "~/services/db.server";
export async function queryStats(context: AppLoadContext) {
let db = database(context.db);

let [articles, likes, tutorials] = await Promise.all(
["article" as const, "like" as const, "tutorial" as const].map(
async (type) => {
let results = await db
.select({ value: count() })
.from(Tables.posts)
.where(eq(Tables.posts.type, type));
return results.at(0)?.value ?? 0;
},
),
let [articles, likes, tutorials, glossary] = await Promise.all(
[
"article" as const,
"like" as const,
"tutorial" as const,
"glossary" as const,
].map(async (type) => {
let results = await db
.select({ value: count() })
.from(Tables.posts)
.where(eq(Tables.posts.type, type));
return results.at(0)?.value ?? 0;
}),
);

return { articles, likes, tutorials };
return { articles, likes, tutorials, glossary };
}

export async function createQuickLike(
Expand Down
9 changes: 7 additions & 2 deletions app/routes/_.cms._index/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ export function Stats() {
path: "tutorials",
stat: loaderData.stats.tutorials,
},
];
{
name: t("total.glossary"),
path: "glossary",
stat: loaderData.stats.glossary,
},
] satisfies Array<{ name: string; path: string; stat: number }>;

return (
<div className="flex flex-col gap-5">
<Heading className="text-base font-semibold leading-6 text-zinc-900 dark:text-zinc-50">
{t("title")}
</Heading>

<dl className="grid grid-cols-1 gap-5 sm:grid-cols-3">
<dl className="grid grid-cols-1 gap-5 sm:grid-cols-4">
{stats.map((item) => (
<div
key={item.name}
Expand Down

0 comments on commit 49cf7b6

Please sign in to comment.