-
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.
- Loading branch information
Showing
23 changed files
with
217 additions
and
39 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
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 |
---|---|---|
|
@@ -11,3 +11,7 @@ select { | |
margin: 0; | ||
font: inherit; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { ArticleDetailsPageAsync as ArticleDetailsPage } from './ui/ArticleDetailsPage/ArticleDetailsPage.async'; | ||
export { ArticleDetailsCommentsSchema } from './model/types/ArticleDetailsCommentsSchema'; | ||
export { ArticleDetailsPageSchema } from './model/types'; |
4 changes: 2 additions & 2 deletions
4
src/pages/ArticleDetailsPage/model/selectors/comments/comments.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
export const getArticleCommentsIsLoading = (state: StateSchema) => state.articleDetailsComments?.isLoading; | ||
export const getArticleCommentsError = (state: StateSchema) => state.articleDetailsComments?.error; | ||
export const getArticleCommentsIsLoading = (state: StateSchema) => state.articleDetailsPage?.comments.isLoading; | ||
export const getArticleCommentsError = (state: StateSchema) => state.articleDetailsPage?.comments.error; |
9 changes: 9 additions & 0 deletions
9
src/pages/ArticleDetailsPage/model/selectors/recommendations/recommendations.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,9 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
export const getArticleRecommendationsIsLoading = ( | ||
state: StateSchema, | ||
) => state.articleDetailsPage?.recommendations.isLoading; | ||
|
||
export const getArticleRecommendationsError = ( | ||
state: StateSchema, | ||
) => state.articleDetailsPage?.recommendations.error; |
27 changes: 27 additions & 0 deletions
27
...icleDetailsPage/model/services/fetchArticleRecommendations/fetchArticleRecommendations.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,27 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
import { ThunkConfig } from 'app/providers/StoreProvider'; | ||
import { Article } from 'entities/Article'; | ||
|
||
export const fetchArticleRecommendations = createAsyncThunk<Article[], void, ThunkConfig<string>>( | ||
'articleDetailsPage/fetchArticleRecommendations', | ||
async (args, thunkAPI) => { | ||
const { extra, rejectWithValue } = thunkAPI; | ||
|
||
try { | ||
const response = await extra.api.get<Article[]>('/articles', { | ||
params: { | ||
_limit: 4, | ||
}, | ||
}); | ||
|
||
if (!response.data) { | ||
throw new Error(); | ||
} | ||
|
||
return response.data; | ||
} catch (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
45 changes: 45 additions & 0 deletions
45
src/pages/ArticleDetailsPage/model/slices/articleDetailsRecommendationsSlice.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,45 @@ | ||
import { createEntityAdapter, createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
|
||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
import { Article } from 'entities/Article'; | ||
|
||
import { | ||
fetchArticleRecommendations, | ||
} from '../../model/services/fetchArticleRecommendations/fetchArticleRecommendations'; | ||
import { ArticleDetailsRecommendationsSchema } from '../types/ArticleDetailsRecommendationsSchema'; | ||
|
||
const recommendationsAdapter = createEntityAdapter<Article>({ | ||
selectId: (article) => article.id, | ||
}); | ||
|
||
export const getArticleRecommendations = recommendationsAdapter.getSelectors<StateSchema>( | ||
(state) => state.articleDetailsPage?.recommendations || recommendationsAdapter.getInitialState(), | ||
); | ||
|
||
const articleDetailsRecommendationsSlice = createSlice({ | ||
name: 'articleDetailsRecommendationsSlice', | ||
initialState: recommendationsAdapter.getInitialState<ArticleDetailsRecommendationsSchema>({ | ||
isLoading: false, | ||
error: undefined, | ||
ids: [], | ||
entities: {}, | ||
}), | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(fetchArticleRecommendations.pending, (state) => { | ||
state.error = undefined; | ||
state.isLoading = true; | ||
}) | ||
.addCase(fetchArticleRecommendations.fulfilled, (state, action: PayloadAction<Article[]>) => { | ||
state.isLoading = false; | ||
recommendationsAdapter.setAll(state, action.payload); | ||
}) | ||
.addCase(fetchArticleRecommendations.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.error = action.payload; | ||
}); | ||
}, | ||
}); | ||
|
||
export const { reducer: articleDetailsRecommendationsReducer } = articleDetailsRecommendationsSlice; |
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,12 @@ | ||
import { combineReducers } from '@reduxjs/toolkit'; | ||
|
||
import { articleDetailsCommentsReducer } from '../../model/slices/articleDetailsCommentsSlice'; | ||
import { | ||
articleDetailsRecommendationsReducer, | ||
} from '../../model/slices/articleDetailsRecommendationsSlice'; | ||
import { ArticleDetailsPageSchema } from '../types'; | ||
|
||
export const articleDetailsPageReducer = combineReducers<ArticleDetailsPageSchema>({ | ||
comments: articleDetailsCommentsReducer, | ||
recommendations: articleDetailsRecommendationsReducer, | ||
}); |
8 changes: 8 additions & 0 deletions
8
src/pages/ArticleDetailsPage/model/types/ArticleDetailsRecommendationsSchema.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,8 @@ | ||
import { EntityState } from '@reduxjs/toolkit'; | ||
|
||
import { Article } from 'entities/Article'; | ||
|
||
export interface ArticleDetailsRecommendationsSchema extends EntityState<Article>{ | ||
isLoading?: boolean; | ||
error?: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { | ||
ArticleDetailsCommentsSchema, | ||
} from '../types/ArticleDetailsCommentsSchema'; | ||
import { | ||
ArticleDetailsRecommendationsSchema, | ||
} from '../types/ArticleDetailsRecommendationsSchema'; | ||
|
||
export interface ArticleDetailsPageSchema { | ||
comments: ArticleDetailsCommentsSchema, | ||
recommendations: ArticleDetailsRecommendationsSchema, | ||
} |
8 changes: 8 additions & 0 deletions
8
src/pages/ArticleDetailsPage/ui/ArticleDetailsPage/ArticleDetailsPage.module.scss
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
.commentTitle { | ||
margin-top: 20px; | ||
} | ||
|
||
.recommendations { | ||
margin-top: 20px; | ||
flex-wrap: nowrap; | ||
overflow-x: auto; | ||
overflow-y: hidden; | ||
justify-content: flex-start; | ||
} |
Oops, something went wrong.