mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-09-09 11:15:08 +08:00
extract type
This commit is contained in:
@@ -20,8 +20,10 @@ import { TaskCategory, TaskInfo, TaskType } from "src/types/Task";
|
|||||||
|
|
||||||
import { TaskCategoryLabels, TaskInfos } from "../Tasks/TaskTypes";
|
import { TaskCategoryLabels, TaskInfos } from "../Tasks/TaskTypes";
|
||||||
|
|
||||||
|
export type TaskCategoryItem = { taskType: TaskType; count: number };
|
||||||
|
|
||||||
export interface TasksOptionProps {
|
export interface TasksOptionProps {
|
||||||
content: Partial<Record<TaskCategory, Array<{ taskType: TaskType; count: number }>>>;
|
content: Partial<Record<TaskCategory, TaskCategoryItem[]>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TaskOption = ({ content }: TasksOptionProps) => {
|
export const TaskOption = ({ content }: TasksOptionProps) => {
|
||||||
@@ -40,7 +42,7 @@ export const TaskOption = ({ content }: TasksOptionProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="flex flex-col gap-14">
|
<Box className="flex flex-col gap-14">
|
||||||
{Object.entries(content).map(([category, taskTypes]) => (
|
{Object.entries(content).map(([category, items]) => (
|
||||||
<div key={category}>
|
<div key={category}>
|
||||||
<Flex>
|
<Flex>
|
||||||
<Heading size="lg" className="pb-4">
|
<Heading size="lg" className="pb-4">
|
||||||
@@ -52,7 +54,7 @@ export const TaskOption = ({ content }: TasksOptionProps) => {
|
|||||||
</ExternalLink>
|
</ExternalLink>
|
||||||
</Flex>
|
</Flex>
|
||||||
<SimpleGrid columns={[1, 1, 2, 2, 3, 4]} gap={4}>
|
<SimpleGrid columns={[1, 1, 2, 2, 3, 4]} gap={4}>
|
||||||
{taskTypes
|
{items
|
||||||
.map(({ taskType, count }) => ({ ...taskInfoMap[taskType], count }))
|
.map(({ taskType, count }) => ({ ...taskInfoMap[taskType], count }))
|
||||||
.map((item) => (
|
.map((item) => (
|
||||||
<Link key={category + item.id} href={item.pathname}>
|
<Link key={category + item.id} href={item.pathname}>
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import { useEffect, useMemo, useState } from "react";
|
|||||||
import { LeaderboardWidget, TaskOption, WelcomeCard } from "src/components/Dashboard";
|
import { LeaderboardWidget, TaskOption, WelcomeCard } from "src/components/Dashboard";
|
||||||
import { getDashboardLayout } from "src/components/Layout";
|
import { getDashboardLayout } from "src/components/Layout";
|
||||||
import { get } from "src/lib/api";
|
import { get } from "src/lib/api";
|
||||||
import { AvailableTasks, TaskCategory, TaskType } from "src/types/Task";
|
import { AvailableTasks, TaskCategory } from "src/types/Task";
|
||||||
export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props";
|
export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props";
|
||||||
|
import { TaskCategoryItem } from "src/components/Dashboard/TaskOption";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
@@ -59,4 +60,4 @@ const filterAvailableTasks = (availableTasks: Partial<AvailableTasks>) =>
|
|||||||
Object.entries(availableTasks)
|
Object.entries(availableTasks)
|
||||||
.filter(([, count]) => count > 0)
|
.filter(([, count]) => count > 0)
|
||||||
.sort((a, b) => b[1] - a[1])
|
.sort((a, b) => b[1] - a[1])
|
||||||
.map(([taskType, count]) => ({ taskType, count })) as Array<{ taskType: TaskType; count: number }>;
|
.map(([taskType, count]) => ({ taskType, count })) as TaskCategoryItem[];
|
||||||
|
|||||||
Reference in New Issue
Block a user