-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from dappforce/deploy/grill-integration
Grill Comment Integration
- Loading branch information
Showing
38 changed files
with
819 additions
and
202 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
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ const varsToExport = [ | |
'MAINTENANCE_TEXT', | ||
|
||
'GA_ID', | ||
'AMP_ID', | ||
|
||
'HCAPTCHA_SITE_KEY', | ||
|
||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,112 @@ | ||
@import 'src/styles/subsocial-vars.scss' | ||
|
||
.ChatFloatingWrapper | ||
z-index: 10 | ||
position: fixed | ||
bottom: $space_normal | ||
right: $space_normal | ||
|
||
.ChatUnreadCount | ||
position: absolute | ||
padding: 2px $space_tiny | ||
top: 0 | ||
right: 0 | ||
font-size: $font_tiny | ||
background: red | ||
border-radius: 32px | ||
transform: translate(25%, -25%) | ||
color: white | ||
|
||
.ChatFloatingButton | ||
padding: $space_small $space_normal | ||
// To offset optical illusion from the grill icon | ||
padding-left: $space_small | ||
border-radius: 32px | ||
font-size: 1rem | ||
color: white !important | ||
display: flex | ||
justify-content: center | ||
height: auto | ||
align-items: center | ||
background: linear-gradient(95.39deg, #C43333 9.79%, #F9A11E 135.53%) !important | ||
gap: $space_tiny | ||
border: none | ||
|
||
&:hover, &:focus | ||
filter: brightness(1.1) | ||
|
||
img | ||
display: block | ||
height: 1.1rem | ||
|
||
.ChatContainer | ||
z-index: 1010 | ||
position: fixed | ||
bottom: 0 | ||
left: 0 | ||
width: 100% | ||
height: 100vh | ||
display: flex | ||
flex-direction: column | ||
justify-content: flex-end | ||
|
||
.ChatOverlay | ||
position: absolute | ||
inset: 0 | ||
width: 100% | ||
height: 100% | ||
background-color: rgba(0, 0, 0, .2) | ||
transition: opacity 0.2s ease-out | ||
opacity: 1 | ||
|
||
.ChatContent | ||
height: 90vh | ||
height: 90dvh | ||
width: 100% | ||
background: #F8FAFC | ||
border-radius: $border_radius_huge | ||
opacity: 1 | ||
transform: translateY(0) | ||
transition: transform 0.3s ease-in-out, opacity 0.2s ease-in-out | ||
display: flex | ||
flex-direction: column | ||
|
||
.ChatControl | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
padding-top: $space-tiny | ||
|
||
button | ||
border-radius: 50% | ||
background: #F0F1F9 | ||
border: none | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
width: 2rem | ||
height: 2rem | ||
padding: 0 | ||
font-size: 1rem | ||
|
||
.ChatIframe | ||
flex: 1 | ||
|
||
iframe | ||
display: block | ||
border-radius: $border_radius_large | ||
width: 100% | ||
height: 100% | ||
border: none | ||
|
||
&.ChatContainerHidden | ||
pointer-events: none | ||
|
||
.ChatOverlay | ||
opacity: 0 | ||
|
||
.ChatContent | ||
transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out | ||
opacity: 0 | ||
transform: translateY(100%) | ||
|
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,101 @@ | ||
import { Button } from 'antd' | ||
import clsx from 'clsx' | ||
import { useEffect, useRef, useState } from 'react' | ||
import { createPortal } from 'react-dom' | ||
import { HiChevronDown } from 'react-icons/hi2' | ||
import { useSendEvent } from 'src/providers/AnalyticContext' | ||
import { useChatOpenState } from 'src/rtk/app/hooks' | ||
import { useAppSelector } from 'src/rtk/app/store' | ||
import { ChatEntity } from 'src/rtk/features/chat/chatSlice' | ||
import { disablePageScroll, enablePageScroll } from 'src/utils/window' | ||
import { useResponsiveSize } from '../responsive' | ||
import styles from './ChatFloatingModal.module.sass' | ||
import ChatIframe from './ChatIframe' | ||
|
||
export default function ChatFloatingModal() { | ||
const { isLargeDesktop } = useResponsiveSize() | ||
const sendEvent = useSendEvent() | ||
const [isOpen, setIsOpen] = useChatOpenState() | ||
const entity = useAppSelector(state => state.chat.entity) | ||
|
||
const [unreadCount, setUnreadCount] = useState(0) | ||
|
||
useEffect(() => { | ||
if (!entity) return | ||
|
||
const unreadCountFromStorage = getUnreadCount(entity) | ||
if (unreadCountFromStorage && !isNaN(unreadCountFromStorage)) { | ||
setUnreadCount(unreadCountFromStorage) | ||
} | ||
}, [entity]) | ||
|
||
const hasOpened = useRef(false) | ||
const toggleChat = () => { | ||
let event | ||
if (isOpen) { | ||
event = 'close_grill_iframe' | ||
} else { | ||
event = 'open_grill_iframe' | ||
setUnreadCount(0) | ||
if (entity) saveUnreadCount(entity, 0) | ||
} | ||
sendEvent(event) | ||
|
||
if (!isOpen) disablePageScroll() | ||
else enablePageScroll() | ||
|
||
setIsOpen(!isOpen) | ||
hasOpened.current = true | ||
} | ||
|
||
if (isLargeDesktop) { | ||
return null | ||
} | ||
|
||
const onUnreadCountChange = (count: number) => { | ||
if (count > 0 && entity) { | ||
setUnreadCount(count) | ||
saveUnreadCount(entity, count) | ||
} | ||
} | ||
|
||
if (!entity) return null | ||
|
||
return ( | ||
<> | ||
{createPortal( | ||
<div className={clsx(styles.ChatContainer, !isOpen && styles.ChatContainerHidden)}> | ||
<div className={clsx(styles.ChatOverlay)} onClick={() => setIsOpen(false)} /> | ||
<div className={clsx(styles.ChatContent)}> | ||
<div className={clsx(styles.ChatControl)}> | ||
<Button onClick={toggleChat}> | ||
<HiChevronDown /> | ||
</Button> | ||
</div> | ||
<ChatIframe onUnreadCountChange={onUnreadCountChange} className={styles.ChatIframe} /> | ||
</div> | ||
</div>, | ||
document.body, | ||
)} | ||
{createPortal( | ||
<div className={styles.ChatFloatingWrapper}> | ||
<Button className={styles.ChatFloatingButton} onClick={toggleChat}> | ||
<img src='/images/grillchat.svg' alt='GrillChat' /> | ||
<span>Comments</span> | ||
</Button> | ||
{!!unreadCount && <span className={styles.ChatUnreadCount}>{unreadCount}</span>} | ||
</div>, | ||
document.body, | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
type Entity = NonNullable<ChatEntity['entity']> | ||
function getUnreadCount(entity: Entity) { | ||
return parseInt(localStorage.getItem(`unreadCount:${entity.type}:${entity.data.id}`) ?? '') ?? 0 | ||
} | ||
|
||
function saveUnreadCount(entity: Entity, count: number) { | ||
localStorage.setItem(`unreadCount:${entity.type}:${entity.data.id}`, count.toString() ?? '0') | ||
} |
Oops, something went wrong.