feat(don): add goal reset function
Build and Push Image / build-backend (push) Successful in 6m23s
Build and Push Image / build-frontend (push) Successful in 3m36s
Build and Push Image / push (push) Successful in 1m38s

This commit is contained in:
2026-06-16 06:52:07 +07:00 Unverified
parent 414f407d08
commit e483360b5b
6 changed files with 42 additions and 6 deletions
+5 -2
View File
@@ -1,15 +1,18 @@
"use server";
import { getArtifactConfig } from "@/lib/api";
import { db } from "@/lib/db";
import { donations, settings } from "@/lib/db/schema";
import { sum } from "drizzle-orm";
import { gt, sum } from "drizzle-orm";
export async function getDonateBar() {
const { donateGoalStarting } = await getArtifactConfig();
const [{ amount }] = await db
.select({
amount: sum(donations.amount),
})
.from(donations);
.from(donations)
.where(gt(donations.created, donateGoalStarting ?? new Date(0)));
const [{ goal }] = await db
.select({ goal: settings.donateGoal })
.from(settings)
+7 -3
View File
@@ -4,6 +4,7 @@ import { sse } from "@/lib/db/sse-endpoints";
import { useEffect, useRef, useState } from "react";
import { getDonateBar } from "./api";
import { motion } from "motion/react";
import { pausePass } from "@/lib/utils";
type Data = Awaited<ReturnType<typeof getDonateBar>>;
@@ -15,7 +16,9 @@ export default function TopDonateWidget() {
useEffect(() => {
async function update() {
void getDonateBar().then(setBar);
if (textRef.current)
void getDonateBar().then(pausePass(10000)).then(setBar);
else void getDonateBar().then(setBar);
}
queueMicrotask(update);
const { clean } = sse.donate.subMany({
@@ -74,13 +77,14 @@ export default function TopDonateWidget() {
return () => window.removeEventListener("resize", onResize);
}, [bar]);
return bar && bar.amount !== null && bar.goal ? (
return bar ? (
<div className="relative h-full max-h-[20svw] w-full rounded-full bg-[#252525]">
<div className="absolute inset-2 rounded-full bg-black" />
<motion.div
className="absolute inset-1.5 rounded-full bg-linear-to-b from-[#FD0000] to-[#830000]"
animate={{
width: `calc(6px + ${Math.min(1, Number(bar.amount) / bar.goal)} * (100% - 12px))`,
width: `calc(${Math.min(1, Number(bar.amount ?? "0") / (bar.goal ?? 1)) * 100}% - ${Math.min(1, Number(bar.amount ?? "0") / (bar.goal ?? 1)) * 12}px)`,
// width: `calc(6px + ${Math.min(1, Number(bar.amount) / bar.goal)} * (100% - 12px))`,
}}
initial={{
width: 0,