Skip to content

Commit b402561

Browse files
committed
chore: last updated on
1 parent 1ed8ffe commit b402561

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

web/src/pages/Home.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Spinner } from "~/components/ui/spinner";
77
import { supabase } from "~/supabase/supabaseClient";
88

99
import { CompanyCarousel } from "~/components/CompanyCarousel";
10+
import { Badge } from "~/components/ui/badge";
1011

1112
const CACHE_KEY = "home_stats_cache";
1213
const CACHE_DURATION = 1000 * 60 * 15; // 15 min
@@ -22,6 +23,8 @@ export default function Home() {
2223
const [session, setSession] = useState<boolean>(false);
2324

2425
/* --------------------- FETCH STATS -------------------- */
26+
const [lastDbUpdate, setLastDbUpdate] = useState<string | null>(null);
27+
2528
useEffect(() => {
2629
async function fetchStats() {
2730
if (memoryCache) {
@@ -36,33 +39,49 @@ export default function Home() {
3639
if (Date.now() - parsed.timestamp < CACHE_DURATION) {
3740
memoryCache = parsed.data;
3841
setStats(parsed.data);
42+
if (parsed.lastDbUpdate) setLastDbUpdate(parsed.lastDbUpdate);
3943
setLoading(false);
4044
return;
4145
}
4246
}
4347

4448
const [companiesRes, problemsRes] = await Promise.all([
4549
supabase.from("companies").select("*", { count: "exact", head: true }),
46-
4750
supabase.from("problems").select("*", { count: "exact", head: true }),
51+
supabase
52+
.from("problems")
53+
.select("updated_at")
54+
.order("updated_at", { ascending: false })
55+
.limit(1)
56+
.single(),
4857
]);
4958

5059
const data = {
5160
companies: companiesRes.count ?? 0,
5261
problems: problemsRes.count ?? 0,
5362
};
5463

64+
const lastDbUpdateRes = await supabase
65+
.from("app_metadata")
66+
.select("last_db_update")
67+
.eq("id", 1)
68+
.single();
69+
70+
const lastDbUpdate = lastDbUpdateRes.data?.last_db_update ?? null;
71+
5572
memoryCache = data;
5673

5774
localStorage.setItem(
5875
CACHE_KEY,
5976
JSON.stringify({
6077
data,
78+
lastDbUpdate,
6179
timestamp: Date.now(),
6280
}),
6381
);
6482

6583
setStats(data);
84+
setLastDbUpdate(lastDbUpdate);
6685
setLoading(false);
6786
}
6887
fetchStats();
@@ -84,7 +103,7 @@ export default function Home() {
84103

85104
return (
86105
<main className="flex h-[calc(100vh-var(--header-height,4rem))] flex-col items-center justify-between">
87-
<div className="flex w-full flex-col items-center gap-4 px-6 py-16">
106+
<div className="flex w-full flex-col items-center gap-4 px-6 pt-16">
88107
<div className="font-geist text-primary relative flex flex-col items-start text-3xl font-semibold sm:text-4xl md:text-5xl dark:drop-shadow-[0_4px_8px_rgba(0,0,0,0.5)]">
89108
<span>Company-Wise</span>
90109
<span>
@@ -163,7 +182,7 @@ export default function Home() {
163182
</div>
164183
<div className="flex w-full flex-1 flex-col">
165184
{/* -------------------- STATS SECTION ------------------- */}
166-
<div className="w-full py-8">
185+
<div className="font-geist flex w-full flex-col items-center gap-4">
167186
<div className="mx-auto flex max-w-4xl justify-center gap-16 text-center">
168187
{loading ? (
169188
<div className="text-muted-foreground text-sm">
@@ -191,6 +210,23 @@ export default function Home() {
191210
</>
192211
)}
193212
</div>
213+
{!loading && <div className="flex flex-row items-center gap-2">
214+
<div className="text-muted-foreground flex gap-x-1 text-sm">
215+
Problems Last Updated on{" "}
216+
<Badge
217+
variant="default"
218+
className="bg-purple-50 px-1.5 text-purple-700 dark:bg-purple-950 dark:text-purple-300"
219+
>
220+
{lastDbUpdate
221+
? new Date(lastDbUpdate).toLocaleDateString("en-US", {
222+
month: "short",
223+
day: "numeric",
224+
year: "numeric",
225+
})
226+
: "—"}
227+
</Badge>
228+
</div>
229+
</div>}
194230
</div>
195231
</div>
196232
</div>

0 commit comments

Comments
 (0)