-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from YoubetDao/feature/dashboard-total-issue
feat: issue completion leaderboard
- Loading branch information
Showing
6 changed files
with
119 additions
and
113 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,21 +1,12 @@ | ||
import { Button } from '@/components/ui/button' | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
// import { signIn } from 'next-auth/react' | ||
// import { useSearchParams } from 'next/navigation' | ||
import { useLocation } from 'react-router-dom' | ||
import { useState } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import * as z from 'zod' | ||
import { Icons } from '@/components/icons' | ||
// import GithubSignInButton from '../github-auth-button' | ||
|
||
const CLIENT_ID = 'Ov23li86Nz0RcXbj54Z5' | ||
const REDIRECT_URI = 'http://localhost:3000/auth/github/callback' | ||
|
||
const signIn = (...args: unknown[]) => { | ||
location.href = '/' | ||
} | ||
|
||
const githubOAuth = () => { | ||
window.location.href = `http://github.com/login/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=user:email` | ||
} | ||
|
@@ -32,31 +23,7 @@ const GithubSignInButton = () => { | |
) | ||
} | ||
|
||
const formSchema = z.object({ | ||
email: z.string().email({ message: 'Enter a valid email address' }), | ||
}) | ||
|
||
type UserFormValue = z.infer<typeof formSchema> | ||
|
||
export default function UserAuthForm() { | ||
const searchParams = new URLSearchParams(useLocation().search) | ||
const callbackUrl = searchParams.get('callbackUrl') | ||
const [loading, setLoading] = useState(false) | ||
const defaultValues = { | ||
email: '[email protected]', | ||
} | ||
const form = useForm<UserFormValue>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues, | ||
}) | ||
|
||
const onSubmit = async (data: UserFormValue) => { | ||
signIn('credentials', { | ||
email: data.email, | ||
callbackUrl: callbackUrl ?? '/dashboard', | ||
}) | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="relative"> | ||
|
This file contains 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,74 @@ | ||
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<Issue[]>([]) | ||
const [assigneeStats, setAssigneeStats] = useState<{ | ||
[key: string]: { avatarSrc: string; name: string; html: string; completedTasks: number } | ||
}>({}) | ||
const [openedCount, setOpenedCount] = useState<number>(0) | ||
const [closedCount, setClosedCount] = useState<number>(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 ( | ||
<Card className="col-span-4 md:col-span-3"> | ||
<CardHeader> | ||
<CardTitle>Issue Completion Leaderboard</CardTitle> | ||
<CardDescription> | ||
Opened: {openedCount} Closed: {closedCount} | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="space-y-8"> | ||
{Object.values(assigneeStats).map((assignee, index) => ( | ||
<LeaderboardRow | ||
key={index} | ||
avatarSrc={assignee.avatarSrc} | ||
name={assignee.name} | ||
html={assignee.html} | ||
completedTasks={assignee.completedTasks} | ||
/> | ||
))} | ||
</div> | ||
</CardContent> | ||
</Card> | ||
) | ||
} |
This file contains 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,26 @@ | ||
import React from 'react' | ||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' | ||
interface LeaderboardRowProps { | ||
avatarSrc: string | ||
name: string | ||
html: string | ||
completedTasks: number | ||
} | ||
|
||
const LeaderboardRow: React.FC<LeaderboardRowProps> = ({ avatarSrc, name, html, completedTasks }) => { | ||
return ( | ||
<div className="flex items-center"> | ||
<Avatar className="h-9 w-9"> | ||
<AvatarImage src={avatarSrc} alt="Avatar" /> | ||
<AvatarFallback>{name.charAt(0)}</AvatarFallback> | ||
</Avatar> | ||
<div className="ml-4 space-y-1"> | ||
<p className="text-sm font-medium leading-none">{name}</p> | ||
<p className="text-sm text-muted-foreground">{html}</p> | ||
</div> | ||
<div className="ml-auto font-medium">{completedTasks} </div> | ||
</div> | ||
) | ||
} | ||
|
||
export default LeaderboardRow |
This file was deleted.
Oops, something went wrong.
This file contains 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 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