2024-08-16 15:05:04 +08:00
|
|
|
|
import { Card, Select, Timeline, TimelineItemProps } from 'antd';
|
2024-08-16 13:00:02 +08:00
|
|
|
|
import { useEffect, useState } from 'react';
|
2024-08-16 13:37:56 +08:00
|
|
|
|
import GitHubCalendar from 'react-github-calendar';
|
2024-08-16 13:00:02 +08:00
|
|
|
|
import Title from '@/components/Title';
|
2024-08-16 13:17:03 +08:00
|
|
|
|
import dayjs from 'dayjs'
|
|
|
|
|
|
|
|
|
|
|
|
interface Commit {
|
|
|
|
|
|
commit: {
|
|
|
|
|
|
author: { date: string },
|
|
|
|
|
|
message: string
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-16 13:00:02 +08:00
|
|
|
|
|
|
|
|
|
|
const Home = () => {
|
2024-08-16 15:05:04 +08:00
|
|
|
|
const [year, setYear] = useState<number>(new Date().getFullYear())
|
|
|
|
|
|
const [yearList, setYearList] = useState<{ value: number, label: string }[]>([])
|
|
|
|
|
|
|
2024-08-16 13:00:02 +08:00
|
|
|
|
const [blog_iterativeRecording, setBlog_IterativeRecording] = useState<TimelineItemProps[]>([])
|
|
|
|
|
|
const [admin_iterativeRecording, setAdmin_IterativeRecording] = useState<TimelineItemProps[]>([])
|
|
|
|
|
|
const [server_iterativeRecording, setServer_IterativeRecording] = useState<TimelineItemProps[]>([])
|
|
|
|
|
|
|
|
|
|
|
|
// 从github获取最近10次迭代记录
|
|
|
|
|
|
const getCommitData = async (project: string) => {
|
|
|
|
|
|
const res = await fetch(`https://api.github.com/repos/LiuYuYang01/${project}/commits?per_page=10`)
|
|
|
|
|
|
const data = await res.json()
|
2024-08-16 13:17:03 +08:00
|
|
|
|
const result = data.map((item: Commit) => (
|
|
|
|
|
|
{
|
|
|
|
|
|
label: dayjs(item.commit.author.date).format("YYYY-MM-DD HH:mm:ss"),
|
|
|
|
|
|
children: item.commit.message
|
|
|
|
|
|
}
|
|
|
|
|
|
))
|
2024-08-16 13:00:02 +08:00
|
|
|
|
|
|
|
|
|
|
sessionStorage.setItem('blog_project_iterative', JSON.stringify(result))
|
2024-10-26 18:11:19 +08:00
|
|
|
|
project === "ThriveX-Blog" && setBlog_IterativeRecording(result)
|
2024-08-16 13:00:02 +08:00
|
|
|
|
|
|
|
|
|
|
sessionStorage.setItem('admin_project_iterative', JSON.stringify(result))
|
2024-10-26 18:11:19 +08:00
|
|
|
|
project === "ThriveX-Admin" && setAdmin_IterativeRecording(result)
|
2024-08-16 13:00:02 +08:00
|
|
|
|
|
|
|
|
|
|
sessionStorage.setItem('server_project_iterative', JSON.stringify(result))
|
2024-10-26 18:11:19 +08:00
|
|
|
|
project === "ThriveX-Service" && setServer_IterativeRecording(result)
|
2024-08-16 13:00:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-08-16 15:05:04 +08:00
|
|
|
|
// 获取当前年份
|
|
|
|
|
|
const currentYear = dayjs().year();
|
|
|
|
|
|
// 生成最近10年的年份数组
|
|
|
|
|
|
const yearList = Array.from({ length: 10 }, (_, i) => currentYear - i);
|
|
|
|
|
|
setYearList(yearList.map(item => ({ value: item, label: item + '' })))
|
|
|
|
|
|
|
2024-08-16 13:00:02 +08:00
|
|
|
|
// 如果缓存中有值就无需重新调接口
|
|
|
|
|
|
const blog_project_iterative = JSON.parse(sessionStorage.getItem('blog_project_iterative') || '[]')
|
2024-10-26 18:11:19 +08:00
|
|
|
|
blog_project_iterative.length ? setBlog_IterativeRecording(blog_project_iterative) : getCommitData("ThriveX-Blog")
|
2024-08-16 13:00:02 +08:00
|
|
|
|
|
|
|
|
|
|
const admin_project_iterative = JSON.parse(sessionStorage.getItem('admin_project_iterative') || '[]')
|
2024-10-26 18:11:19 +08:00
|
|
|
|
admin_project_iterative.length ? setAdmin_IterativeRecording(admin_project_iterative) : getCommitData("ThriveX-Admin")
|
2024-08-16 13:00:02 +08:00
|
|
|
|
|
|
|
|
|
|
const server_project_iterative = JSON.parse(sessionStorage.getItem('server_project_iterative') || '[]')
|
2024-10-26 18:11:19 +08:00
|
|
|
|
server_project_iterative.length ? setServer_IterativeRecording(server_project_iterative) : getCommitData("ThriveX-Service")
|
2024-08-16 13:00:02 +08:00
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Title value='项目迭代记录'></Title>
|
|
|
|
|
|
|
|
|
|
|
|
<Card className='mt-2'>
|
2024-08-16 15:05:04 +08:00
|
|
|
|
<div className='flex flex-col items-center mt-2 mb-22'>
|
|
|
|
|
|
<div className='ml-5 mb-6'>
|
|
|
|
|
|
<span>年份切换:</span>
|
|
|
|
|
|
|
|
|
|
|
|
<Select
|
|
|
|
|
|
size='small'
|
|
|
|
|
|
defaultValue={year}
|
|
|
|
|
|
options={yearList}
|
|
|
|
|
|
onChange={setYear}
|
|
|
|
|
|
className='w-20'
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<GitHubCalendar username="liuyuyang01" year={year} />
|
2024-08-16 13:37:56 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2024-08-16 13:17:03 +08:00
|
|
|
|
<div className='flex justify-between'>
|
|
|
|
|
|
<div className='flex-1'>
|
2024-10-26 18:11:19 +08:00
|
|
|
|
<h3 className='text-xl text-center pb-6 font-bold text-gradient block'>ThriveX-Blog</h3>
|
2024-08-16 13:17:03 +08:00
|
|
|
|
<Timeline mode="left" items={blog_iterativeRecording} />
|
2024-08-16 13:00:02 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2024-08-16 13:17:03 +08:00
|
|
|
|
<div className='flex-1'>
|
2024-10-26 18:11:19 +08:00
|
|
|
|
<h3 className='text-xl text-center pb-6 font-bold text-gradient block'>ThriveX-Admin</h3>
|
2024-08-16 13:17:03 +08:00
|
|
|
|
<Timeline mode="left" items={admin_iterativeRecording} />
|
2024-08-16 13:00:02 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2024-08-16 13:17:03 +08:00
|
|
|
|
<div className='flex-1'>
|
2024-10-26 18:11:19 +08:00
|
|
|
|
<h3 className='text-xl text-center pb-6 font-bold text-gradient block'>ThriveX-Service</h3>
|
2024-08-16 13:17:03 +08:00
|
|
|
|
<Timeline mode="left" items={server_iterativeRecording} />
|
2024-08-16 13:00:02 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default Home;
|