-
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.
Merge pull request #209 from Studio-Yandex-Practicum/api-140-insert-t…
…o-BlogBlock #140-api-inserted-to-BlogBlock
- Loading branch information
Showing
17 changed files
with
173 additions
and
33 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
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 |
---|---|---|
|
@@ -48,5 +48,6 @@ | |
border-radius: 6px; | ||
transition: transform 0.3s ease-in-out; | ||
scroll-snap-align: start; | ||
object-fit: cover; | ||
} | ||
} |
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 getBlogPostsSelector = (state: StateSchema) => { | ||
return state.blogPosts.posts | ||
} |
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,23 @@ | ||
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 { IBlogPostData } from '../types/types' | ||
import { ACTION_GET_BLOG_POSTS } from '@/shared/constants/constants' | ||
|
||
// export const getStoreReviews = createAsyncThunk<StoreReviewData[], void, ThunkConfig<ApiError>>( | ||
export const getBlogPosts = createAsyncThunk<IBlogPostData[], void, ThunkConfig<ApiError>>( | ||
//void1- выходные данные, void2- входные данные , thunkConfig- тип store | ||
ACTION_GET_BLOG_POSTS, // action type, первый аргумент | ||
async (_, thunkAPI) => { | ||
// второй аргумент- асинхронная функция , кот вызовет dispatch в компоненте | ||
const { rejectWithValue, extra } = thunkAPI | ||
try { | ||
const { data } = await extra.api.get(ApiRoutes.BLOG_POSTS) | ||
|
||
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,35 @@ | ||
import { createSlice } from '@reduxjs/toolkit' | ||
import { IBlogPostsSchema } from '../types/types' | ||
import { getBlogPosts } from '../services/getBlogPosts' | ||
import { REDUCER_BLOG_POSTS } from '@/shared/constants/constants' | ||
import { rejectedPayloadHandle } from '@/shared/api/rejectedPayloadHandle' | ||
|
||
const initialState: IBlogPostsSchema = { | ||
isLoading: false, | ||
posts: [] | ||
} | ||
|
||
export const blogPostsSlice = createSlice({ | ||
name: REDUCER_BLOG_POSTS, | ||
initialState, | ||
reducers: { | ||
errorReset: state => { | ||
state.error = undefined | ||
} | ||
}, | ||
extraReducers: builder => { | ||
builder | ||
.addCase(getBlogPosts.pending, state => { | ||
state.isLoading = true | ||
}) | ||
.addCase(getBlogPosts.fulfilled, (state, { payload }) => { | ||
state.isLoading = false | ||
state.posts = payload | ||
}) | ||
.addCase(getBlogPosts.rejected, (state, { payload }) => { | ||
state.isLoading = false | ||
state.error = rejectedPayloadHandle(payload) | ||
}) | ||
} | ||
}) | ||
export const { actions: blogPostsActions, reducer: blogPostsReducer } = blogPostsSlice |
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,33 @@ | ||
export interface IPaginatedResponse<T> { | ||
count: number | ||
previous: string | ||
next: string | ||
results: T[] | ||
} | ||
export interface IBlogTagData { | ||
name: string | ||
} | ||
export interface TBlogCategoryLight { | ||
title: string | ||
slug: string | ||
} | ||
export interface IBlogPostData { | ||
id: number | ||
title: string | ||
text: string | ||
pub_date: string | ||
author: string | ||
image: string | ||
category: TBlogCategoryLight | ||
tags: IBlogTagData[] | ||
views: number | ||
slug: string | ||
meta_title: string | ||
meta_description: string | ||
} | ||
|
||
export interface IBlogPostsSchema { | ||
isLoading: boolean | ||
posts: IBlogPostData[] | ||
error?: string | string[] | ||
} |
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