From c8cd869594788a9cb4e64cf3fa3ca624e751f572 Mon Sep 17 00:00:00 2001 From: notmd Date: Wed, 1 Feb 2023 14:34:47 +0700 Subject: [PATCH] extract type --- website/src/components/Dashboard/TaskOption.tsx | 8 +++++--- website/src/pages/dashboard.tsx | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/website/src/components/Dashboard/TaskOption.tsx b/website/src/components/Dashboard/TaskOption.tsx index 87910695..1ee0489b 100644 --- a/website/src/components/Dashboard/TaskOption.tsx +++ b/website/src/components/Dashboard/TaskOption.tsx @@ -20,8 +20,10 @@ import { TaskCategory, TaskInfo, TaskType } from "src/types/Task"; import { TaskCategoryLabels, TaskInfos } from "../Tasks/TaskTypes"; +export type TaskCategoryItem = { taskType: TaskType; count: number }; + export interface TasksOptionProps { - content: Partial>>; + content: Partial>; } export const TaskOption = ({ content }: TasksOptionProps) => { @@ -40,7 +42,7 @@ export const TaskOption = ({ content }: TasksOptionProps) => { return ( - {Object.entries(content).map(([category, taskTypes]) => ( + {Object.entries(content).map(([category, items]) => (
@@ -52,7 +54,7 @@ export const TaskOption = ({ content }: TasksOptionProps) => { - {taskTypes + {items .map(({ taskType, count }) => ({ ...taskInfoMap[taskType], count })) .map((item) => ( diff --git a/website/src/pages/dashboard.tsx b/website/src/pages/dashboard.tsx index 94c25e57..e9fe3a18 100644 --- a/website/src/pages/dashboard.tsx +++ b/website/src/pages/dashboard.tsx @@ -5,8 +5,9 @@ import { useEffect, useMemo, useState } from "react"; import { LeaderboardWidget, TaskOption, WelcomeCard } from "src/components/Dashboard"; import { getDashboardLayout } from "src/components/Layout"; 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"; +import { TaskCategoryItem } from "src/components/Dashboard/TaskOption"; import useSWR from "swr"; const Dashboard = () => { @@ -59,4 +60,4 @@ const filterAvailableTasks = (availableTasks: Partial) => Object.entries(availableTasks) .filter(([, count]) => count > 0) .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[];