Skip to content

Commit

Permalink
feat: add greeting message in json settings
Browse files Browse the repository at this point in the history
  • Loading branch information
TomatoVan committed Apr 9, 2024
1 parent f55772d commit 4441bbd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
2 changes: 2 additions & 0 deletions extractedTranslations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"Error with getting article data": "",
"Error with getting profile data": "",
"Exit": "",
"Here you can search and view articles on various topics": "",
"IT": "",
"Incorrect age": "",
"Incorrect country": "",
Expand All @@ -48,6 +49,7 @@
"Sorting by": "",
"Thanks for review!": "",
"Try to reload page": "",
"Welcome to the articles page!": "",
"You don`t have access to this page!": "",
"Your name": "",
"article_not_found": "",
Expand Down
3 changes: 2 additions & 1 deletion json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,8 @@
"jsonSettings": {
"theme": "app_light_theme",
"isFirstVisit": true,
"settingsPageHasBeenOpen": false
"settingsPageHasBeenOpen": false,
"isArticlesPageWasOpened": true
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/entities/User/model/types/jsonSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Theme } from '@/shared/const/theme';

export interface JsonSettings {
theme?: Theme;
isFirstVisit?: true;
settingsPageHasBeenOpen?: false;
isFirstVisit?: boolean;
isArticlesPageWasOpened?: boolean;
}
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,45 @@
import { useTranslation } from 'react-i18next';
import { memo, useEffect, useState } from 'react';
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 { Drawer } from '@/shared/ui/Drawer';
import { useAppDispatch } from '@/shared/lib/hook/useAppDispatch/useAppDispatch';

export const ArticlePageGreeting = memo(() => {
const { t } = useTranslation();
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('Welcome to the articles page!')}
text={t('Here you can search and view articles on various topics')}
/>
);

if (isMobile) {
return (
<Drawer lazy isOpen={isOpen} onClose={onClose}>
{text}
</Drawer>
);
}

return (
<Modal lazy isOpen={isOpen} onClose={onClose}>
{text}
</Modal>
);
});
2 changes: 2 additions & 0 deletions src/pages/ArticlesPage/ui/ArticlesPage/ArticlesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { fetchNextArticlePage } from '../../model/services/fetchNextArticlePage/
import { initArticlesPage } from '../../model/services/initArticlesPage/initArticlesPage';
import { articlesPageReducer } from '../../model/slices/articlesPageSlice';
import { Page } from '@/widgets/Page';
import { ArticlePageGreeting } from '@/features/articlePageGreeting';

interface ArticlesPageProps {
className?: string;
Expand Down Expand Up @@ -44,6 +45,7 @@ const ArticlesPage = ({ className }: ArticlesPageProps) => {
>
<ArticlesPageFilters />
<ArticleInfiniteList />
<ArticlePageGreeting />
</Page>
</DynamicModuleLoader>
);
Expand Down

0 comments on commit 4441bbd

Please sign in to comment.