diff --git a/i18n/en/code.json b/i18n/en/code.json index 13b22dc..b650046 100644 --- a/i18n/en/code.json +++ b/i18n/en/code.json @@ -384,5 +384,14 @@ }, "communityLeaderboard.banner.title": { "message": "Community OpenRank Leaderboard" + }, + "communityLeaderboard.fetchingData": { + "message": "Fetching data..." + }, + "communityLeaderboard.fetchDataError": { + "message": "Error on fetching data" + }, + "communityLeaderboard.noDataForMonth": { + "message": "No data found for this month" } } diff --git a/i18n/zh/code.json b/i18n/zh/code.json index 4fcc024..34ce95c 100644 --- a/i18n/zh/code.json +++ b/i18n/zh/code.json @@ -384,5 +384,14 @@ }, "communityLeaderboard.banner.title": { "message": "OpenRank 贡献度排行榜" + }, + "communityLeaderboard.fetchingData": { + "message": "正在获取数据..." + }, + "communityLeaderboard.fetchDataError": { + "message": "获取数据错误" + }, + "communityLeaderboard.noDataForMonth": { + "message": "当月数据未找到" } } diff --git a/package-lock.json b/package-lock.json index 14fcbaf..ec4a4b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,6 @@ "docusaurus-plugin-image-zoom": "^2.0.0", "echarts": "^5.5.1", "echarts-for-react": "^3.0.2", - "jquery": "^3.7.1", "katex": "^0.16.11", "lodash": "^4.17.21", "prism-react-renderer": "^2.3.1", @@ -37,7 +36,6 @@ "@simbathesailor/use-what-changed": "^2.0.0", "@types/lodash": "^4.17.7", "antd": "^5.20.5", - "moment": "^2.30.1", "typescript": "^5.5.4" }, "engines": { @@ -9310,11 +9308,6 @@ "@sideway/pinpoint": "^2.0.0" } }, - "node_modules/jquery": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz", - "integrity": "sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==" - }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmmirror.com/js-tokens/-/js-tokens-4.0.0.tgz", @@ -12396,6 +12389,8 @@ "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", "dev": true, + "optional": true, + "peer": true, "engines": { "node": "*" } diff --git a/package.json b/package.json index b52c2ce..f6dde35 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "docusaurus-plugin-image-zoom": "^2.0.0", "echarts": "^5.5.1", "echarts-for-react": "^3.0.2", - "jquery": "^3.7.1", "katex": "^0.16.11", "lodash": "^4.17.21", "prism-react-renderer": "^2.3.1", @@ -43,7 +42,6 @@ "@simbathesailor/use-what-changed": "^2.0.0", "@types/lodash": "^4.17.7", "antd": "^5.20.5", - "moment": "^2.30.1", "typescript": "^5.5.4" }, "browserslist": { diff --git a/src/components/DevLeaderboard/Banner.tsx b/src/components/CommunityOpenRankLeaderboard/Banner.tsx similarity index 100% rename from src/components/DevLeaderboard/Banner.tsx rename to src/components/CommunityOpenRankLeaderboard/Banner.tsx diff --git a/src/components/DevLeaderboard/Details.tsx b/src/components/CommunityOpenRankLeaderboard/Details.tsx similarity index 100% rename from src/components/DevLeaderboard/Details.tsx rename to src/components/CommunityOpenRankLeaderboard/Details.tsx diff --git a/src/components/DevLeaderboard/Graph.tsx b/src/components/CommunityOpenRankLeaderboard/Graph.tsx similarity index 100% rename from src/components/DevLeaderboard/Graph.tsx rename to src/components/CommunityOpenRankLeaderboard/Graph.tsx diff --git a/src/components/DevLeaderboard/Leaderboard.tsx b/src/components/CommunityOpenRankLeaderboard/Leaderboard.tsx similarity index 100% rename from src/components/DevLeaderboard/Leaderboard.tsx rename to src/components/CommunityOpenRankLeaderboard/Leaderboard.tsx diff --git a/src/components/DevLeaderboard/index.tsx b/src/components/CommunityOpenRankLeaderboard/index.tsx similarity index 69% rename from src/components/DevLeaderboard/index.tsx rename to src/components/CommunityOpenRankLeaderboard/index.tsx index 690d807..4004e86 100644 --- a/src/components/DevLeaderboard/index.tsx +++ b/src/components/CommunityOpenRankLeaderboard/index.tsx @@ -1,19 +1,20 @@ import React, { useEffect, useState } from 'react'; -import $ from 'jquery'; +import axios from 'axios'; import { message } from 'antd'; import Leaderboard from './Leaderboard'; import Details from './Details'; import Graph from './Graph'; import Banner from './Banner'; +import { translate } from '@docusaurus/Translate'; const DevLeaderboard = () => { const [graph, setGraph] = useState(null); const [selectedNodeId, setSelectedNodeId] = useState(null); - const [platform, setPlatform] = useState("github"); - const [date, setDate] = useState("202407"); + const [platform, setPlatform] = useState(''); + const [date, setDate] = useState(''); const [dateKeys, setDateKeys] = useState([]); - const [datePlaceholder, setDatePlaceholder] = useState(""); + const [datePlaceholder, setDatePlaceholder] = useState(''); const baseUrl = "https://oss.x-lab.info/open_digger/"; const typeMap = new Map([ @@ -24,29 +25,24 @@ const DevLeaderboard = () => { ]); const loadData = async (platform: string, repoName: string) => { - const hide = message.loading("正在获取数据...", 0); + const hide = message.loading(translate({ id: 'communityLeaderboard.fetchingData' }), 0); try { - console.time('fetchData') - const data = await $.getJSON( - `${baseUrl}${platform}/${repoName}/community_openrank.json` - ); + const data = (await axios.get(`${baseUrl}${platform}/${repoName}/community_openrank.json`)).data; if (!data || Object.keys(data).length === 0) { - message.warning("未查询到相关信息"); - } else { - const keys = Object.keys(data.data); - const lastKey = keys[keys.length - 1]; - const formattedLastKey = `${lastKey.slice(0, 4)}-${lastKey.slice(4)}`; - setGraph(data); - setDate(lastKey); - setDatePlaceholder(formattedLastKey); - setDateKeys(keys); - setPlatform(platform); + throw ('No valid data found'); } - console.timeEnd('fetchData') - hide(); + const keys = Object.keys(data.data); + const lastKey = keys[keys.length - 1]; + const formattedLastKey = `${lastKey.slice(0, 4)}-${lastKey.slice(4)}`; + setGraph(data); + setDate(lastKey); + setDatePlaceholder(formattedLastKey); + setDateKeys(keys); + setPlatform(platform); } catch (error) { - message.error("获取数据时出错"); + message.error(translate({ id: 'communityLeaderboard.fetchDataError' })); console.error(error); + } finally { hide(); } }; @@ -55,7 +51,7 @@ const DevLeaderboard = () => { if (graph) { const keys = Object.keys(graph.data); if (!keys.includes(date)) { - message.error("该月份无数据"); + message.error(translate({ id: 'communityLeaderboard.noDataForMonth' })); return; } setSelectedNodeId(-1); diff --git a/src/components/DevLeaderboard/styles.module.css b/src/components/CommunityOpenRankLeaderboard/styles.module.css similarity index 73% rename from src/components/DevLeaderboard/styles.module.css rename to src/components/CommunityOpenRankLeaderboard/styles.module.css index dc662e7..fdb07b9 100644 --- a/src/components/DevLeaderboard/styles.module.css +++ b/src/components/CommunityOpenRankLeaderboard/styles.module.css @@ -13,22 +13,23 @@ left: 50%; transform: translateX(-50%); width: 700px; - height: 130px; - background-color: rgba(255, 255, 255, 0.5); + height: 140px; + background-color: rgba(241, 246, 250, 0.5); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); border-radius: 1rem; padding: 1rem; - border: 1px solid grey; +} + +[data-theme='dark'] .bannerBox { + background-color: rgba(35, 43, 67, 0.5); } .bannerTitle { margin-bottom: 0.5rem; text-align: center; - font-size: 1.5rem; + font-size: 1.8rem; font-weight: bold; - color: black; - text-shadow: 0 0 10px white; } .bannerContent { @@ -38,14 +39,14 @@ .leftBox { position: absolute; - top: 20%; + top: 30%; left: 20px; - height: 60%; + height: 50%; } .rightBox { position: absolute; right: 20px; - top: 20%; - height: 60%; + top: 30%; + height: 50%; } diff --git a/src/pages/community_openrank_leaderboard.tsx b/src/pages/community_openrank_leaderboard.tsx index 0784db7..4660c37 100644 --- a/src/pages/community_openrank_leaderboard.tsx +++ b/src/pages/community_openrank_leaderboard.tsx @@ -1,11 +1,11 @@ import Layout from '@theme/Layout'; -import DevLeaderboard from '../components/DevLeaderboard'; +import CommunityOpenRankLeaderboard from '../components/CommunityOpenRankLeaderboard'; export default (): JSX.Element => { return (
- +
);