Consolidate API calls to TaskContext

This commit is contained in:
AbdBarho
2023-01-29 11:03:07 +01:00
parent 5b113eadd9
commit d7f2a6d0d9
7 changed files with 135 additions and 126 deletions
+6 -11
View File
@@ -1,16 +1,11 @@
import { BaseTask, TaskContent, TaskResponse, TaskType } from "src/types/Task";
import { BaseTask, TaskResponse, TaskType } from "src/types/Task";
interface TaskInteraction {
id: string;
update_type: string;
content: TaskContent;
}
export type TaskApiHook<Task extends BaseTask> = {
export type TaskApiHook<Task extends BaseTask, ResponseContent> = {
response: TaskResponse<Task>;
isLoading: boolean;
completeTask: (interaction: TaskInteraction) => void;
skipTask: () => void;
completeTask: (interaction: ResponseContent) => Promise<void>;
skipTask: () => Promise<void>;
rejectTask: (reason: string) => Promise<void>;
};
export type TaskApiHooks = Record<TaskType, (args: TaskType) => TaskApiHook<BaseTask>>;
export type TaskApiHooks = Record<TaskType, (args: TaskType) => TaskApiHook<BaseTask, any>>;
+27 -2
View File
@@ -14,6 +14,30 @@ export enum TaskType {
random = "random",
}
export enum TaskCategory {
Create = "Create",
Evaluate = "Evaluate",
Label = "Label",
Random = "Random",
}
export interface TaskInfo {
category: TaskCategory;
help_link: string;
id: string;
mode?: string;
pathname: string;
type: string;
update_type: string;
}
export enum TaskUpdateType {
MessageRanking = "message_ranking",
Random = "random",
TextLabels = "text_labels",
TextReplyToMessage = "text_reply_to_message",
}
// we need to reconsider how to handle task content types
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type TaskContent = any;
@@ -29,14 +53,15 @@ export interface BaseTask {
type: TaskType;
}
export interface TaskAvailableResponse<Task extends BaseTask> {
export interface ServerTaskResponse<Task extends BaseTask> {
id: string;
userId: string;
task: Task;
}
interface TaskAvailable<Task extends BaseTask> extends TaskAvailableResponse<Task> {
interface TaskAvailable<Task extends BaseTask> extends ServerTaskResponse<Task> {
taskAvailability: "AVAILABLE";
taskInfo: TaskInfo;
}
interface AwaitingInitialTask {