import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; import {getConfigValue} from "@brojs/cli"; import { BASE_API_URL } from "../api.js"; const baseQuery = fetchBaseQuery({ baseUrl: BASE_API_URL, prepareHeaders: (headers) => { const token = localStorage.getItem('token'); if (token) { headers.set('Authorization', `Bearer ${token}`); } return headers; }, }); export const apiSlice = createApi({ reducerPath: 'api', baseQuery, endpoints: (builder) => ({ getChats: builder.query({ query: (username) => `/chat/list/${username}`, }), postChat: builder.mutation({ query: ({ id1, id2 }) => ({ url: `/chat/item/${id1}/${id2}`, method: 'POST', }), }), }), }); // Export hooks for usage in functional components export const { useGetChatsQuery, usePostChatMutation } = apiSlice;