Skip to content

Commit 34c2bf7

Browse files
committed
feat(add cache query): integrate request with reactQuery cache
1 parent 7676974 commit 34c2bf7

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

web/src/components/internal-ui/ChatBox.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ interface Props {
1111
messageData: Message[];
1212
endpoint: ENDPOINTS;
1313
request: any;
14+
id: string;
1415
}
1516

1617
interface BasicGenApiResponse {
1718
output: string;
1819
}
1920

20-
const ChatBox = ({ messageData, endpoint, request }: Props) => {
21+
const ChatBox = ({ messageData, endpoint, request, id }: Props) => {
2122
const addMessage = useGptStore((s) => s.addMessage);
23+
2224
const { data, error, isLoading } = usePost<BasicGenApiResponse>(
2325
endpoint,
24-
request
26+
request,
27+
id
2528
);
2629

2730
useEffect(() => {

web/src/features/basicGen/BasicGen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const BasicGen = () => {
3535
max_token: data.maxToken,
3636
service: data.service,
3737
input: data.input,
38+
requestId: uuid(),
3839
};
3940
if (data.input) setReq(request);
4041
};
@@ -57,6 +58,7 @@ const BasicGen = () => {
5758
endpoint={ENDPOINTS.postBasic}
5859
request={req}
5960
messageData={messages}
61+
id={req?.requestId ?? ""}
6062
/>
6163
<HStack
6264
mt="3"

web/src/features/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export interface ApiRequestBasicGen {
1818
max_token: number;
1919
service: string;
2020
input: string;
21+
requestId: string;
2122
}

web/src/hooks/usePost.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import apiClient from "../utils/apiClient";
33
import { useQuery } from "@tanstack/react-query";
44
import { ENDPOINTS } from "../features/constants";
55

6-
const usePost = <T>(endpoint: ENDPOINTS, data: T) =>
6+
const usePost = <T>(endpoint: ENDPOINTS, data: T, id: string) =>
77
useQuery({
8-
queryKey: [endpoint],
8+
queryKey: [endpoint, id],
99
queryFn: () =>
1010
data
1111
? apiClient.post<T>(endpoint, data)

0 commit comments

Comments
 (0)