-
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.
- Loading branch information
1 parent
cdbc800
commit c976850
Showing
10 changed files
with
209 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { isEmptyArray } from '@subsocial/utils' | ||
import { useSelectPost, useSelectSpace } from 'src/rtk/app/hooks' | ||
import CreateChatModalButton from './CreateChatModal' | ||
import UnhideChatButton from './UnhideChatButton' | ||
|
||
type ChatButtonProps = { | ||
spaceId?: string | ||
} | ||
|
||
const ChatButton = ({ spaceId }: ChatButtonProps) => { | ||
const space = useSelectSpace(spaceId) | ||
|
||
const spaceContent = space?.content | ||
|
||
const chats = spaceContent?.chats | ||
const chat = chats?.[0] | ||
|
||
const post = useSelectPost(chat.id) | ||
|
||
const isPostHidden = !!post?.post.struct.hidden | ||
|
||
if (spaceContent && !isEmptyArray(chats) && !isPostHidden) return null | ||
|
||
return isPostHidden ? ( | ||
<UnhideChatButton post={post?.post?.struct} /> | ||
) : ( | ||
<CreateChatModalButton spaceId={spaceId} /> | ||
) | ||
} | ||
|
||
export default ChatButton |
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 |
---|---|---|
@@ -1,6 +1,41 @@ | ||
@import 'src/styles/subsocial-vars.scss' | ||
|
||
.ChatIframe | ||
transition: opacity 150ms ease-out | ||
opacity: 1 | ||
|
||
&.ChatIframeLoading | ||
opacity: 0 | ||
opacity: 0 | ||
|
||
.ButtonWrapper | ||
display: flex | ||
align-items: center | ||
gap: $space_tiny | ||
align-items: center | ||
margin: 0 19px 0 0 | ||
padding: 12px 0 | ||
|
||
.ChatButton | ||
height: auto | ||
position: relative | ||
display: inline-flex | ||
font-size: 14px | ||
background: transparent | ||
align-items: center | ||
padding: 0 | ||
border: 0 | ||
outline: none | ||
cursor: pointer | ||
|
||
.ChatUnreadCount | ||
font-size: 10px | ||
padding: 2px 3px | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
height: 14px | ||
min-width: 14px | ||
font-weight: 500 | ||
background: #EB2F95 | ||
border-radius: 32px | ||
color: white |
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,51 @@ | ||
import { PostData } from '@subsocial/api/types' | ||
import { Button } from 'antd' | ||
import clsx from 'clsx' | ||
import { useEffect, useState } from 'react' | ||
import { useSetChatEntityConfig, useSetChatOpen } from 'src/rtk/app/hooks' | ||
import { useAppSelector } from 'src/rtk/app/store' | ||
import { getUnreadCount } from './ChatFloatingModal' | ||
import styles from './ChatIframe.module.sass' | ||
|
||
type ChatLinkButtonWithCounterProps = { | ||
post: PostData | ||
} | ||
|
||
const ChatLinkButtonWithCounter = ({ post }: ChatLinkButtonWithCounterProps) => { | ||
const setChatConfig = useSetChatEntityConfig() | ||
const setChatOpen = useSetChatOpen() | ||
|
||
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]) | ||
|
||
return ( | ||
<span className={styles.ButtonWrapper}> | ||
<Button | ||
onClick={() => { | ||
setChatConfig({ | ||
entity: { type: 'post', data: post }, | ||
withFloatingButton: false, | ||
}) | ||
setChatOpen(true) | ||
}} | ||
type='link' | ||
className={styles.ChatButton} | ||
> | ||
Chat | ||
</Button> | ||
{!!unreadCount && <div className={clsx(styles.ChatUnreadCount)}>{unreadCount}</div>} | ||
</span> | ||
) | ||
} | ||
|
||
export default ChatLinkButtonWithCounter |
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,46 @@ | ||
import { PostUpdate } from '@subsocial/api/substrate/wrappers' | ||
import { PostStruct } from '@subsocial/api/types' | ||
import { useAppDispatch } from 'src/rtk/app/store' | ||
import { fetchPost } from 'src/rtk/features/posts/postsSlice' | ||
import { DataSourceTypes } from 'src/types' | ||
import { useSubsocialApi } from '../substrate' | ||
import HiddenButton from '../utils/HiddenButton' | ||
|
||
type UnhideChatButtonProps = { | ||
post?: PostStruct | ||
} | ||
|
||
const UnhideChatButton = ({ post }: UnhideChatButtonProps) => { | ||
const dispatch = useAppDispatch() | ||
const { subsocial } = useSubsocialApi() | ||
|
||
if (!post) return null | ||
|
||
const newTxParams = () => { | ||
const update = PostUpdate({ | ||
hidden: false, | ||
}) | ||
return [post.id, update] | ||
} | ||
|
||
const onTxSuccess = () => { | ||
dispatch( | ||
fetchPost({ api: subsocial, id: post.id, dataSource: DataSourceTypes.CHAIN, reload: true }), | ||
) | ||
} | ||
|
||
return ( | ||
<HiddenButton | ||
struct={post} | ||
newTxParams={newTxParams} | ||
buttonType='primary' | ||
size={'middle'} | ||
ghost | ||
onTxSuccess={onTxSuccess} | ||
type='post' | ||
label='Unhide chat' | ||
/> | ||
) | ||
} | ||
|
||
export default UnhideChatButton |
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
Oops, something went wrong.