mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-12 00:40:07 +08:00
Add types for TaskType to TaskHook
Pre-commit Apply better naming to task api hooks Lint
This commit is contained in:
@@ -4,7 +4,7 @@ import { TaskEmptyState } from "src/components/EmptyState";
|
||||
import { LoadingScreen } from "src/components/Loading/LoadingScreen";
|
||||
import { Task } from "src/components/Tasks/Task";
|
||||
import { TaskInfos } from "src/components/Tasks/TaskTypes";
|
||||
import { apiHooksByType, ERROR_CODES } from "src/lib/constants";
|
||||
import { ERROR_CODES, taskApiHooks } from "src/lib/constants";
|
||||
import { getTypeSafei18nKey } from "src/lib/i18n";
|
||||
import { TaskType } from "src/types/Task";
|
||||
|
||||
@@ -14,8 +14,8 @@ type TaskPageProps = {
|
||||
|
||||
export const TaskPage = ({ type }: TaskPageProps) => {
|
||||
const { t } = useTranslation(["tasks", "common"]);
|
||||
const apiHook = apiHooksByType[type];
|
||||
const { tasks, isLoading, reset, trigger, error } = apiHook(type);
|
||||
const taskApiHook = taskApiHooks[type];
|
||||
const { tasks, isLoading, reset, trigger, error } = taskApiHook(type);
|
||||
const taskInfo = TaskInfos.find((taskType) => taskType.type === type);
|
||||
|
||||
if (isLoading) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
useRankInitialPromptsTask,
|
||||
useRankPrompterRepliesTask,
|
||||
} from "src/hooks/tasks/useRankReplies";
|
||||
import { TaskApiHooks } from "src/types/Hooks";
|
||||
import { TaskType } from "src/types/Task";
|
||||
|
||||
export const ERROR_CODES = {
|
||||
@@ -28,7 +29,7 @@ export const ERROR_CODES = {
|
||||
TASK_MESSAGE_TOO_LONG: 1008,
|
||||
};
|
||||
|
||||
export const apiHooksByType = {
|
||||
export const taskApiHooks: TaskApiHooks = {
|
||||
[TaskType.random]: useGenericTaskAPI,
|
||||
[TaskType.assistant_reply]: useCreateAssistantReply,
|
||||
[TaskType.initial_prompt]: useCreateInitialPrompt,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { MutatorCallback, MutatorOptions } from "swr";
|
||||
|
||||
import { BaseTask, TaskResponse, TaskType } from "./Task";
|
||||
|
||||
type ConcreteTaskResponse = TaskResponse<BaseTask>;
|
||||
type TaskError = { errorCode: number; message: string };
|
||||
|
||||
type Trigger = (
|
||||
extraArgument?: unknown,
|
||||
options?: MutatorOptions<ConcreteTaskResponse>
|
||||
) => Promise<ConcreteTaskResponse>;
|
||||
|
||||
type Reset = (
|
||||
data?: ConcreteTaskResponse | Promise<ConcreteTaskResponse> | MutatorCallback<ConcreteTaskResponse>,
|
||||
opts?: boolean | MutatorOptions<ConcreteTaskResponse>
|
||||
) => Promise<ConcreteTaskResponse>;
|
||||
|
||||
type TaskAPIHook = {
|
||||
tasks: TaskResponse<BaseTask>[];
|
||||
isLoading: boolean;
|
||||
error: TaskError;
|
||||
trigger: Trigger;
|
||||
reset: Reset;
|
||||
};
|
||||
|
||||
export type TaskApiHooks = Record<TaskType, (args: TaskType) => TaskAPIHook>;
|
||||
Reference in New Issue
Block a user