-
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 create new and edit article pages
- Loading branch information
Showing
21 changed files
with
209 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ArticleEditPageAsync as ArticleEditPage } from './ui/ArticleEditPage.async'; |
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 { lazy } from 'react'; | ||
|
||
export const ArticleEditPageAsync = lazy(() => new Promise((resolve) => { | ||
// @ts-ignore | ||
// ТАК В РЕАЛЬНЫХ ПРОЕКТАХ НЕ ДЕЛАТЬ!!!!! ДЕЛАЕМ ДЛЯ КУРСА! | ||
setTimeout(() => resolve(import('./ArticleEditPage')), 1500); | ||
})); |
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 @@ | ||
.ArticleEditPage { | ||
|
||
} |
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,17 @@ | ||
import React from 'react'; | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import { ArticleEditPage } from './ArticleEditPage'; | ||
|
||
export default { | ||
title: 'shared/ArticleEditPage', | ||
component: ArticleEditPage, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof ArticleEditPage>; | ||
|
||
const Template: ComponentStory<typeof ArticleEditPage> = (args) => <ArticleEditPage {...args} />; | ||
|
||
export const Normal = Template.bind({}); | ||
Normal.args = {}; |
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,23 @@ | ||
import { classNames } from 'shared/lib/classNames/classNames'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { memo } from 'react'; | ||
import { Page } from 'widgets/Page/Page'; | ||
import { useParams } from 'react-router-dom'; | ||
import cls from './ArticleEditPage.module.scss'; | ||
|
||
interface ArticleEditPageProps { | ||
className?: string; | ||
} | ||
const ArticleEditPage = memo((props: ArticleEditPageProps) => { | ||
const { className } = props; | ||
const { t } = useTranslation(); | ||
const { id } = useParams<{ id: string }>(); | ||
const isEdit = Boolean(id); | ||
return ( | ||
<Page className={classNames(cls.ArticleEditPage, {}, [className])}> | ||
{isEdit ? 'Edit article' : 'Create new article'} | ||
</Page> | ||
); | ||
}); | ||
|
||
export default ArticleEditPage; |
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,10 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
import { getArticlesDetailsData } from '../../../../entities/Article'; | ||
import { getUserAuthData } from '../../../../entities/User'; | ||
|
||
export const getCanEditArticle = createSelector(getArticlesDetailsData, getUserAuthData, (article, user) => { | ||
if (!article || !user) { | ||
return false; | ||
} | ||
return article.user.id === user.id; | ||
}); |
File renamed without changes.
File renamed without changes.
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
8 changes: 8 additions & 0 deletions
8
...es/ArticlesDetailsPage/ui/ArticlesDetailsPageHeader/ArticlesDetailsPageHeader.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.ArticlesDetailsPageHeader { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.editBtn { | ||
margin-left: auto; | ||
} |
17 changes: 17 additions & 0 deletions
17
...es/ArticlesDetailsPage/ui/ArticlesDetailsPageHeader/ArticlesDetailsPageHeader.stories.tsx
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,17 @@ | ||
import React from 'react'; | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import { ArticlesDetailsPageHeader } from './ArticlesDetailsPageHeader'; | ||
|
||
export default { | ||
title: 'shared/ArticlesDetailsPageHeader', | ||
component: ArticlesDetailsPageHeader, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof ArticlesDetailsPageHeader>; | ||
|
||
const Template: ComponentStory<typeof ArticlesDetailsPageHeader> = (args) => <ArticlesDetailsPageHeader {...args} />; | ||
|
||
export const Normal = Template.bind({}); | ||
Normal.args = {}; |
54 changes: 54 additions & 0 deletions
54
src/pages/ArticlesDetailsPage/ui/ArticlesDetailsPageHeader/ArticlesDetailsPageHeader.tsx
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 { classNames } from 'shared/lib/classNames/classNames'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { memo, useCallback } from 'react'; | ||
import { Button, ButtonTheme } from 'shared/ui/Button/Button'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { RoutePath } from 'shared/config/routeConfig/routeConfig'; | ||
import { useSelector } from 'react-redux'; | ||
import { getCanEditArticle } from 'pages/ArticlesDetailsPage/model/selectors/article'; | ||
import { getUserAuthData } from '../../../../entities/User'; | ||
import { getArticlesDetailsData } from '../../../../entities/Article'; | ||
import cls from './ArticlesDetailsPageHeader.module.scss'; | ||
|
||
interface ArticlesDetailsPageHeaderProps { | ||
className?: string; | ||
} | ||
|
||
export const ArticlesDetailsPageHeader = memo((props: ArticlesDetailsPageHeaderProps) => { | ||
const { className } = props; | ||
const { t } = useTranslation(); | ||
|
||
const navigate = useNavigate(); | ||
const article = useSelector(getArticlesDetailsData); | ||
|
||
const onBackToList = useCallback(() => { | ||
navigate(RoutePath.articles); | ||
}, [navigate]); | ||
|
||
const onEditArticle = useCallback(() => { | ||
navigate(`${RoutePath.article_details}${article?.id}/edit`); | ||
}, [article?.id, navigate]); | ||
|
||
const canEdit = useSelector(getCanEditArticle); | ||
|
||
return ( | ||
<div className={classNames(cls.ArticlesDetailsPageHeader, {}, [className])}> | ||
<Button | ||
theme={ButtonTheme.OUTLINE} | ||
onClick={onBackToList} | ||
> | ||
{t('Back to list')} | ||
</Button> | ||
{canEdit && ( | ||
<Button | ||
className={cls.editBtn} | ||
theme={ButtonTheme.OUTLINE} | ||
onClick={onEditArticle} | ||
> | ||
{t('Edit')} | ||
</Button> | ||
)} | ||
|
||
</div> | ||
); | ||
}); |
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 |
---|---|---|
|
@@ -14,3 +14,8 @@ | |
.mainLink { | ||
margin-right: 15px; | ||
} | ||
|
||
.appName { | ||
width: var(--sidebar-width); | ||
margin-left: 15px; | ||
} |
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