-
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.
added feature AddArticleComents and entiti Comment, added profile pag…
…es for users, added article list, article item and skeleton
- Loading branch information
Showing
80 changed files
with
1,732 additions
and
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { userReducer } from "entities/User"; | |
import { createReducerManager } from "./reducerManager"; | ||
import { $api } from "shared/api/api"; | ||
import { To, NavigateOptions } from "react-router-dom"; | ||
import { rtkQueryApi } from "shared/api/rtkQueryApi"; | ||
|
||
export function createReduxStore( | ||
initialState?: StateSchema, | ||
|
@@ -16,7 +17,8 @@ export function createReduxStore( | |
const rootRedusers: ReducersMapObject<StateSchema> = { | ||
...asyncReducers, | ||
counter: counterReducer, | ||
user: userReducer | ||
user: userReducer, | ||
[rtkQueryApi.reducerPath]: rtkQueryApi.reducer, | ||
}; | ||
|
||
const reducerManager = createReducerManager(rootRedusers); | ||
|
@@ -34,7 +36,7 @@ export function createReduxStore( | |
thunk: { | ||
extraArgument | ||
}, | ||
}) | ||
}).concat(rtkQueryApi.middleware), | ||
}); | ||
|
||
// @ts-ignore | ||
Check warning on line 42 in src/app/providers/StoreProvider/config/store.ts GitHub Actions / pipeline (20.7.0)
|
||
|
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 @@ | ||
export { ArticleList } from "./ui/ArticleList"; | ||
|
||
export { ArticleDetails } from "./ui/ArticleDetails/ui/ArticleDetails"; | ||
|
||
export type { Article } from "./model/types/Article"; | ||
export type { ArticleDetailsSchema } from "./model/types/ArticleDetailsSchema"; |
3 changes: 3 additions & 0 deletions
3
...ies/Article/model/selectors/ArticleDetails/getArticleDetailsData/getArticleDetailsData.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,3 @@ | ||
import { StateSchema } from "app/providers/StoreProvider"; | ||
|
||
export const getArticleDetailsData = (state: StateSchema) => state.articleDetails?.data; |
3 changes: 3 additions & 0 deletions
3
...s/Article/model/selectors/ArticleDetails/getArticleDetailsError/getArticleDetailsError.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,3 @@ | ||
import { StateSchema } from "app/providers/StoreProvider"; | ||
|
||
export const getArticleDetailsError = (state: StateSchema) => state.articleDetails?.error; |
3 changes: 3 additions & 0 deletions
3
...e/model/selectors/ArticleDetails/getArticleDetailsIsLoading/getArticleDetailsIsLoading.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,3 @@ | ||
import { StateSchema } from "app/providers/StoreProvider"; | ||
|
||
export const getArticleDetailsIsLoading = (state: StateSchema) => state.articleDetails?.isLoading; |
31 changes: 31 additions & 0 deletions
31
src/entities/Article/model/services/fetchArticlesById/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,31 @@ | ||
import { createAsyncThunk } from "@reduxjs/toolkit"; | ||
import { ThunkConfig } from "app/providers/StoreProvider"; | ||
import { Article } from "../../types/Article"; | ||
import { USER_LOCALSTORAGE_KEY } from "shared/const/localStorage"; | ||
|
||
export const fetchArticleById = createAsyncThunk<Article, string, ThunkConfig<string>>( | ||
"profile/fetchArticleById", | ||
async (articleId, thunkApi) => { | ||
const { rejectWithValue, extra } = thunkApi; | ||
|
||
try { | ||
const token = localStorage.getItem(USER_LOCALSTORAGE_KEY) || ""; | ||
const encodedToken = encodeURIComponent(token); | ||
|
||
const response = await extra.api.get<Article>(`/articles/${articleId}&_expand=user`, { | ||
headers: { | ||
"Authorization": `${encodedToken}` | ||
} | ||
}); | ||
|
||
if (!response.data) { | ||
throw new Error(); | ||
} | ||
|
||
return response.data; | ||
} catch (error) { | ||
console.log(error); | ||
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 { PayloadAction, createSlice } from "@reduxjs/toolkit"; | ||
import { ArticleDetailsSchema } from "../types/ArticleDetailsSchema"; | ||
import { Article } from "../types/Article"; | ||
import { fetchArticleById } from "../services/fetchArticlesById/fetchArticleById"; | ||
|
||
const initialState: ArticleDetailsSchema = { | ||
}; | ||
|
||
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,54 @@ | ||
import { User } from "entities/User"; | ||
|
||
export enum ArticleBlockType { | ||
CODE = "CODE", | ||
IMAGE = "IMAGE", | ||
TEXT = "TEXT", | ||
} | ||
|
||
export enum ArticleListView { | ||
GRID = "GRID", | ||
COLUMN = "COLUMN" | ||
} | ||
|
||
export interface ArticleBlockBase { | ||
id: string; | ||
type: ArticleBlockType; | ||
} | ||
|
||
export interface ArticleCodeBlock extends ArticleBlockBase { | ||
type: ArticleBlockType.CODE; | ||
code: string; | ||
} | ||
|
||
export interface ArticleImageBlock extends ArticleBlockBase { | ||
type: ArticleBlockType.IMAGE; | ||
src: string, | ||
title: string, | ||
} | ||
|
||
export interface ArticleTextBlock extends ArticleBlockBase { | ||
type: ArticleBlockType.TEXT; | ||
title?: string; | ||
paragraphs: string[]; | ||
} | ||
|
||
export type ArticleBlock = ArticleCodeBlock | ArticleImageBlock | ArticleTextBlock; | ||
|
||
export enum ArticleType { | ||
IT = "IT", | ||
SCIENCE = "SCIENCE", | ||
ECONOMYCS = "ECONOMYCS", | ||
} | ||
|
||
export interface Article { | ||
id: string; | ||
user: User; | ||
title: string; | ||
subtitle: string; | ||
img: string; | ||
views: number; | ||
createdAt: string; | ||
type: ArticleType[]; | ||
blocks: ArticleBlock[]; | ||
} |
Oops, something went wrong.