mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-01 16:50:12 +08:00
Refactor fetch and post to use axios
Fix set_label id missing in payload use frontend_message_id pre-commit Refactor api fetcher/poster to axios create lint Remove string literal for path Revert oasst_api_client.ts Fix warning httpStatusCode OasstError optional parameter Refactor remove api base url for local api Lint add blank line
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import fetcher from "src/lib/fetcher";
|
||||
import poster from "src/lib/poster";
|
||||
import { get, post } from "src/lib/api";
|
||||
import { BaseTask, TaskResponse } from "src/types/Task";
|
||||
import useSWRImmutable from "swr/immutable";
|
||||
import useSWRMutation from "swr/mutation";
|
||||
@@ -10,19 +9,15 @@ export const useGenericTaskAPI = <TaskType extends BaseTask>(taskApiEndpoint: st
|
||||
|
||||
const [tasks, setTasks] = useState<ConcreteTaskResponse[]>([]);
|
||||
|
||||
const { isLoading, mutate, error } = useSWRImmutable<ConcreteTaskResponse>(
|
||||
"/api/new_task/" + taskApiEndpoint,
|
||||
fetcher,
|
||||
{
|
||||
onSuccess: (data) => setTasks([data]),
|
||||
revalidateOnMount: true,
|
||||
dedupingInterval: 500,
|
||||
}
|
||||
);
|
||||
const { isLoading, mutate, error } = useSWRImmutable<ConcreteTaskResponse>("/api/new_task/" + taskApiEndpoint, get, {
|
||||
onSuccess: (data) => setTasks([data]),
|
||||
revalidateOnMount: true,
|
||||
dedupingInterval: 500,
|
||||
});
|
||||
|
||||
const { trigger } = useSWRMutation("/api/update_task", poster, {
|
||||
const { trigger } = useSWRMutation("/api/update_task", post, {
|
||||
onSuccess: async (response) => {
|
||||
const newTask: ConcreteTaskResponse = await response.json();
|
||||
const newTask: ConcreteTaskResponse = response;
|
||||
setTasks((oldTasks) => [...oldTasks, newTask]);
|
||||
mutate();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user