-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44c0dce
commit dbf6710
Showing
12 changed files
with
153 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { StateSchema } from '@/app/providers/StoreProvider' | ||
|
||
export const getShopNewsSelector = (state: StateSchema) => { | ||
return state.shopNews.news | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit' | ||
import { ThunkConfig } from '@/app/providers/StoreProvider/config/StateSchema' | ||
import { ApiError, ApiErrorTypes, ApiRoutes } from '@/shared/api/types' | ||
import { apiErrorIdentify } from '@/shared/api/apiErrorIdentify' | ||
import { ShopNewsData } from '../types/types' | ||
|
||
// export const getStoreReviews = createAsyncThunk<StoreReviewData[], void, ThunkConfig<ApiError>>( | ||
export const getShopNews = createAsyncThunk<ShopNewsData[], void, ThunkConfig<ApiError>>( | ||
//void1- выходные данные, void2- входные данные , thunkConfig- тип store | ||
'shop-news', // action type, первый аргумент | ||
async (_, thunkAPI) => { | ||
// второй аргумент- асинхронная функция , кот вызовет dispatch в компоненте | ||
const { rejectWithValue, extra } = thunkAPI | ||
try { | ||
const { data } = await extra.api.get(ApiRoutes.SHOP_NEWS) | ||
|
||
return data.results | ||
} catch (error) { | ||
return rejectWithValue(apiErrorIdentify(error, ApiErrorTypes.DATA_EMPTY_ERROR)) | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createSlice } from '@reduxjs/toolkit' | ||
import { getShopNews } from '../services/getShopNews' | ||
import { ShopNewsSchema } from '../types/types' | ||
|
||
const initialState: ShopNewsSchema = { | ||
isLoading: false, | ||
news: [] | ||
} | ||
|
||
export const shopNewsSlice = createSlice({ | ||
name: 'shopNews', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: builder => { | ||
builder | ||
.addCase(getShopNews.pending, state => { | ||
state.isLoading = true | ||
}) | ||
.addCase(getShopNews.fulfilled, (state, { payload }) => { | ||
state.isLoading = false | ||
state.news = payload | ||
}) | ||
.addCase(getShopNews.rejected, state => { | ||
state.isLoading = false | ||
}) | ||
} | ||
}) | ||
|
||
export const { actions: shopNewsActions, reducer: shopNewsReducer } = shopNewsSlice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export interface GetShopNewsResponse { | ||
count: number | ||
previous: string | ||
next: string | ||
results: ShopNewsData[] | ||
} | ||
|
||
export interface ShopNewsData { | ||
id: number | ||
title: string | ||
text: string | ||
image: string | ||
pub_date: string | ||
slug: string | ||
meta_title: string | ||
meta_description: string | ||
} | ||
|
||
export interface ShopNewsSchema { | ||
isLoading: boolean | ||
news: ShopNewsData[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters