Skip to content

Commit 9c49641

Browse files
committed
add greeting modal for articles
1 parent 8de2e57 commit 9c49641

File tree

8 files changed

+74
-3
lines changed

8 files changed

+74
-3
lines changed

json-server/db.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,8 @@
20122012
"jsonSettings": {
20132013
"theme": "app_magneta_theme",
20142014
"isFirstVisit": true,
2015-
"settingsPageHasBeenOpened": false
2015+
"settingsPageHasBeenOpened": false,
2016+
"isArtcilesPageWasOpened": true
20162017
}
20172018
},
20182019
{

public/locales/en/translation.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@
3434
" You don": "Forbidden. You don`t have access."
3535
},
3636
"Close": "Close",
37-
"add five": "add five"
37+
"add five": "add five",
38+
"Welcome to the articles page": "Welcome to the articles page",
39+
"Here you can search and view articles on various topics": "Here you can search and view articles on various topics"
3840
}

public/locales/ru/translation.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@
3131
"Forbidden": {
3232
" You don": "Запрещенный. \nУ вас нет доступа."
3333
},
34-
"Close": "Закрывать"
34+
"Close": "Закрывать",
35+
"Welcome to the articles page": "Добро пожаловать на страницу статей",
36+
"Here you can search and view articles on various topics": "Здесь вы можете искать и просматривать статьи на различные темы"
3537
}

src/entities/User/model/types/jsonSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface _JsonSettings {
44
theme: Theme;
55
isFirstVisist: boolean;
66
settingsPageHasBeenOpened: boolean;
7+
isArtcilesPageWasOpened?: boolean;
78
}
89

910
export type JsonSettings = Partial<_JsonSettings>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ArticlePageGreeting } from './ui/ArticlePageGreeting/ArticlePageGreeting';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ComponentStory, ComponentMeta } from '@storybook/react';
2+
import { ArticlePageGreeting } from './ArticlePageGreeting';
3+
4+
export default {
5+
title: 'entities/ArticlePageGreeting',
6+
component: ArticlePageGreeting,
7+
argTypes: {
8+
backgroundColor: { control: 'color' },
9+
},
10+
} as ComponentMeta<typeof ArticlePageGreeting>;
11+
12+
const Template: ComponentStory<typeof ArticlePageGreeting> = () => {
13+
return <ArticlePageGreeting />;
14+
};
15+
16+
export const Primary = Template.bind({});
17+
Primary.args = {};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { useEffect, useState } from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { isMobile } from 'react-device-detect';
4+
import { Modal } from '@/shared/ui/Modal';
5+
import { Text } from '@/shared/ui/Text';
6+
import { saveJsonSettings, useJsonSettings } from '@/entities/User';
7+
import { useAppDispatch } from '@/shared/lib/hooks/useAppDispatch/useAppDispatch';
8+
import { Drawer } from '@/shared/ui/Drawer';
9+
10+
export const ArticlePageGreeting = () => {
11+
const { t } = useTranslation();
12+
const [isOpen, setIsOpen] = useState(false);
13+
const { isArtcilesPageWasOpened } = useJsonSettings();
14+
const dispatch = useAppDispatch();
15+
16+
useEffect(() => {
17+
if (!isArtcilesPageWasOpened) {
18+
setIsOpen(true);
19+
dispatch(saveJsonSettings({ isArtcilesPageWasOpened: true }));
20+
}
21+
}, [dispatch, isArtcilesPageWasOpened]);
22+
23+
const handleOnClose = () => setIsOpen(false);
24+
25+
const text = (
26+
<Text
27+
title={t('Welcome to the articles page')}
28+
text={t('Here you can search and view articles on various topics')}
29+
/>
30+
);
31+
32+
if (isMobile) {
33+
return (
34+
<Drawer isOpen={isOpen} lazy onClose={handleOnClose}>
35+
{text}
36+
</Drawer>
37+
);
38+
}
39+
40+
return (
41+
<Modal isOpen={isOpen} lazy onClose={handleOnClose}>
42+
{text}
43+
</Modal>
44+
);
45+
};

src/pages/ArticlesPage/ui/ArticlesPage/ArticlesPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { fetchNextArticlesPage } from '../../model/services/fetchNextArticlesPag
1313
import { articlesPageReducer } from '../../model/slices/articlesPageSlice';
1414
import s from './ArticlesPage.module.scss';
1515
import { ArticlesPageFilters } from '../ArticlesPageFilters/ArticlesPageFilters';
16+
import { ArticlePageGreeting } from '@/features/articlePageGreeting';
1617

1718
const reducers: ReducersList = {
1819
articlesPage: articlesPageReducer,
@@ -35,6 +36,7 @@ export const ArticlesPage = memo(() => {
3536
<Page onScrollEnd={onLoadNextPart} className={s.ArticlesPage} data-testid="ArticlesPage">
3637
<ArticlesPageFilters />
3738
<ArtcileInfiniteList className={s.list} />
39+
<ArticlePageGreeting />
3840
</Page>
3941
</DynamicModuleLoader>
4042
);

0 commit comments

Comments
 (0)