-
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
24 changed files
with
717 additions
and
111 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,16 +1,17 @@ | ||
import { ReactNode } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { Navigate, useLocation } from 'react-router-dom'; | ||
|
||
import { getUserAuthData } from 'entities/User'; | ||
import { AppRoutes, RoutePath } from 'shared/config/routerConfig/routerConfig'; | ||
|
||
export function RequireAuth({ children }: {children: JSX.Element}) { | ||
export function RequireAuth({ children }: {children: ReactNode}) { | ||
const auth = useSelector(getUserAuthData); | ||
const location = useLocation(); | ||
|
||
if (!auth?.username) { | ||
return <Navigate to={RoutePath[AppRoutes.MAIN]} state={{ from: location }} replace />; | ||
} | ||
|
||
return children; | ||
return children as JSX.Element; | ||
} |
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,12 +1,14 @@ | ||
import { VFC } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Page } from 'shared/ui/Page'; | ||
|
||
export const AboutPage: VFC = () => { | ||
const { t } = useTranslation('about'); | ||
|
||
return ( | ||
<div> | ||
<Page> | ||
{t('О сайте')} | ||
</div> | ||
</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
46 changes: 46 additions & 0 deletions
46
src/pages/ArticlesPage/model/services/fetchNextArticlesPage/fetchNextArticlesPage.test.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,46 @@ | ||
import { TestAsyncThunk } from 'shared/lib/tests/testAsyncThunk/TestAsyncThunk'; | ||
|
||
import { fetchArticlesList } from '../fetchArticlesList/fetchArticlesList'; | ||
import { fetchNextArticlesPage } from './fetchNextArticlesPage'; | ||
|
||
jest.mock('../fetchArticlesList/fetchArticlesList'); | ||
|
||
describe('fetchNextArticlesPage.test', () => { | ||
test('success fetch', async () => { | ||
const thunk = new TestAsyncThunk(fetchNextArticlesPage, { | ||
articlesPage: { | ||
page: 2, | ||
ids: [], | ||
entities: {}, | ||
limit: 5, | ||
isLoading: false, | ||
hasMore: true, | ||
}, | ||
}); | ||
|
||
await thunk.callThunk(); | ||
|
||
expect(thunk.dispatch).toBeCalledTimes(4); | ||
expect(fetchArticlesList).toBeCalledWith({ | ||
page: 3, | ||
}); | ||
}); | ||
|
||
test('fetchArticleList not called', async () => { | ||
const thunk = new TestAsyncThunk(fetchNextArticlesPage, { | ||
articlesPage: { | ||
page: 2, | ||
ids: [], | ||
entities: {}, | ||
limit: 5, | ||
isLoading: false, | ||
hasMore: false, | ||
}, | ||
}); | ||
|
||
await thunk.callThunk(); | ||
|
||
expect(thunk.dispatch).toBeCalledTimes(2); | ||
expect(fetchArticlesList).not.toHaveBeenCalled(); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
src/pages/ArticlesPage/model/services/fetchNextArticlesPage/fetchNextArticlesPage.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,30 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
import { ThunkConfig } from 'app/providers/StoreProvider'; | ||
|
||
import { articlesPageActions } from '../../slices/articlesPageSlice'; | ||
import { fetchArticlesList } from '../../services/fetchArticlesList/fetchArticlesList'; | ||
import { | ||
getArticlesPageHasMore, | ||
getArticlesPageIsLoading, | ||
getArticlesPageNumber, | ||
} from '../../selectors/articlesPageSelectors'; | ||
|
||
export const fetchNextArticlesPage = createAsyncThunk<void, void, ThunkConfig<string>>( | ||
'articlesPage/fetchNextArticlesPage', | ||
async (_, thunkAPI) => { | ||
const { | ||
getState, dispatch, | ||
} = thunkAPI; | ||
const hasMore = getArticlesPageHasMore(getState()); | ||
const page = getArticlesPageNumber(getState()); | ||
const isLoading = getArticlesPageIsLoading(getState()); | ||
|
||
if (hasMore && !isLoading) { | ||
dispatch(articlesPageActions.setPage(page + 1)); | ||
dispatch(fetchArticlesList({ | ||
page: page + 1, | ||
})); | ||
} | ||
}, | ||
); |
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,12 +1,14 @@ | ||
import { VFC } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Page } from 'shared/ui/Page'; | ||
|
||
export const MainPage: VFC = () => { | ||
const { t } = useTranslation('main'); | ||
|
||
return ( | ||
<div> | ||
<Page> | ||
{t('Главная страница')} | ||
</div> | ||
</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
Oops, something went wrong.