-
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 greeting message in json settings
- Loading branch information
Showing
6 changed files
with
54 additions
and
3 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ArticlePageGreeting } from './ui/ArticlePageGreeting/ArticlePageGreeting'; |
45 changes: 45 additions & 0 deletions
45
src/features/articlePageGreeting/ui/ArticlePageGreeting/ArticlePageGreeting.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,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> | ||
); | ||
}); |
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