mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-16 01:10:06 +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:
@@ -23,8 +23,7 @@ import {
|
||||
} from "@chakra-ui/react";
|
||||
import { FlagIcon, QuestionMarkCircleIcon } from "@heroicons/react/20/solid";
|
||||
import { useEffect, useReducer } from "react";
|
||||
import fetcher from "src/lib/fetcher";
|
||||
import poster from "src/lib/poster";
|
||||
import { get, post } from "src/lib/api";
|
||||
import { Message } from "src/types/Conversation";
|
||||
import { colors } from "styles/Theme/colors";
|
||||
import useSWR from "swr";
|
||||
@@ -101,7 +100,7 @@ export const FlaggableElement = (props: FlaggableElementProps) => {
|
||||
const [isEditing, setIsEditing] = useBoolean();
|
||||
const backgroundColor = useColorModeValue("gray.200", "gray.700");
|
||||
|
||||
const { data, isLoading } = useSWR("/api/valid_labels", fetcher);
|
||||
const { data, isLoading } = useSWR("/api/valid_labels", get);
|
||||
useEffect(() => {
|
||||
if (isLoading) {
|
||||
return;
|
||||
@@ -110,7 +109,7 @@ export const FlaggableElement = (props: FlaggableElementProps) => {
|
||||
updateReport({ type: "load_labels", labels: valid_labels });
|
||||
}, [data, isLoading]);
|
||||
|
||||
const { trigger } = useSWRMutation("/api/set_label", poster, {
|
||||
const { trigger } = useSWRMutation("/api/set_label", post, {
|
||||
onSuccess: () => {
|
||||
setIsEditing.off();
|
||||
},
|
||||
|
||||
@@ -12,7 +12,6 @@ interface MessageTableEntryProps {
|
||||
export function MessageTableEntry(props: MessageTableEntryProps) {
|
||||
const { item } = props;
|
||||
const backgroundColor = useColorModeValue("gray.50", "gray.800");
|
||||
|
||||
return (
|
||||
<div>
|
||||
<FlaggableElement message={item} key={`flag_${item.id || item.frontend_message_id}`}>
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Box, CircularProgress, Stack, StackProps, Text, TextProps, useColorMode
|
||||
import { boolean } from "boolean";
|
||||
import { useState } from "react";
|
||||
import { MessageTableEntry } from "src/components/Messages/MessageTableEntry";
|
||||
import fetcher from "src/lib/fetcher";
|
||||
import { get } from "src/lib/api";
|
||||
import useSWR from "swr";
|
||||
|
||||
const MessageHeaderProps: TextProps = {
|
||||
@@ -34,7 +34,7 @@ export function MessageWithChildren(props: MessageWithChildrenProps) {
|
||||
const [message, setMessage] = useState(null);
|
||||
const [children, setChildren] = useState(null);
|
||||
|
||||
const { isLoading } = useSWR(id ? `/api/messages/${id}` : null, fetcher, {
|
||||
const { isLoading } = useSWR(id ? `/api/messages/${id}` : null, get, {
|
||||
onSuccess: (data) => {
|
||||
setMessage(data);
|
||||
},
|
||||
@@ -42,7 +42,7 @@ export function MessageWithChildren(props: MessageWithChildrenProps) {
|
||||
setMessage(null);
|
||||
},
|
||||
});
|
||||
const { isLoading: isLoadingChildren } = useSWR(id ? `/api/messages/${id}/children` : null, fetcher, {
|
||||
const { isLoading: isLoadingChildren } = useSWR(id ? `/api/messages/${id}/children` : null, get, {
|
||||
onSuccess: (data) => {
|
||||
setChildren(data);
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import { EvaluateTask } from "src/components/Tasks/EvaluateTask";
|
||||
import { LabelTask } from "src/components/Tasks/LabelTask";
|
||||
import { TaskCategory, TaskInfo, TaskTypes } from "src/components/Tasks/TaskTypes";
|
||||
import { UnchangedWarning } from "src/components/Tasks/UnchangedWarning";
|
||||
import poster from "src/lib/poster";
|
||||
import { post } from "src/lib/api";
|
||||
import { TaskContent } from "src/types/Task";
|
||||
import { TaskReplyState } from "src/types/TaskReplyState";
|
||||
import useSWRMutation from "swr/mutation";
|
||||
@@ -28,7 +28,7 @@ export const Task = ({ frontendId, task, trigger, mutate }) => {
|
||||
|
||||
const taskType = TaskTypes.find((taskType) => taskType.type === task.type);
|
||||
|
||||
const { trigger: sendRejection } = useSWRMutation("/api/reject_task", poster, {
|
||||
const { trigger: sendRejection } = useSWRMutation("/api/reject_task", post, {
|
||||
onSuccess: async () => {
|
||||
mutate();
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Box, CircularProgress, useColorModeValue } from "@chakra-ui/react";
|
||||
import { MessageTable } from "src/components/Messages/MessageTable";
|
||||
import fetcher from "src/lib/fetcher";
|
||||
import { get } from "src/lib/api";
|
||||
import useSWR from "swr";
|
||||
|
||||
interface UserMessagesCellProps {
|
||||
@@ -16,7 +16,7 @@ interface UserMessagesCellProps {
|
||||
*/
|
||||
const UserMessagesCell = ({ path }: UserMessagesCellProps) => {
|
||||
const url = path || "/api/messages/user";
|
||||
const { data: messages, isLoading } = useSWR(url, fetcher, {
|
||||
const { data: messages, isLoading } = useSWR(url, get, {
|
||||
refreshInterval: 2000,
|
||||
});
|
||||
// TODO(#651): This box coloring and styling is used in multiple places. We
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from "@chakra-ui/react";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import fetcher from "src/lib/fetcher";
|
||||
import { get } from "src/lib/api";
|
||||
import useSWR from "swr";
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ const UsersCell = () => {
|
||||
// Fetch and save the users.
|
||||
// This follows useSWR's recommendation for simple pagination:
|
||||
// https://swr.vercel.app/docs/pagination#when-to-use-useswr
|
||||
useSWR(`/api/admin/users?pageIndex=${pageIndex}`, fetcher, {
|
||||
useSWR(`/api/admin/users?pageIndex=${pageIndex}`, get, {
|
||||
onSuccess: setUsers,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user