Skip to content

Commit

Permalink
feat(web): add event counter
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrnt committed Sep 11, 2024
1 parent eb6c945 commit b348c5e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 28 deletions.
6 changes: 0 additions & 6 deletions apps/web/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ const config = {
},
};

console.log({
"process.env.SENTRY_ORG": process.env.SENTRY_ORG,
"process.env.SENTRY_PROJECT": process.env.SENTRY_PROJECT,

})

const withSentry =
process.env.SENTRY_ORG && process.env.SENTRY_PROJECT
? withSentryConfig
Expand Down
15 changes: 0 additions & 15 deletions apps/web/public/img/companies/mavenoid.svg

This file was deleted.

28 changes: 28 additions & 0 deletions apps/web/src/components/EventCounter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {} from "react";
import { motion, AnimatePresence } from "framer-motion";
import { trpc } from "utils/trpc";

export function EventCounter() {
const { data } = trpc.events.getEventCount.useQuery();

return (
<div className="p-8 text-xl font-bold text-primary mx-auto flex space-x-1">
<AnimatePresence mode="popLayout">
<motion.span
initial={{ y: 20, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
exit={{ y: -20, opacity: 0 }}
transition={{ duration: 0.3 }}
aria-live="polite"
>
{new Intl.NumberFormat("en", { notation: "compact" }).format(
data ?? 0
)}
</motion.span>
</AnimatePresence>
<span className="w-full text-white">
Events processed and counting...
</span>
</div>
);
}
7 changes: 1 addition & 6 deletions apps/web/src/components/UsedBy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Image from "next/image";
import Link from "next/link";
import DynabaseLogo from "../../public/img/companies/dynabase.svg";
import IgusLogo from "../../public/img/companies/igus.svg";
import MavenoidLogo from "../../public/img/companies/mavenoid.svg";

import RBTXLogo from "../../public/img/companies/rbtx.svg";

const COMPANIES = [
Expand All @@ -21,11 +21,6 @@ const COMPANIES = [
logo: DynabaseLogo,
companyUrl: "https://dynabase.de/",
},
{
name: "Mavenoid",
logo: MavenoidLogo,
companyUrl: "https://mavenoid.com/",
},
] satisfies Array<{
logo: React.ReactNode;
name: string;
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { twMerge } from "tailwind-merge";
import { generateCodeSnippets } from "utils/snippets";
import abbyScreenshot from "../../public/screenshot.png";
import type { NextPageWithLayout } from "./_app";
import { EventCounter } from "components/EventCounter";

const { useAbby, AbbyProvider, useFeatureFlag, __abby__, withDevtools } =
createAbby({
Expand Down Expand Up @@ -137,6 +138,7 @@ const Home: NextPageWithLayout<
Start free, scale at a fair price.
</span>
</div>
<EventCounter />
{heroMediaVariant === "Image" && (
<Image
src={abbyScreenshot}
Expand Down
19 changes: 18 additions & 1 deletion apps/web/src/server/trpc/router/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { groupBy, uniqBy } from "lodash-es";
import { EventService } from "server/services/EventService";
import { ProjectService } from "server/services/ProjectService";
import { z } from "zod";
import { protectedProcedure, router } from "../trpc";
import { protectedProcedure, publicProcedure, router } from "../trpc";
import { AbbyEventType } from "@tryabby/core";
import dayjs from "dayjs";
import { getBaseEventsByInterval, TIME_INTERVAL } from "lib/events";
import memoize from "memoize";
import type { Context } from "../context";

export const getEventData = memoize(
async (testId: string, interval: string, potentialVariants: string[]) => {
Expand Down Expand Up @@ -325,4 +326,20 @@ export const eventRouter = router({
)),
};
}),
getEventCount: publicProcedure.query(async ({ ctx }) => {
return await getTotalEventCount(ctx);
}),
});

const getTotalEventCount = memoize(
async (ctx: Context) => {
const [eventCount, apiRequestCount] = await Promise.all([
ctx.prisma.event.count(),
ctx.prisma.apiRequest.count(),
]);
return eventCount + apiRequestCount;
},
{
maxAge: 1000 * 60,
}
);

0 comments on commit b348c5e

Please sign in to comment.