Merge branch 'main' into 766_admin_enhancement

This commit is contained in:
notmd
2023-01-21 12:51:15 +07:00
19 changed files with 405 additions and 88 deletions
@@ -1,8 +1,9 @@
import { Table, TableContainer, Tbody, Td, Th, Thead, Tr, useColorModeValue } from "@chakra-ui/react";
import React from "react";
import { Table, TableContainer, Tbody, Td, Text, Th, Thead, Tr, useColorModeValue } from "@chakra-ui/react";
import { useTranslation } from "next-i18next";
import React, { useMemo } from "react";
import { useTable } from "react-table";
import { get } from "src/lib/api";
import { LeaderboardEntity, LeaderboardTimeFrame } from "src/types/Leaderboard";
import { LeaderboardReply, LeaderboardTimeFrame } from "src/types/Leaderboard";
import useSWRImmutable from "swr/immutable";
const columns = [
@@ -26,13 +27,26 @@ const columns = [
* Presents a grid of leaderboard entries with more detailed information.
*/
const LeaderboardGridCell = ({ timeFrame }: { timeFrame: LeaderboardTimeFrame }) => {
const { data } = useSWRImmutable<LeaderboardEntity[]>(`/api/leaderboard?time_frame=${timeFrame}`, get, {
fallbackData: [],
const { t } = useTranslation();
const { data: reply } = useSWRImmutable<LeaderboardReply>(`/api/leaderboard?time_frame=${timeFrame}`, get, {
revalidateOnMount: true,
});
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({
columns,
data: reply?.leaderboard ?? [],
});
const backgroundColor = useColorModeValue("white", "gray.800");
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns, data });
const lastUpdated = useMemo(() => {
const val = new Date(reply?.last_updated);
return t("last_updated_at", { val, formatParams: { val: { dateStyle: "full", timeStyle: "short" } } });
}, [t, reply?.last_updated]);
if (!reply) {
return null;
}
return (
<TableContainer>
@@ -66,6 +80,7 @@ const LeaderboardGridCell = ({ timeFrame }: { timeFrame: LeaderboardTimeFrame })
})}
</Tbody>
</Table>
<Text p="2">{lastUpdated}</Text>
</TableContainer>
);
};
@@ -50,6 +50,7 @@ export function MessageTableEntry(props: MessageTableEntryProps) {
bg={item.is_assistant ? backgroundColor : backgroundColor2}
onClick={props.enabled && goToMessage}
_hover={props.enabled && { cursor: "pointer", opacity: 0.9 }}
whiteSpace="pre-wrap"
>
{inlineAvatar && avatar}
{item.text}
+3 -3
View File
@@ -6,9 +6,9 @@ import { LeaderboardTimeFrame } from "src/types/Leaderboard";
* Returns the set of valid labels that can be applied to messages.
*/
const handler = withoutRole("banned", async (req, res) => {
const time_frame = (req.query.time_frame as LeaderboardTimeFrame) || LeaderboardTimeFrame.day;
const { leaderboard } = await oasstApiClient.fetch_leaderboard(time_frame);
res.status(200).json(leaderboard);
const time_frame = (req.query.time_frame as LeaderboardTimeFrame) ?? LeaderboardTimeFrame.day;
const info = await oasstApiClient.fetch_leaderboard(time_frame);
res.status(200).json(info);
});
export default handler;
+1
View File
@@ -12,6 +12,7 @@ export const enum LeaderboardTimeFrame {
}
export interface LeaderboardReply {
time_frame: LeaderboardTimeFrame;
last_updated: string; // date time iso string
leaderboard: LeaderboardEntity[];
}