Skip to content

Commit

Permalink
refactor: use search params to determine leaderboard type
Browse files Browse the repository at this point in the history
Signed-off-by: frank-zsy <[email protected]>
  • Loading branch information
frank-zsy committed Nov 29, 2024
1 parent 0326660 commit 020211c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 60 deletions.
12 changes: 0 additions & 12 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,6 @@ const config: Config = {
indexDocs: true,
},
],
[
path.resolve(__dirname, 'plugin-dynamic-routes/index.ts'),
{
routes: [
{
path: '/leaderboards',
exact: false,
component: '../src/pages/leaderboards_page/index.tsx',
}
]
}
],
],

themes: ['@docusaurus/theme-mermaid'],
Expand Down
52 changes: 52 additions & 0 deletions src/pages/leaderboards/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { useEffect, useState } from 'react';
import Layout from '@theme/Layout';
import SimpleTable from '../../components/SimpleTable';
import { translate } from '@docusaurus/Translate';
import axios from 'axios';
import styles from './styles.module.css';

function OpenLeaderboard() {

const [title, setTitle] = useState('Ranking List Title');
const [data, setData] = useState([]);
const [options, setOptions] = useState([]);

useEffect(() => {
const search = new URLSearchParams(window.location.search);
const type = search.get('type');
if (!type) {
alert('You need to set a leaderboard type first.');
return;
}
if (type === 'projects') {
axios.get(`https://oss.open-digger.cn/leaderboards/${type}.json`).then(resp => {
const data = resp.data;
setTitle(translate({ id: 'leaderboards.projects.title' }));
setData(data.data);
setOptions([
{ name: '#', type: 'String', fields: ['rank'], width: 80 },
{ name: translate({ id: 'leaderboards.projects.name' }), type: 'StringWithIcon', fields: ['name', 'logo'], width: 250 },
{ name: 'OpenRank', type: 'String', fields: ['openrank'], width: 150 },
{ name: translate({ id: 'leaderboards.projects.initiator' }), type: 'StringWithIcon', fields: ['initiator', 'initiatorLogo'], width: 250 },
{ name: translate({ id: 'leaderboards.projects.country' }), type: 'String', fields: ['country'], width: 250 },
]);
}).catch(e => {
console.log(e);
});
} else {
alert(`Leaderboard type ${type} is not supported.`);
}

}, []);

return (
<Layout>
<div className={styles.mainRankingList} >
<SimpleTable title={title} data={data} options={options}
/>
</div>
</Layout>
);
}

export default OpenLeaderboard;
File renamed without changes.
48 changes: 0 additions & 48 deletions src/pages/leaderboards_page/index.tsx

This file was deleted.

0 comments on commit 020211c

Please sign in to comment.