fix chats sorting
This commit is contained in:
39
src/backend/redux/api_slice.js
Normal file
39
src/backend/redux/api_slice.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
||||
import {getConfigValue} from "@brojs/cli";
|
||||
|
||||
const LOCAL = "http://localhost:8099";
|
||||
const DEV = "https://dev.bro-js.ru";
|
||||
|
||||
export const BASE_API_URL = LOCAL + getConfigValue("enterfront.api");
|
||||
|
||||
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: (body) => ({
|
||||
url: '/chat/post',
|
||||
method: 'POST',
|
||||
body,
|
||||
}),
|
||||
}),
|
||||
// Add more endpoints as needed
|
||||
}),
|
||||
});
|
||||
|
||||
// Export hooks for usage in functional components
|
||||
export const { useGetChatsQuery, usePostChatMutation } = apiSlice;
|
||||
12
src/backend/redux/store.js
Normal file
12
src/backend/redux/store.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
import { apiSlice } from './api_slice';
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().concat(apiSlice.middleware),
|
||||
});
|
||||
|
||||
export default store;
|
||||
Reference in New Issue
Block a user