-
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.
Add feature ArticleEditButton, plural form and edit widget
- Loading branch information
1 parent
df74ff4
commit 73cf8c1
Showing
13 changed files
with
179 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
.PLATE { | ||
.card { | ||
width: 240px; | ||
width: 235px; | ||
height: 350px; | ||
overflow: hidden; | ||
display: flex; | ||
|
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 { ArticleEditButton } from './ui/ArticleEditButton' |
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,41 @@ | ||
import React, { FC, useCallback } from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { useNavigate } from 'react-router-dom' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { ToggleFeaturesComponent } from '@/shared/lib/features' | ||
import { Button as DeprecatedButton, ButtonVariables } from '@/shared/ui/deprecated/Button' | ||
import { getRouteArticleEdit } from '@/shared/const/router' | ||
import { getArticleDetailsData } from '@/entities/Article' | ||
import { Button } from '@/shared/ui/redesigned/Button' | ||
|
||
interface ArticleEditButtonProps { | ||
className?: string | ||
} | ||
|
||
export const ArticleEditButton: FC<ArticleEditButtonProps> = React.memo((props) => { | ||
const { className } = props | ||
const { t } = useTranslation('article-details') | ||
const navigate = useNavigate() | ||
const article = useSelector(getArticleDetailsData) | ||
|
||
const onEditArticle = useCallback(() => { | ||
if (article) { | ||
navigate(getRouteArticleEdit(article?.id)) | ||
} | ||
}, [article, navigate]) | ||
|
||
const deprecatedContent = ( | ||
<DeprecatedButton onClick={onEditArticle} theme={ButtonVariables.OUTLINE}> | ||
{t('Редактировать')} | ||
</DeprecatedButton> | ||
) | ||
|
||
const redesignedContent = ( | ||
<Button onClick={onEditArticle} variant="outline"> | ||
{t('Редактировать')} | ||
</Button> | ||
) | ||
|
||
return <ToggleFeaturesComponent featureName="isAppRedesigned" on={redesignedContent} off={deprecatedContent} /> | ||
}) |
3 changes: 3 additions & 0 deletions
3
src/pages/ArticleDetailsPage/ui/AdditionalInfoContainer/AdditionalInfoContainer.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,3 @@ | ||
.AdditionalInfoContainer { | ||
width: 264px; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/pages/ArticleDetailsPage/ui/AdditionalInfoContainer/AdditionalInfoContainer.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,29 @@ | ||
import React, { FC } from 'react' | ||
import { useSelector } from 'react-redux' | ||
|
||
import cls from './AdditionalInfoContainer.module.scss' | ||
|
||
import { ArticleAdditionalInfo } from '@/widgets/ArticleAdditionalInfo' | ||
import { Card } from '@/shared/ui/redesigned/Card' | ||
import { getArticleDetailsData } from '@/entities/Article' | ||
|
||
interface AdditionalInfoContainerProps { | ||
className?: string | ||
} | ||
|
||
export const AdditionalInfoContainer: FC<AdditionalInfoContainerProps> = React.memo((props) => { | ||
const { className } = props | ||
|
||
const article = useSelector(getArticleDetailsData) | ||
|
||
if (!article) { | ||
return null | ||
} | ||
|
||
return ( | ||
// eslint-disable-next-line i18next/no-literal-string | ||
<Card className={cls.AdditionalInfoContainer} padding="24" borderRadius="round"> | ||
<ArticleAdditionalInfo author={article.user} views={article.views} createdAt={article.createdAt} /> | ||
</Card> | ||
) | ||
}) |
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
20 changes: 20 additions & 0 deletions
20
src/pages/ArticleDetailsPage/ui/DetailsContainer/DetailsContainer.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,20 @@ | ||
import React, { FC } from 'react' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import { Card } from '@/shared/ui/redesigned/Card' | ||
import { ArticleDetails } from '@/entities/Article' | ||
|
||
interface DetailsContainerProps { | ||
className?: string | ||
} | ||
|
||
export const DetailsContainer: FC<DetailsContainerProps> = React.memo((props) => { | ||
const { className } = props | ||
const { id } = useParams<{ id: string }>() | ||
|
||
return ( | ||
<Card max className={className} padding="24"> | ||
<ArticleDetails id={id} /> | ||
</Card> | ||
) | ||
}) |
35 changes: 35 additions & 0 deletions
35
src/widgets/ArticleAdditionalInfo/ArticleAdditionalInfo.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,35 @@ | ||
import React, { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { User } from '@/entities/User' | ||
import { HStack, VStack } from '@/shared/ui/redesigned/Stack' | ||
import { Avatar } from '@/shared/ui/redesigned/Avatar' | ||
import { Text } from '@/shared/ui/redesigned/Text' | ||
import { ArticleEditButton } from '@/features/ArticleEditButton' | ||
|
||
interface ArticleAdditionalInfoProps { | ||
className?: string | ||
author?: User | ||
createdAt?: string | ||
views?: number | ||
} | ||
|
||
export const ArticleAdditionalInfo: FC<ArticleAdditionalInfoProps> = React.memo((props) => { | ||
const { className, author, createdAt, views } = props | ||
const { t } = useTranslation('article-details') | ||
|
||
return ( | ||
<VStack gap="24"> | ||
<HStack gap="8"> | ||
<Avatar src={author?.avatar} size={32} /> | ||
<Text text={author?.username} bold /> | ||
</HStack> | ||
<ArticleEditButton /> | ||
<VStack gap="8"> | ||
<Text text={t('{{count}} просмотров', { count: views })} /> | ||
|
||
<Text text={createdAt} /> | ||
</VStack> | ||
</VStack> | ||
) | ||
}) |
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 { ArticleAdditionalInfo } from './ArticleAdditionalInfo' |