-
Notifications
You must be signed in to change notification settings - Fork 118
feat: open page #34 #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IkramBagban
wants to merge
10
commits into
code100x:main
Choose a base branch
from
IkramBagban:feat/open-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ca19603
feat: add endpoint for open statistics and daily metrics
IkramBagban 92e0944
feat: add database seeding script
IkramBagban 4f85eae
feat: add Open page and add stats
IkramBagban cafc242
feat: refactor Open page layout and enhance positions a bit
IkramBagban 5907475
feat: add daily charts in open page
IkramBagban f8f7bdb
refactor: add types & clean the code
IkramBagban 5c7caa0
feat: add incremental site regenration
IkramBagban 0a79653
Merge branch 'main' of https://github.com/code100x/photo-ai into feat…
IkramBagban bed8053
Merge branch 'main' of https://github.com/code100x/photo-ai into feat…
IkramBagban 70657be
fix: revalidating stats data every 24h
IkramBagban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
import { BACKEND_URL } from "../config"; | ||
import Heading from "@/components/open/Heading"; | ||
import StatCards from "@/components/open/StatCards"; | ||
import OpenCharts from "@/components/open/OpenCharts"; | ||
|
||
async function getStatsData() { | ||
const response = await fetch(`${BACKEND_URL}/open`, { | ||
next: { revalidate: 60 * 60 * 24 }, | ||
}); | ||
return response.json(); | ||
} | ||
|
||
async function OpenPage() { | ||
const statsData = await getStatsData(); | ||
|
||
return ( | ||
<div className="min-h-screen bg-background py-20 px-4 sm:px-6 lg:px-8"> | ||
<div className="max-w-7xl mx-auto"> | ||
<Heading className="text-4xl font-bold text-foreground text-center mb-12 "> | ||
Open Stats | ||
</Heading> | ||
|
||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-6 mb-16"> | ||
<StatCards stats={statsData?.data || {}} /> | ||
</div> | ||
|
||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8"> | ||
<OpenCharts statsData={statsData?.data || []} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default OpenPage; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use client"; | ||
import React, { ReactNode } from "react"; | ||
import { motion } from "framer-motion"; | ||
const Heading: React.FC<{ children: ReactNode; className?: string }> = ({ | ||
children, | ||
className | ||
}) => { | ||
return ( | ||
<motion.h1 | ||
initial={{ opacity: 0, y: -20 }} | ||
animate={{ opacity: 1, y: 0 }} | ||
transition={{ duration: 0.6, ease: "easeOut" }} | ||
className={className || ""} | ||
> | ||
{children} | ||
</motion.h1> | ||
); | ||
}; | ||
|
||
export default Heading; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react"; | ||
import { motion } from "framer-motion"; | ||
const Loader = () => { | ||
return ( | ||
<div className="min-h-screen flex items-center justify-center bg-background"> | ||
<motion.div | ||
animate={{ rotate: 360 }} | ||
transition={{ duration: 1, repeat: Infinity, ease: "linear" }} | ||
className="w-12 h-12 border-4 border-primary border-t-transparent rounded-full" | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Loader; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
|
||
interface Props { | ||
className? : string, | ||
children: React.ReactNode | ||
} | ||
export const Card:React.FC<Props> = ({ className, children }) => ( | ||
<div className={`rounded-lg border p-4 ${className}`}>{children}</div> | ||
); | ||
|
||
export const CardHeader:React.FC<Props> = ({ className, children }) => ( | ||
<div className={`pb-2 ${className}`}>{children}</div> | ||
); | ||
|
||
export const CardTitle:React.FC<Props> = ({ className, children }) => ( | ||
<h3 className={`text-lg font-semibold ${className}`}>{children}</h3> | ||
); | ||
|
||
export const CardContent:React.FC<Props> = ({ className, children }) => ( | ||
<div className={className}>{children}</div> | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
"use client"; | ||
|
||
import { motion } from "framer-motion"; | ||
import { | ||
LineChart, | ||
Line, | ||
XAxis, | ||
YAxis, | ||
CartesianGrid, | ||
Tooltip, | ||
ResponsiveContainer, | ||
} from "recharts"; | ||
import { format } from "date-fns"; | ||
import { Card, CardContent, CardHeader, CardTitle } from "./OpenCardUI"; | ||
import { useTheme } from "next-themes"; | ||
import { StatsData } from "@/types"; | ||
|
||
const chartVariants = { | ||
hidden: { opacity: 0, scale: 0.95 }, | ||
visible: { | ||
opacity: 1, | ||
scale: 1, | ||
transition: { duration: 0.7, ease: "easeOut" }, | ||
}, | ||
}; | ||
|
||
interface CharConfig { | ||
title: string; | ||
data: | ||
| { date: string }[] | ||
| { date: string; count?: number; amount?: number }[]; | ||
key: "count" | "amount"; | ||
color: string; | ||
} | ||
|
||
const OpenCharts: React.FC<{ statsData: StatsData }> = ({ statsData }) => { | ||
const { theme } = useTheme(); | ||
|
||
const chartConfig: CharConfig[] = [ | ||
{ | ||
title: "Daily Users", | ||
data: statsData.charts?.dailyUsers, | ||
key: "count", | ||
color: "#3b82f6", | ||
}, | ||
{ | ||
title: "Daily Trained Models", | ||
data: statsData.charts?.dailyTrainedModels, | ||
key: "count", | ||
color: "#10b981", | ||
}, | ||
{ | ||
title: "Daily Generated Images", | ||
data: statsData.charts?.dailyGeneratedImages, | ||
key: "count", | ||
color: "#f59e0b", | ||
}, | ||
{ | ||
title: "Daily Revenue", | ||
data: statsData.charts?.dailyRevenue, | ||
key: "amount", | ||
color: "#ef4444", | ||
}, | ||
]; | ||
|
||
return (chartConfig || []).map((chart: CharConfig) => ( | ||
<motion.div | ||
key={chart.title} | ||
variants={chartVariants} | ||
initial="hidden" | ||
animate="visible" | ||
> | ||
<Card className="bg-background/80 border-border/30 backdrop-blur-sm"> | ||
<CardHeader> | ||
<CardTitle className="text-lg font-semibold text-foreground"> | ||
{chart.title} | ||
</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="h-80"> | ||
<ResponsiveContainer width="100%" height="100%"> | ||
<LineChart data={chart.data}> | ||
<CartesianGrid | ||
strokeDasharray="3 3" | ||
stroke={theme === "dark" ? "#444" : "#ddd"} | ||
/> | ||
<XAxis | ||
dataKey="date" | ||
tickFormatter={(date) => format(new Date(date), "MMM dd")} | ||
stroke={theme === "dark" ? "#ccc" : "#666"} | ||
/> | ||
<YAxis stroke={theme === "dark" ? "#ccc" : "#666"} /> | ||
<Tooltip | ||
contentStyle={{ | ||
backgroundColor: theme === "dark" ? "#333" : "#fff", | ||
border: "none", | ||
borderRadius: "8px", | ||
boxShadow: "0 4px 6px rgba(0,0,0,0.1)", | ||
}} | ||
/> | ||
<Line | ||
type="monotone" | ||
dataKey={chart.key} | ||
stroke={chart.color} | ||
strokeWidth={2} | ||
dot={{ r: 4 }} | ||
activeDot={{ r: 6 }} | ||
/> | ||
</LineChart> | ||
</ResponsiveContainer> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
</motion.div> | ||
)); | ||
}; | ||
|
||
export default OpenCharts; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this endpoint is doing too many DB calls. Can we make it more optimal?
Also cache this to 1 day intervals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already cached the data and revalidating every hour using ISR let me set it for a day