diff --git a/src/components/issue-completion-leaderboard.tsx b/src/components/issue-completion-leaderboard.tsx deleted file mode 100644 index 4a158d6..0000000 --- a/src/components/issue-completion-leaderboard.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import api from '@/service' -import { Issue } from '@/types' -import { useEffect, useState } from 'react' -import LeaderboardRow from './leaderboard-row' -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' -export function IssueCompletionLeaderboard() { - const [issues, setIssues] = useState([]) - const [assigneeStats, setAssigneeStats] = useState<{ - [key: string]: { avatarSrc: string; name: string; html: string; completedTasks: number } - }>({}) - const [openedCount, setOpenedCount] = useState(0) - const [closedCount, setClosedCount] = useState(0) - - useEffect(() => { - api.fetchIssues('YoubetDao', 'youbet-test-repo').then((data) => { - if (data) { - setIssues(data) - - const stats: { [key: string]: { avatarSrc: string; name: string; html: string; completedTasks: number } } = {} - let opened = 0 - let closed = 0 - - data.forEach((issue) => { - issue.assignees.forEach((assignee) => { - if (!stats[assignee.login]) { - stats[assignee.login] = { - avatarSrc: assignee.avatar_url, - name: assignee.login, - html: assignee.html_url, // 将 email 改为 html 字段 - completedTasks: 0, - } - } - if (issue.state === 'closed') { - stats[assignee.login].completedTasks += 1 - } - }) - if (issue.state === 'closed') { - closed++ - } else { - opened++ - } - }) - - setAssigneeStats(stats) - setOpenedCount(opened) - setClosedCount(closed) - } - }) - }, []) - - return ( - - - Issue Completion Leaderboard - - Opened: {openedCount} Closed: {closedCount} - - - -
- {Object.values(assigneeStats).map((assignee, index) => ( - - ))} -
-
-
- ) -} diff --git a/src/components/task-completion-leaderboard.tsx b/src/components/task-completion-leaderboard.tsx new file mode 100644 index 0000000..8f0d490 --- /dev/null +++ b/src/components/task-completion-leaderboard.tsx @@ -0,0 +1,38 @@ +import LeaderboardRow from './leaderboard-row' +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' +interface AssigneeStats { + [key: string]: { + avatarSrc: string + name: string + html: string + completedTasks: number + } +} + +// 定义 IssueCompletionLeaderboardProps 接口 +interface TaskCompletionLeaderboardProps { + assigneeStats: AssigneeStats +} + +export function TaskCompletionLeaderboard({ assigneeStats }: TaskCompletionLeaderboardProps) { + return ( + + + Task Completion Leaderboard + + +
+ {Object.values(assigneeStats).map((assignee, index) => ( + + ))} +
+
+
+ ) +} diff --git a/src/pages/dashboard/index.tsx b/src/pages/dashboard/index.tsx index 9c096dd..fed4439 100644 --- a/src/pages/dashboard/index.tsx +++ b/src/pages/dashboard/index.tsx @@ -1,127 +1,81 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { ScrollArea } from '@/components/ui/scroll-area' -import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' -import { AreaGraph } from '@/components/charts/AreaGraph' -import { BarGraph } from '@/components/charts/BarGraph' -import { PieGraph } from '@/components/charts/PieGraph' -import { IssueCompletionLeaderboard } from '@/components/issue-completion-leaderboard' +import { Tabs, TabsContent } from '@/components/ui/tabs' +import { useEffect, useState } from 'react' +import api from '@/service' +import { TaskCompletionLeaderboard } from '@/components/task-completion-leaderboard' export default function Dashboard() { + const [assigneeStats, setAssigneeStats] = useState<{ + [key: string]: { avatarSrc: string; name: string; html: string; completedTasks: number } + }>({}) + const [openedCount, setOpenedCount] = useState(0) + const [closedCount, setClosedCount] = useState(0) + + useEffect(() => { + api.fetchIssues('YoubetDao', 'youbet-test-repo').then((data) => { + if (data) { + const stats: { [key: string]: { avatarSrc: string; name: string; html: string; completedTasks: number } } = {} + let opened = 0 + let closed = 0 + console.log(data) + + data.forEach((issue) => { + issue.assignees.forEach((assignee) => { + if (!stats[assignee.login]) { + stats[assignee.login] = { + avatarSrc: assignee.avatar_url, + name: assignee.login, + html: assignee.html_url, // 将 email 改为 html 字段 + completedTasks: 0, + } + } + if (issue.state === 'closed') { + stats[assignee.login].completedTasks += 1 + } + }) + if (issue.state === 'closed') { + closed++ + } else { + opened++ + } + }) + + setAssigneeStats(stats) + setOpenedCount(opened) + setClosedCount(closed) + } + }) + }, []) return ( <>
-
-

Hi, Welcome back 👋

+
+

Hi, Welcome to YouBet Task 👋

- - - Overview - - Analytics - - - -
- - - Total Revenue - - - - - -
$45,231.89
-

+20.1% from last month

-
-
- - - Subscriptions - - - - - - - -
+2350
-

+180.1% from last month

-
-
+ + +
- Sales - - - - + Opened Tasks -
+12,234
-

+19% from last month

+
{openedCount}
- Active Now - - - + Completed Tasks -
+573
-

+201 since last hour

+
{closedCount}
-
-
- -
- -
- -
-
- -
+
+