Skip to content

Commit

Permalink
feat: add write something condition for user that dont have profile
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jan 17, 2024
1 parent c4e6bfc commit 21dd93e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/components/posts/WriteSomething.module.sass
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
.PostButton
background: $color_primary
color: white
opacity: 0.3
border: none
border-radius: 60px
padding: 0 $space_big
cursor: pointer

&:disabled
opacity: 0.3
cursor: default
47 changes: 38 additions & 9 deletions src/components/posts/WriteSomething.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import clsx from 'clsx'
import { ComponentProps, useState } from 'react'
import { useSendEvent } from 'src/providers/AnalyticContext'
import { useSelectProfile } from 'src/rtk/app/hooks'
import {
useSelectProfile,
useSelectSpaceIdsWhereAccountCanPostWithLoadingStatus,
} from 'src/rtk/app/hooks'
import { selectSpaceIdsThatCanSuggestIfSudo } from 'src/utils'
import { useMyAddress } from '../auth/MyAccountsContext'
import Avatar from '../profiles/address-views/Avatar'
import { newSpaceUrl } from '../urls'
import Segment from '../utils/Segment'
import { PostEditorModal } from './editor/ModalEditor'
import styles from './WriteSomething.module.sass'
Expand All @@ -18,21 +23,45 @@ export default function WriteSomething({ defaultSpaceId, ...props }: WriteSometh
const myAddress = useMyAddress() ?? ''
const profileData = useSelectProfile(myAddress)

const { isLoading, spaceIds: ids } =
useSelectSpaceIdsWhereAccountCanPostWithLoadingStatus(myAddress)
if (isLoading) {
return null
}

const spaceIds = selectSpaceIdsThatCanSuggestIfSudo({ myAddress, spaceIds: ids })
const anySpace = spaceIds[0]

const onClickInput = () => {
sendEvent('createpost_button_clicked', { eventSource: 'write-something' })
setVisible(true)
if (anySpace) {
sendEvent('createpost_button_clicked', { eventSource: 'write-something' })
setVisible(true)
return
}
}

const content = (
<>
<button className={styles.InputButton} onClick={onClickInput}>
{anySpace ? 'Write something...' : 'Create a profile to start posting'}
</button>
<button className={styles.PostButton} disabled={!!anySpace}>
{anySpace ? 'Post' : 'Create Profile'}
</button>
</>
)

return (
<>
<Segment {...props} className={clsx('d-flex', styles.WriteSomething, props.className)}>
<Avatar address={myAddress} avatar={profileData?.content?.image} size={40} />
<button className={styles.InputButton} onClick={onClickInput}>
Write something...
</button>
<button className={styles.PostButton} disabled>
Post
</button>
{anySpace ? (
content
) : (
<a href={newSpaceUrl(true)} className='d-flex w-100'>
{content}
</a>
)}
</Segment>
<PostEditorModal
defaultSpaceId={defaultSpaceId}
Expand Down

0 comments on commit 21dd93e

Please sign in to comment.