Skip to content

Commit

Permalink
implements: refactoring article entity
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-scrpt committed Oct 18, 2023
1 parent 43018ed commit f628f24
Show file tree
Hide file tree
Showing 72 changed files with 241 additions and 265 deletions.
93 changes: 21 additions & 72 deletions server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@
"views": 1,
"createdAt": "26.04.2022",
"userId": "1",
"tagsId": [
"1",
"2",
"3"
],
"tagsId": ["1", "2", "3"],
"blocks": [
{
"id": "1",
Expand Down Expand Up @@ -196,9 +192,7 @@
"views": 2,
"createdAt": "26.02.2022",
"userId": "2",
"tagsId": [
"2"
],
"tagsId": ["2"],
"blocks": [
{
"id": "1",
Expand All @@ -219,10 +213,8 @@
"img": "https://miro.medium.com/max/1200/1*FNakkrty3kjOvNU8m5iQfw.png",
"views": 3,
"createdAt": "26.02.2019",
"userId": "3",
"tagsId": [
"3"
],
"userId": "2",
"tagsId": ["3"],
"blocks": [
{
"id": "1",
Expand All @@ -244,10 +236,7 @@
"views": 10222,
"createdAt": "24.01.2022",
"userId": "1",
"tagsId": [
"3",
"4"
],
"tagsId": ["3", "4"],
"blocks": [
{
"id": "1",
Expand All @@ -269,10 +258,7 @@
"views": 10222,
"createdAt": "26.02.2020",
"userId": "1",
"tagsId": [
"2",
"3"
],
"tagsId": ["2", "3"],
"blocks": [
{
"id": "1",
Expand All @@ -294,11 +280,7 @@
"views": 1022,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"1",
"4",
"5"
],
"tagsId": ["1", "4", "5"],
"blocks": [
{
"id": "1",
Expand All @@ -320,10 +302,7 @@
"views": 100,
"createdAt": "21.02.2022",
"userId": "1",
"tagsId": [
"1",
"5"
],
"tagsId": ["1", "5"],
"blocks": [
{
"id": "1",
Expand All @@ -345,10 +324,7 @@
"views": 102222,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"4",
"5"
],
"tagsId": ["4", "5"],
"blocks": [
{
"id": "1",
Expand All @@ -370,9 +346,7 @@
"views": 1022,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"1"
],
"tagsId": ["1"],
"blocks": [
{
"id": "1",
Expand All @@ -394,9 +368,7 @@
"views": 1022,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"1"
],
"tagsId": ["1"],
"blocks": [
{
"id": "1",
Expand All @@ -418,9 +390,7 @@
"views": 1022,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"1"
],
"tagsId": ["1"],
"blocks": [
{
"id": "1",
Expand All @@ -442,9 +412,7 @@
"views": 66687,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"1"
],
"tagsId": ["1"],
"blocks": [
{
"id": "1",
Expand All @@ -466,10 +434,7 @@
"views": 48,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"1",
"3"
],
"tagsId": ["1", "3"],
"blocks": [
{
"id": "1",
Expand All @@ -491,10 +456,7 @@
"views": 1022,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"2",
"4"
],
"tagsId": ["2", "4"],
"blocks": [
{
"id": "1",
Expand All @@ -516,9 +478,7 @@
"views": 555,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"5"
],
"tagsId": ["5"],
"blocks": [
{
"id": "1",
Expand All @@ -540,10 +500,7 @@
"views": 101,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"3",
"4"
],
"tagsId": ["3", "4"],
"blocks": [
{
"id": "1",
Expand All @@ -565,9 +522,7 @@
"views": 5,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"4"
],
"tagsId": ["4"],
"blocks": [
{
"id": "1",
Expand All @@ -589,9 +544,7 @@
"views": 1111,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"2"
],
"tagsId": ["2"],
"blocks": [
{
"id": "1",
Expand All @@ -613,11 +566,7 @@
"views": 58,
"createdAt": "26.02.2022",
"userId": "1",
"tagsId": [
"2",
"3",
"4"
],
"tagsId": ["2", "3", "4"],
"blocks": [
{
"id": "1",
Expand Down Expand Up @@ -724,4 +673,4 @@
"id": "vlh_SR2"
}
]
}
}
3 changes: 1 addition & 2 deletions src/app/provider/StoreProvider/type/state.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DeepPartial, ReducersMapObject } from '@reduxjs/toolkit'
import { ArticleState } from 'entity/Article'
import { ArticleFeedState } from 'entity/ArticleFeed/type/state.type'
import { ArticleFeedState, ArticleState } from 'entity/Article'
import { ArticleRecomendedState } from 'entity/ArticleRecomended'
import { CounterState } from 'entity/Counter'
import { CountryState } from 'entity/Country'
Expand Down
14 changes: 8 additions & 6 deletions src/entity/Article/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export { Article } from './ui/Article/Article'
export { IArticle } from './type/article.type'
export { ArticleState } from './type/state.type'
export { getArticleData } from './model/selector/getArticleData'
export { getArticleError } from './model/selector/getArticleError'
export { getArticleIsLoading } from './model/selector/getArticleIsLoading'
export { ArticleFeed } from './ui/ArticleFeed/ArticleFeed'
export { ArticleFeedItem } from './ui/ArticleFeedItem/ArticleFeedItem'

export { ArticleBlockVariantEnum, IArticleBlockText } from './type/article.type'
export * from './type'
export * from './model/service/articleFeed'
export * from './model/service/article'
export * from './model/slice'
export * from './model/selector/article'
export * from './model/selector/articleFeed'
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/entity/Article/model/selector/article/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './getArticleData'
export * from './getArticleIsLoading'
export * from './getArticleError'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StateSchema } from 'app/provider/StoreProvider'

import { articleFeedAdapter } from '../../slice'

export const getArticleFeedData = articleFeedAdapter.getSelectors<StateSchema>(
(state) => {
console.log('=>>>>>>>>>>>>>> state', state)
return state.articleFeed || articleFeedAdapter.getInitialState()
}
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StateSchema } from 'app/provider/StoreProvider'
import { ArticleFeedOrderEnum } from 'entity/ArticleFeed/type/order.enum'

import { ArticleFeedOrderEnum } from '../../../type'

export const getArticleFeedOrder = (state: StateSchema) =>
state.articleFeed?.order ?? ArticleFeedOrderEnum.ASC
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StateSchema } from 'app/provider/StoreProvider'
import { ArticleFeedSortFieldEnum } from 'entity/ArticleFeed/type/sort.enum'

import { ArticleFeedSortFieldEnum } from '../../../type'

export const getArticleFeedSort = (state: StateSchema) =>
state.articleFeed?.sort ?? ArticleFeedSortFieldEnum.CREATED
14 changes: 14 additions & 0 deletions src/entity/Article/model/selector/articleFeed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export * from './getArticleFeedBaseLimit'
export * from './getArticleFeedData'
export * from './getArticleFeedError'
export * from './getArticleFeedHasMore'
export * from './getArticleFeedInited'
export * from './getArticleFeedIsLoading'
export * from './getArticleFeedLimit'
export * from './getArticleFeedOrder'
export * from './getArticleFeedPage'
export * from './getArticleFeedSearch'
export * from './getArticleFeedSort'
export * from './getArticleFeedTag'
export * from './getArticleFeedView'
export * from './getArticleFeedViewActive'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createAsyncThunk } from '@reduxjs/toolkit'
import { ThunkConfigType } from 'app/provider/StoreProvider'

import { IArticle } from '../../type/article.type'
import { IArticle } from '../../../type'

export const fetchArticleData = createAsyncThunk<
IArticle,
Expand Down
1 change: 1 addition & 0 deletions src/entity/Article/model/service/article/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './fetchAritcleData'
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createAsyncThunk } from '@reduxjs/toolkit'
import { ThunkConfigType } from 'app/provider/StoreProvider'
import { ArticleFeedOrderEnum } from 'entity/ArticleFeed/type/order.enum'
import { storageFeedOrder } from 'shared/lib/storage/LocalStorage'

import { articleFeedAction } from '../slice/articleFeed.slice'
import { ArticleFeedOrderEnum } from '../../../type'
import { articleFeedAction } from '../../slice'
import { fetchArticleFeed } from './fetchArticleFeed'

export const changeArticleFeedOrder = createAsyncThunk<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createAsyncThunk } from '@reduxjs/toolkit'
import { ThunkConfigType } from 'app/provider/StoreProvider'

import { articleFeedAction } from '../slice/articleFeed.slice'
import { articleFeedAction } from '../../slice'
import { fetchArticleFeed } from './fetchArticleFeed'

export const changeArticleFeedSearch = createAsyncThunk<
Expand All @@ -12,7 +12,6 @@ export const changeArticleFeedSearch = createAsyncThunk<
const { rejectWithValue, dispatch } = thunkAPI

try {
console.log('search', query)
dispatch(articleFeedAction.setSearch(query))
dispatch(articleFeedAction.setPage(1))
dispatch(fetchArticleFeed())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { createAsyncThunk } from '@reduxjs/toolkit'
import { ThunkConfigType } from 'app/provider/StoreProvider'
import { storageFeedSort } from 'shared/lib/storage/LocalStorage'

import { ArticleFeedSortFieldEnum } from '../../type/sort.enum'
import { articleFeedAction } from '../slice/articleFeed.slice'
import { ArticleFeedSortFieldEnum } from '../../../type/sort.enum'
import { articleFeedAction } from '../../slice'
import { fetchArticleFeed } from './fetchArticleFeed'

export const changeArticleFeedSort = createAsyncThunk<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createAsyncThunk } from '@reduxjs/toolkit'
import { ThunkConfigType } from 'app/provider/StoreProvider'

import { articleFeedAction } from '../slice/articleFeed.slice'
import { articleFeedAction } from '../../slice'
import { fetchArticleFeed } from './fetchArticleFeed'

export const changeArticleFeedTag = createAsyncThunk<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
storageFeedView,
} from 'shared/lib/storage/LocalStorage'

import { ArticleFeedViewEnum } from '../../type/view.enum'
import { getArticleFeedLimitBase } from '../selector/getArticleFeedBaseLimit'
import { articleFeedAction } from '../slice/articleFeed.slice'
import { ArticleFeedViewEnum } from '../../../type/view.enum'
import { getArticleFeedLimitBase } from '../../selector/articleFeed'
import { articleFeedAction } from '../../slice'
import { fetchArticleFeed } from './fetchArticleFeed'

export const changeArticleFeedView = createAsyncThunk<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { createAsyncThunk } from '@reduxjs/toolkit'
import { ThunkConfigType } from 'app/provider/StoreProvider'
import { IArticle } from 'entity/Article'
import { controlQueryParams } from 'shared/lib/queryParams/controlQueryParams'

import { getArticleFeedLimit } from '../selector/getArticleFeedLimit'
import { getArticleFeedOrder } from '../selector/getArticleFeedOrder'
import { getArticleFeedPage } from '../selector/getArticleFeedPage'
import { getArticleFeedSearch } from '../selector/getArticleFeedSearch'
import { getArticleFeedSort } from '../selector/getArticleFeedSort'
import { getArticleFeedTag } from '../selector/getArticleFeedTag'
import { IArticle } from '../../../type'
import {
getArticleFeedLimit,
getArticleFeedOrder,
getArticleFeedPage,
getArticleFeedSearch,
getArticleFeedSort,
getArticleFeedTag,
} from '../../selector/articleFeed'

export const fetchArticleFeed = createAsyncThunk<
IArticle[],
Expand Down
Loading

0 comments on commit f628f24

Please sign in to comment.