chores: config redux
This commit is contained in:
parent
4bb7ed8c31
commit
477d311213
@ -1,7 +1,7 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { Geist, Geist_Mono } from 'next/font/google';
|
||||
|
||||
import { ThemeProvider } from '@/shared/theme/theme-provider';
|
||||
import { Providers } from '@/shared/providers/providers';
|
||||
|
||||
import './globals.css';
|
||||
|
||||
@ -30,14 +30,7 @@ export default function RootLayout({
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
<ThemeProvider
|
||||
attribute='class'
|
||||
defaultTheme='system'
|
||||
enableSystem
|
||||
disableTransitionOnChange
|
||||
>
|
||||
{children}
|
||||
</ThemeProvider>
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
21
src/shared/api/base-api.ts
Normal file
21
src/shared/api/base-api.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
const baseQuery = fetchBaseQuery({
|
||||
baseUrl: process.env.NEXT_PUBLIC_API_URL,
|
||||
});
|
||||
|
||||
export const TAGS = {
|
||||
STOCKS: 'stocks',
|
||||
GAS_STATIONS: 'gas-stations',
|
||||
VACANCIES: 'vacancies',
|
||||
PARTNERS: 'partners',
|
||||
CERTIFICATES: 'certificates',
|
||||
CHARITY: 'charity',
|
||||
} as const;
|
||||
|
||||
export const baseAPI = createApi({
|
||||
reducerPath: 'baseAPI',
|
||||
baseQuery,
|
||||
tagTypes: Object.values(TAGS),
|
||||
endpoints: () => ({}),
|
||||
});
|
||||
23
src/shared/providers/providers.tsx
Normal file
23
src/shared/providers/providers.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
import { store } from '../store';
|
||||
import { ThemeProvider } from '../theme/theme-provider';
|
||||
|
||||
type ProvidersProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export const Providers = ({ children }: ProvidersProps) => {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<ThemeProvider
|
||||
attribute='class'
|
||||
defaultTheme='system'
|
||||
enableSystem
|
||||
disableTransitionOnChange
|
||||
>
|
||||
{children}
|
||||
</ThemeProvider>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
19
src/shared/store/index.ts
Normal file
19
src/shared/store/index.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
import { setupListeners } from '@reduxjs/toolkit/query/react';
|
||||
import { baseAPI } from '@/shared/api/base-api';
|
||||
|
||||
import { rootReducer } from './root-reducer';
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: rootReducer,
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().concat(baseAPI.middleware),
|
||||
devTools: process.env.NODE_ENV === 'development',
|
||||
});
|
||||
|
||||
setupListeners(store.dispatch);
|
||||
|
||||
// Infer the `RootState` and `AppDispatch` types from the store itself
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
6
src/shared/store/root-reducer.ts
Normal file
6
src/shared/store/root-reducer.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { combineReducers } from '@reduxjs/toolkit';
|
||||
import { baseAPI } from '@/shared/api/base-api';
|
||||
|
||||
export const rootReducer = combineReducers({
|
||||
[baseAPI.reducerPath]: baseAPI.reducer,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user