-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add logic for articles and skeleton
- Loading branch information
Showing
39 changed files
with
616 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ArticleDetails": "", | ||
"Произошла ошибка при загрузке статьи": "", | ||
"Список статей": "", | ||
"Статья не найдена": "" | ||
} |
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 was deleted.
Oops, something went wrong.
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,6 @@ | ||
{ | ||
"Список статей": "List of articles", | ||
"Статья не найдена": "Article not found", | ||
"Произошла ошибка при загрузке статьи": "An error occurred while loading the article", | ||
"Articles page": "Articles" | ||
} |
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 was deleted.
Oops, something went wrong.
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,6 @@ | ||
{ | ||
"Список статей": "Список статей", | ||
"Статья не найдена": "Статья не найдена", | ||
"Произошла ошибка при загрузке статьи": "Произошла ошибка при загрузке статьи", | ||
"Articles page": "Статьи" | ||
} |
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
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,8 @@ | ||
export { ArticleDetails } from './ui/ArticleDetails/ArticleDetails'; | ||
export { Article } from './model/types/article'; | ||
export { ArticleDetailsSchema } from './model/types/articleDetailsSchema'; | ||
export { | ||
getArticleDetails, | ||
getArticleDetailsIsLoading, | ||
getArticleDetailsError, | ||
} from './model/selectors/getArticleDetails/getArticleDetails'; |
5 changes: 5 additions & 0 deletions
5
src/entities/Article/model/selectors/getArticleDetails/getArticleDetails.ts
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 getArticleDetails = (state: StateSchema) => state.articleDetails?.data; | ||
export const getArticleDetailsIsLoading = (state: StateSchema) => state.articleDetails?.isLoading; | ||
export const getArticleDetailsError = (state: StateSchema) => state.articleDetails?.error; |
25 changes: 25 additions & 0 deletions
25
src/entities/Article/model/services/fetchArticleById/fetchArticleById.ts
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,25 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
import { ThunkConfig } from 'app/providers/StoreProvider'; | ||
|
||
import { Article } from '../../types/article'; | ||
|
||
export const fetchArticleById = createAsyncThunk<Article, string, ThunkConfig<string>>( | ||
'getArticleDetails/fetchArticleById', | ||
async (articleId, thunkAPI) => { | ||
const { extra, rejectWithValue } = thunkAPI; | ||
|
||
try { | ||
const response = await extra.api.get<Article>(`/articles/${articleId}`); | ||
|
||
if (!response.data) { | ||
throw new Error(); | ||
} | ||
|
||
return response.data; | ||
} catch (e) { | ||
console.log(e); | ||
return rejectWithValue('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, PayloadAction } from '@reduxjs/toolkit'; | ||
|
||
import { fetchArticleById } from '../services/fetchArticleById/fetchArticleById'; | ||
import { ArticleDetailsSchema } from '../types/articleDetailsSchema'; | ||
import { Article } from '../types/article'; | ||
|
||
const initialState: ArticleDetailsSchema = { | ||
isLoading: false, | ||
error: undefined, | ||
data: undefined, | ||
}; | ||
|
||
export const articleDetailsSlice = createSlice({ | ||
name: 'articleDetails', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(fetchArticleById.pending, (state) => { | ||
state.error = undefined; | ||
state.isLoading = true; | ||
}) | ||
.addCase(fetchArticleById.fulfilled, (state, action: PayloadAction<Article>) => { | ||
state.isLoading = false; | ||
state.data = action.payload; | ||
}) | ||
.addCase(fetchArticleById.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.error = action.payload; | ||
}); | ||
}, | ||
}); | ||
|
||
export const { actions: articleDetailsActions } = articleDetailsSlice; | ||
export const { reducer: articleDetailsReducer } = articleDetailsSlice; |
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,46 @@ | ||
export enum ArticleBlockType { | ||
TEXT = 'TEXT', | ||
CODE = 'CODE', | ||
IMAGE = 'IMAGE' | ||
} | ||
|
||
export interface ArticleBlockBase { | ||
id: string; | ||
type: ArticleBlockType; | ||
} | ||
|
||
export interface ArticleTextBlock extends ArticleBlockBase { | ||
type: ArticleBlockType.TEXT; | ||
title?: string; | ||
paragraphs: string[]; | ||
} | ||
|
||
export interface ArticleCodeBlock extends ArticleBlockBase { | ||
type: ArticleBlockType.CODE; | ||
code: string; | ||
} | ||
|
||
export interface ArticleImageBlock extends ArticleBlockBase { | ||
type: ArticleBlockType.IMAGE; | ||
src: string; | ||
title: string; | ||
} | ||
|
||
export type ArticleBlock = ArticleTextBlock | ArticleCodeBlock | ArticleImageBlock; | ||
|
||
export enum ArticleType { | ||
IT = 'IT', | ||
SCIENCE = 'SCIENCE', | ||
ECONOMICS = 'ECONOMICS' | ||
} | ||
|
||
export interface Article { | ||
id: string; | ||
title: string; | ||
subtitle: string; | ||
img: string; | ||
views: number; | ||
createdAt: string; | ||
type: ArticleType[]; | ||
blocks: ArticleBlock[]; | ||
} |
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,7 @@ | ||
import { Article } from './article'; | ||
|
||
export interface ArticleDetailsSchema { | ||
isLoading: boolean; | ||
error?: string; | ||
data?: Article; | ||
} |
Oops, something went wrong.