This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DirectMessages Banner and Update All Banners (#3851)
- Loading branch information
1 parent
e523d39
commit f9e1380
Showing
32 changed files
with
427 additions
and
390 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/web/src/components/banner/AppBannerWrapper.module.css
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,15 @@ | ||
.root { | ||
flex-shrink: 0; | ||
} | ||
|
||
.root > div:first-child { | ||
position: static; | ||
} | ||
|
||
.isMobile { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
z-index: 15; | ||
} |
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,19 @@ | ||
import cn from 'classnames' | ||
|
||
import { isMobile } from 'utils/clientUtil' | ||
|
||
import styles from './AppBannerWrapper.module.css' | ||
|
||
/** | ||
* Contains all the banners. Useful for mobile web to allow this to switch to fixed positioning, | ||
* but also would like to see this control the banner list instead of App.js if it's possible to decouple some of the logic | ||
*/ | ||
export const AppBannerWrapper = ({ | ||
children | ||
}: { | ||
children: React.ReactNode | ||
}) => ( | ||
<div className={cn(styles.root, { [styles.isMobile]: isMobile() })}> | ||
{children} | ||
</div> | ||
) |
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 was deleted.
Oops, something went wrong.
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,76 @@ | ||
import { ReactNode } from 'react' | ||
|
||
import { Client } from '@audius/common' | ||
import { IconArrowWhite } from '@audius/stems' | ||
import cn from 'classnames' | ||
|
||
import { Banner, BannerProps } from 'components/banner/Banner' | ||
import Pill from 'components/pill/Pill' | ||
import { getClient } from 'utils/clientUtil' | ||
|
||
import styles from './CallToActionBanner.module.css' | ||
|
||
export type CallToActionBannerProps = Pick< | ||
BannerProps, | ||
'onClose' | 'className' | ||
> & { | ||
onAccept: () => void | ||
emoji?: string | ||
pill?: string | ||
pillPosition?: 'left' | 'right' | ||
text: ReactNode | ||
} | ||
|
||
export const CallToActionBanner = (props: CallToActionBannerProps) => { | ||
const { | ||
emoji, | ||
pill, | ||
pillPosition = 'left', | ||
text, | ||
onAccept, | ||
...bannerProps | ||
} = props | ||
|
||
const client = getClient() | ||
|
||
return ( | ||
<Banner | ||
isElectron={client === Client.ELECTRON} | ||
isMobile={client === Client.MOBILE} | ||
{...bannerProps} | ||
> | ||
<div | ||
className={cn(styles.ctaBanner, { | ||
[styles.isMobile]: client === Client.MOBILE | ||
})} | ||
onClick={onAccept} | ||
> | ||
<div className={styles.content}> | ||
{pill && pillPosition === 'left' ? ( | ||
<Pill | ||
className={styles.pill} | ||
textClassName={styles.pillText} | ||
showIcon={false} | ||
clickable={false} | ||
text={pill} | ||
/> | ||
) : null} | ||
<div className={styles.contentSelection}> | ||
{emoji ? <i className={cn('emoji', emoji)} /> : null} | ||
<div className={styles.text}>{text}</div> | ||
<IconArrowWhite className={styles.arrow} /> | ||
</div> | ||
{pill && pillPosition === 'right' ? ( | ||
<Pill | ||
className={styles.pill} | ||
textClassName={styles.pillText} | ||
showIcon={false} | ||
clickable={false} | ||
text={pill} | ||
/> | ||
) : null} | ||
</div> | ||
</div> | ||
</Banner> | ||
) | ||
} |
59 changes: 59 additions & 0 deletions
59
packages/web/src/components/banner/DirectMessagesBanner.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,59 @@ | ||
import { useCallback, useState } from 'react' | ||
|
||
import { Client, accountSelectors } from '@audius/common' | ||
import { push as pushRoute } from 'connected-react-router' | ||
import { useDispatch } from 'react-redux' | ||
|
||
import { useSelector } from 'common/hooks/useSelector' | ||
import { getClient } from 'utils/clientUtil' | ||
import { CHATS_PAGE } from 'utils/route' | ||
|
||
import { CallToActionBanner } from './CallToActionBanner' | ||
|
||
const messages = { | ||
text: 'Direct Messaging Now Available!', | ||
pill: 'New' | ||
} | ||
|
||
const { getHasAccount } = accountSelectors | ||
|
||
const DIRECT_MESSAGES_BANNER_LOCAL_STORAGE_KEY = 'dismissDirectMessagesBanner' | ||
|
||
/** | ||
* Displays a CTA Banner announcing the launch of Direct Messaging | ||
* for logged in users on desktop web and desktop app (since logged out users can't use Direct Messages) | ||
*/ | ||
export const DirectMessagesBanner = () => { | ||
const dispatch = useDispatch() | ||
const signedIn = useSelector(getHasAccount) | ||
const isMobile = getClient() === Client.MOBILE | ||
const hasDismissed = window.localStorage.getItem( | ||
DIRECT_MESSAGES_BANNER_LOCAL_STORAGE_KEY | ||
) | ||
const [isVisible, setIsVisible] = useState( | ||
!hasDismissed && !isMobile && signedIn | ||
) | ||
|
||
const handleClose = useCallback(() => { | ||
setIsVisible(false) | ||
window.localStorage.setItem( | ||
DIRECT_MESSAGES_BANNER_LOCAL_STORAGE_KEY, | ||
'true' | ||
) | ||
}, []) | ||
|
||
const handleAccept = useCallback(() => { | ||
dispatch(pushRoute(CHATS_PAGE)) | ||
handleClose() | ||
}, [dispatch, handleClose]) | ||
|
||
return isVisible ? ( | ||
<CallToActionBanner | ||
text={messages.text} | ||
pill={messages.pill} | ||
emoji={'speech-balloon'} | ||
onClose={handleClose} | ||
onAccept={handleAccept} | ||
/> | ||
) : null | ||
} |
Oops, something went wrong.