diff --git a/website/src/components/Dashboard/LeaderboardTable.tsx b/website/src/components/Dashboard/LeaderboardTable.tsx index cd7d22d4..b6048f3f 100644 --- a/website/src/components/Dashboard/LeaderboardTable.tsx +++ b/website/src/components/Dashboard/LeaderboardTable.tsx @@ -1,55 +1,12 @@ -import { Badge, Box, Image, Link, Stack, StackDivider, Text, useColorModeValue } from "@chakra-ui/react"; +import { Box, Link, Stack, StackDivider, Text, useColorModeValue } from "@chakra-ui/react"; import NextLink from "next/link"; +import { get } from "src/lib/api"; +import useSWR from "swr"; export function LeaderboardTable() { const backgroundColor = useColorModeValue("white", "gray.700"); const accentColor = useColorModeValue("gray.200", "gray.900"); - - //need to add streak info to chart - - const leaderInfo = [ - { - name: "fozziethebeat#6690", - image: "/images/temp-avatars/av1.jpg", - score: "5,208", - arrowDir: "increase", - streak: false, - streakCount: "5-Day Streak", - }, - { - name: "k_nearest_neighbor#8579", - image: "/images/temp-avatars/av2.jpg", - score: "5,164", - arrowDir: "decrease", - streak: false, - streakCount: "", - }, - { - name: "andreaskoepf#2266", - image: "/images/temp-avatars/av3.jpg", - score: "5,120", - arrowDir: "", - streak: false, - streakCount: "2-Day Streak", - }, - { - name: "AbdBarho#1684", - image: "/images/temp-avatars/av4.jpg", - score: "4,260", - arrowDir: "", - streak: false, - streakCount: "", - }, - { - name: "zu#9016", - image: "/images/temp-avatars/av5.jpg", - score: "3,608", - arrowDir: "", - streak: false, - streakCount: "", - }, - ]; - + const { data: leaderboardEntries } = useSWR("/api/leaderboard", get); return (
@@ -75,15 +32,19 @@ export function LeaderboardTable() {

Score

- {leaderInfo.map((item, itemIndex) => ( -
+ {leaderboardEntries?.map(({ display_name, score }, idx) => ( +
+ {/* Profile Picture -

{item.name}

+ */} +

{display_name}

+ {/* {item.streakCount} + */}
-

{item.score}

+

{score}

))} diff --git a/website/src/components/LeaderboardGridCell/LeaderboardGridCell.tsx b/website/src/components/LeaderboardGridCell/LeaderboardGridCell.tsx new file mode 100644 index 00000000..51dd877e --- /dev/null +++ b/website/src/components/LeaderboardGridCell/LeaderboardGridCell.tsx @@ -0,0 +1,97 @@ +import { Avatar, Box, Grid, GridItem, Text, useColorModeValue } from "@chakra-ui/react"; +import { FiChevronDown } from "react-icons/fi"; +import { get } from "src/lib/api"; +import useSWR from "swr"; + +/** + * Presents a grid of leaderboard entries with more detailed information. + */ +const LeaderboardGridCell = () => { + const { data: leaderboardEntries } = useSWR("/api/leaderboard", get); + const backgroundColor = useColorModeValue("white", "gray.800"); + const columns = `repeat(${FILTER.length}, 1fr)`; + + return ( + <> + + + {FILTER.map(({ title, GridItemProps }, index) => ( + + + + {title} + + + + + + ))} + + + + {leaderboardEntries?.map(({ display_name, ranking, score }, index) => ( + + + + + {display_name} + + + + + {ranking} + + + + {score} + + {/* + + {item.medal} + + */} + + ))} + + + ); +}; + +/** + * Specifies the table headers in the grid. + */ +const FILTER = [ + { + title: "User", + isActive: false, + GridItemProps: { justifyContent: "start" }, + }, + { + title: "Rank", + isActive: false, + GridItemProps: { justifyContent: "center" }, + }, + { + title: "Score", + isActive: false, + GridItemProps: { justifyContent: "center" }, + }, + /* + { + title: "Medal", + isActive: false, + GridItemProps: { justifyContent: "center" }, + }, + */ +]; + +export { LeaderboardGridCell }; diff --git a/website/src/components/LeaderboardGridCell/index.tsx b/website/src/components/LeaderboardGridCell/index.tsx new file mode 100644 index 00000000..c4657eb6 --- /dev/null +++ b/website/src/components/LeaderboardGridCell/index.tsx @@ -0,0 +1 @@ +export * from "./LeaderboardGridCell"; diff --git a/website/src/components/RankItem.tsx b/website/src/components/RankItem.tsx deleted file mode 100644 index daed0576..00000000 --- a/website/src/components/RankItem.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import { Avatar, Box, GridItem, Text } from "@chakra-ui/react"; - -const RankItem = () => { - const leaderInfo = [ - { - username: "fozziethebeat", - rank: 1, - score: 530, - medal: "\uD83E\uDD47", - }, - { - username: "k_nearest", - rank: 2, - score: 420, - medal: "\uD83E\uDD48", - }, - { - username: "zu", - rank: 3, - score: 160, - medal: "\uD83E\uDD49", - }, - { - username: "Abd", - rank: 4, - score: 140, - medal: "", - }, - ]; - - return ( - <> - {leaderInfo.map((item, index) => ( - - - - - {item.username} - - - - - {item.rank} - - - - {item.score} - - - {item.medal} - - - ))} - - ); -}; - -export default RankItem; diff --git a/website/src/lib/oasst_api_client.ts b/website/src/lib/oasst_api_client.ts index 381e6e0f..b2ece97b 100644 --- a/website/src/lib/oasst_api_client.ts +++ b/website/src/lib/oasst_api_client.ts @@ -121,11 +121,19 @@ export class OasstApiClient { }); } - //Fetch valid labels. This is called every task. though the call may be redundant - //keeping this for future where the valid labels may change per task - async fetch_valid_text(): Promise { + /** + * Returns the valid labels for messages. + */ + async fetch_valid_text(): Promise { return this.get(`/api/v1/text_labels/valid_labels`); } + + /** + * Returns the current leaderboard ranking. + */ + async fetch_leaderboard(): Promise { + return this.get(`/api/v1/experimental/leaderboards/create/assistant`); + } } const oasstApiClient = new OasstApiClient(process.env.FASTAPI_URL, process.env.FASTAPI_KEY); diff --git a/website/src/pages/api/leaderboard.ts b/website/src/pages/api/leaderboard.ts new file mode 100644 index 00000000..d2a591a8 --- /dev/null +++ b/website/src/pages/api/leaderboard.ts @@ -0,0 +1,18 @@ +import { withoutRole } from "src/lib/auth"; +import { oasstApiClient } from "src/lib/oasst_api_client"; + +/** + * Returns the set of valid labels that can be applied to messages. + */ +const handler = withoutRole("banned", async (req, res) => { + const { leaderboard } = await oasstApiClient.fetch_leaderboard(); + res.status(200).json( + leaderboard.map(({ display_name, ranking, score }) => ({ + display_name, + ranking, + score, + })) + ); +}); + +export default handler; diff --git a/website/src/pages/leaderboard.tsx b/website/src/pages/leaderboard.tsx new file mode 100644 index 00000000..ef2c4529 --- /dev/null +++ b/website/src/pages/leaderboard.tsx @@ -0,0 +1,25 @@ +import { Box, Heading } from "@chakra-ui/react"; +import Head from "next/head"; +import { getDashboardLayout } from "src/components/Layout"; +import { LeaderboardGridCell } from "src/components/LeaderboardGridCell"; + +const Leaderboard = () => { + return ( + <> + + Leaderboard - Open Assistant + + + + + Leaderboard + + + + + ); +}; + +Leaderboard.getLayout = getDashboardLayout; + +export default Leaderboard; diff --git a/website/src/pages/leaderboard/index.tsx b/website/src/pages/leaderboard/index.tsx deleted file mode 100644 index a350e092..00000000 --- a/website/src/pages/leaderboard/index.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { Box, Grid, GridItem, GridItemProps, Heading, Text, useColorModeValue } from "@chakra-ui/react"; -import Head from "next/head"; -import { FiChevronDown } from "react-icons/fi"; -import { getDashboardLayout } from "src/components/Layout"; -import RankItem from "src/components/RankItem"; - -const Leaderboard = () => { - const backgroundColor = useColorModeValue("white", "gray.800"); - - const GridProps: GridItemProps = { - justifyContent: "start", - }; - const filter = [ - { - title: "User", - isActive: false, - GridItemProps: { ...GridProps, justifyContent: "start" }, - }, - { - title: "Rank", - isActive: false, - GridItemProps: { ...GridProps, justifyContent: "center" }, - }, - { - title: "Score", - isActive: false, - GridItemProps: { ...GridProps, justifyContent: "center" }, - }, - { - title: "Medal", - isActive: false, - GridItemProps: { ...GridProps, justifyContent: "center" }, - }, - ]; - - return ( - <> - - Leaderboard - Open Assistant - - - - - Leaderboard - - - - {filter.map((item, index) => ( - - - - {item.title} - - - - - - ))} - - - - - - - - ); -}; - -Leaderboard.getLayout = getDashboardLayout; - -export default Leaderboard; diff --git a/website/src/types/Leaderboard.ts b/website/src/types/Leaderboard.ts new file mode 100644 index 00000000..ea3c9dae --- /dev/null +++ b/website/src/types/Leaderboard.ts @@ -0,0 +1,5 @@ +export interface LeaderboardEntry { + display_name: string; + ranking: number; + score: number; +}