-
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 widget with additional article information
- Loading branch information
Showing
26 changed files
with
243 additions
and
25 deletions.
There are no files selected for viewing
Binary file added
BIN
+16.1 KB
.loki/reference/chrome_iphone7_shared_AdditionalInfoContainer_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.1 KB
.loki/reference/chrome_iphone7_shared_ArticalAdditionalInfo_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10 KB
.loki/reference/chrome_laptop_shared_AdditionalInfoContainer_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.5 KB
.loki/reference/chrome_laptop_shared_ArticalAdditionalInfo_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 @@ | ||
.card { | ||
width: 264px; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/pages/ArticleDetailsPage/ui/AdditionalInfoContainer/AdditionalInfoContainer.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,16 @@ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { AdditionalInfoContainer } from './AdditionalInfoContainer'; | ||
|
||
export default { | ||
title: 'shared/AdditionalInfoContainer', | ||
component: AdditionalInfoContainer, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof AdditionalInfoContainer>; | ||
|
||
const Template: ComponentStory<typeof AdditionalInfoContainer> = (args) => <AdditionalInfoContainer {...args} />; | ||
|
||
export const Normal = Template.bind({}); | ||
Normal.args = {}; |
54 changes: 54 additions & 0 deletions
54
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,54 @@ | ||
import { memo, useCallback } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { ArticalAdditionalInfo } from '@/widgets/ArticalAdditionalInfo'; | ||
import { Card } from '@/shared/ui/redesigned/Card'; | ||
import { getArticleDetails } from '@/entities/Article'; | ||
import { classNames } from '@/shared/lib/classNames'; | ||
import { getRouteArticleEdit } from '@/shared/const/router'; | ||
import { Skeleton } from '@/shared/ui/redesigned/Skeleton'; | ||
import { VStack } from '@/shared/ui/redesigned/Stack'; | ||
|
||
import cls from './AdditionalInfoContainer.module.scss'; | ||
|
||
interface AdditionalInfoContainerProps { | ||
className?: string; | ||
} | ||
|
||
export const AdditionalInfoContainer = memo((props: AdditionalInfoContainerProps) => { | ||
const { className } = props; | ||
const article = useSelector(getArticleDetails); | ||
const navigate = useNavigate(); | ||
|
||
const onEditArticle = useCallback(() => { | ||
if (article?.id) { | ||
navigate(getRouteArticleEdit(article.id)); | ||
} | ||
}, [navigate, article]); | ||
|
||
if (!article) { | ||
return ( | ||
<Card padding="24" borderRadius="round" className={classNames(cls.card, {}, [className])}> | ||
<VStack gap="32"> | ||
<Skeleton width={200} height={24} /> | ||
<Skeleton width={200} height={38} /> | ||
<Skeleton width={200} height={24} /> | ||
</VStack> | ||
</Card> | ||
); | ||
} | ||
|
||
return ( | ||
<Card padding="24" borderRadius="round" className={classNames(cls.card, {}, [className])}> | ||
<ArticalAdditionalInfo | ||
onEdit={onEditArticle} | ||
author={article.user} | ||
createdAt={article.createdAt} | ||
views={article.views} | ||
/> | ||
</Card> | ||
); | ||
}); | ||
|
||
AdditionalInfoContainer.displayName = 'AdditionalInfoContainer'; |
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
16 changes: 16 additions & 0 deletions
16
src/pages/ArticleDetailsPage/ui/DetailsContainer/DetailsContainer.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,16 @@ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { DetailsContainer } from './DetailsContainer'; | ||
|
||
export default { | ||
title: 'shared/DetailsContainer', | ||
component: DetailsContainer, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof DetailsContainer>; | ||
|
||
const Template: ComponentStory<typeof DetailsContainer> = (args) => <DetailsContainer {...args} />; | ||
|
||
export const Normal = Template.bind({}); | ||
Normal.args = {}; |
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
import { memo } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { ArticleDetails } from '@/entities/Article'; | ||
import { Card } from '@/shared/ui/redesigned/Card'; | ||
|
||
interface DetailsContainerProps { | ||
className?: string; | ||
} | ||
|
||
export const DetailsContainer = memo((props: DetailsContainerProps) => { | ||
const { className } = props; | ||
const { id } = useParams<{ id: string }>(); | ||
|
||
return ( | ||
<Card fullwidth className={className} padding="24" borderRadius="round"> | ||
<ArticleDetails id={id!} /> | ||
</Card> | ||
); | ||
}); | ||
|
||
DetailsContainer.displayName = 'DetailsContainer'; |
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 |
---|---|---|
|
@@ -19,6 +19,10 @@ | |
width: 100%; | ||
} | ||
|
||
.fullheight { | ||
height: 100%; | ||
} | ||
|
||
.gap_0 { | ||
padding: 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
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 { ArticalAdditionalInfo } from './ui/ArticalAdditionalInfo'; |
24 changes: 24 additions & 0 deletions
24
src/widgets/ArticalAdditionalInfo/ui/ArticalAdditionalInfo.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,24 @@ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { article } from '@/entities/Article/testing'; | ||
|
||
import { ArticalAdditionalInfo } from './ArticalAdditionalInfo'; | ||
|
||
export default { | ||
title: 'shared/ArticalAdditionalInfo', | ||
component: ArticalAdditionalInfo, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof ArticalAdditionalInfo>; | ||
|
||
const Template: ComponentStory<typeof ArticalAdditionalInfo> = (args) => ( | ||
<ArticalAdditionalInfo {...args} /> | ||
); | ||
|
||
export const Normal = Template.bind({}); | ||
Normal.args = { | ||
author: article.user, | ||
views: article.views, | ||
createdAt: article.createdAt, | ||
}; |
46 changes: 46 additions & 0 deletions
46
src/widgets/ArticalAdditionalInfo/ui/ArticalAdditionalInfo.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,46 @@ | ||
import { memo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { classNames } from '@/shared/lib/classNames'; | ||
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 { Button } from '@/shared/ui/redesigned/Button'; | ||
import { getCanEditArticle } from '@/pages/ArticleDetailsPage/model/selectors/article'; | ||
|
||
import cls from './ArticalAdditionalInfo.module.scss'; | ||
|
||
interface ArticalAdditionalInfoProps { | ||
className?: string; | ||
author: User; | ||
createdAt: string; | ||
views: number; | ||
onEdit: () => void; | ||
} | ||
|
||
export const ArticalAdditionalInfo = memo((props: ArticalAdditionalInfoProps) => { | ||
const { className, author, views, createdAt, onEdit } = props; | ||
const canEditArticle = useSelector(getCanEditArticle); | ||
|
||
const { t } = useTranslation('articles'); | ||
|
||
return ( | ||
<VStack gap="32" className={classNames(cls.articalAdditionalInfo, {}, [className])}> | ||
<HStack gap="8"> | ||
<Avatar src={author.avatar} size={32} /> | ||
|
||
<Text text={author.username} bold /> | ||
|
||
<Text text={createdAt} /> | ||
</HStack> | ||
|
||
{canEditArticle && <Button onClick={onEdit}>{t('Редактировать')}</Button>} | ||
|
||
<Text text={t('Просмотров', { count: views })} /> | ||
</VStack> | ||
); | ||
}); | ||
|
||
ArticalAdditionalInfo.displayName = 'ArticalAdditionalInfo'; |
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 +1 @@ | ||
export { ArticlesFilters } from './ArticlesFilters'; | ||
export { ArticlesFilters } from './ui/ArticlesFilters'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.