Skip to content

Commit

Permalink
feat: add greetings for articles page
Browse files Browse the repository at this point in the history
  • Loading branch information
sashtje committed Oct 8, 2023
1 parent 37652f1 commit 1ef97f7
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Feature state can take only one of two values: **on** or **off**.
## Features

- [addCommentForm](/src/features/addCommentForm)
- [articlePageGreeting](/src/features/articlePageGreeting)
- [articleRating](/src/features/articleRating)
- [articleRecommendationsList](/src/features/articleRecommendationsList)
- [articleSortSelector](/src/features/articleSortSelector)
Expand Down
3 changes: 2 additions & 1 deletion json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,8 @@
"jsonSettings": {
"theme": "app_orange_theme",
"isFirstVisit": true,
"settingsPageHasBeenOpen": false
"settingsPageHasBeenOpen": false,
"isArticlesPageWasOpened": true
},
"avatar": "https://s10.stc.yc.kpcdn.net/share/i/12/12010775/wr-960.webp"
},
Expand Down
4 changes: 3 additions & 1 deletion public/locales/en/articles.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
"Ошибка при загрузке статей": "Error while loading articles",
"Оцените статью": "Rate this article",
"Оставьте свой отзыв о статье": "Leave your feedback on the article",
"Оценка статей скоро появится!": "Article ratings coming soon!"
"Оценка статей скоро появится!": "Article ratings coming soon!",
"Добро пожаловать на страницу статей": "Welcome to the articles page",
"Здесь Вы можете искать и просматривать статьи на различные темы": "Here you can search and view articles on various topics"
}
4 changes: 3 additions & 1 deletion public/locales/ru/articles.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
"Ошибка при загрузке статей": "Ошибка при загрузке статей",
"Оцените статью": "Оцените статью",
"Оставьте свой отзыв о статье": "Оставьте свой отзыв о статье",
"Оценка статей скоро появится!": "Оценка статей скоро появится!"
"Оценка статей скоро появится!": "Оценка статей скоро появится!",
"Добро пожаловать на страницу статей": "Добро пожаловать на страницу статей",
"Здесь Вы можете искать и просматривать статьи на различные темы": "Здесь Вы можете искать и просматривать статьи на различные темы"
}
2 changes: 1 addition & 1 deletion src/entities/User/model/types/jsonSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { Theme } from '@/shared/const/theme';
export interface JsonSettings {
theme?: Theme;
isFirstVisit?: boolean;
settingsPageHasBeenOpen?: boolean;
isArticlesPageWasOpened?: boolean;
}
1 change: 1 addition & 0 deletions src/features/articlePageGreeting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Article page greeting
1 change: 1 addition & 0 deletions src/features/articlePageGreeting/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ArticlePageGreeting } from './ui/ArticlePageGreeting/ArticlePageGreeting';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ComponentMeta, ComponentStory } from '@storybook/react';

import { ArticlePageGreeting } from './ArticlePageGreeting';

export default {
title: 'features/ArticlePageGreeting',
component: ArticlePageGreeting,
argTypes: {
backgroundColor: { control: 'color' },
},
} as ComponentMeta<typeof ArticlePageGreeting>;

const Template: ComponentStory<typeof ArticlePageGreeting> = (args) => (
<ArticlePageGreeting {...args} />
);

export const Normal = Template.bind({});
Normal.args = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { memo, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { isMobile } from 'react-device-detect';

import { Modal } from '@/shared/ui/Modal';
import { Text } from '@/shared/ui/Text';
import { saveJsonSettings, useJsonSettings } from '@/entities/User';
import { useAppDispatch } from '@/shared/lib/hooks/useAppDispatch/useAppDispatch';
import { Drawer } from '@/shared/ui/Drawer';

export const ArticlePageGreeting = memo(() => {
const { t } = useTranslation('articles');

const [isOpen, setIsOpen] = useState(false);
const { isArticlesPageWasOpened } = useJsonSettings();
const dispatch = useAppDispatch();

useEffect(() => {
if (!isArticlesPageWasOpened) {
setIsOpen(true);
dispatch(saveJsonSettings({ isArticlesPageWasOpened: true }));
}
}, [dispatch, isArticlesPageWasOpened]);

const onClose = () => setIsOpen(false);

const text = (
<Text
title={t('Добро пожаловать на страницу статей')}
text={t('Здесь Вы можете искать и просматривать статьи на различные темы')}
/>
);

if (isMobile) {
return <Drawer>{text}</Drawer>;
}

return (
<Modal lazy isOpen={isOpen} onClose={onClose}>
{text}
</Modal>
);
});

ArticlePageGreeting.displayName = 'ArticlePageGreeting';
3 changes: 3 additions & 0 deletions src/pages/ArticlesPage/ui/ArticlesPage/ArticlesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { useAppDispatch } from '@/shared/lib/hooks/useAppDispatch/useAppDispatch';
import { Page } from '@/widgets/Page';
import { useInitialEffect } from '@/shared/lib/hooks/useInitialEffect/useInitialEffect';
import { ArticlePageGreeting } from '@/features/articlePageGreeting';

import { initArticlesPage } from '../../model/services/initArticlesPage/initArticlesPage';
import { ArticleInfiniteList } from '../ArticleInfiniteList/ArticleInfiniteList';
Expand Down Expand Up @@ -48,6 +49,8 @@ export const ArticlesPage = memo((props: ArticlesPageProps) => {
<ArticlesPageFilters />

<ArticleInfiniteList />

<ArticlePageGreeting />
</Page>
</DynamicModuleLoader>
);
Expand Down

0 comments on commit 1ef97f7

Please sign in to comment.