-
Notifications
You must be signed in to change notification settings - Fork 25
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 #481 from thematters/feature/block-user
Block User
- Loading branch information
Showing
43 changed files
with
804 additions
and
135 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,110 @@ | ||
import { Icon, TextIcon, Translate } from '~/components' | ||
import { useMutation } from '~/components/GQL' | ||
import { BlockUser } from '~/components/GQL/fragments/__generated__/BlockUser' | ||
import userFragments from '~/components/GQL/fragments/user' | ||
import { UnblockUser } from '~/components/GQL/mutations/__generated__/UnblockUser' | ||
import UNBLOCK_USER from '~/components/GQL/mutations/unblockUser' | ||
import BlocKUserModal from '~/components/Modal/BlockUserModal' | ||
import { ModalInstance, ModalSwitch } from '~/components/ModalManager' | ||
|
||
import { TEXT } from '~/common/enums' | ||
import ICON_BLOCK from '~/static/icons/block.svg?sprite' | ||
import ICON_UNBLOCK from '~/static/icons/unblock.svg?sprite' | ||
|
||
import styles from './styles.css' | ||
|
||
const fragments = { | ||
user: userFragments.block | ||
} | ||
|
||
const TextIconBlock = () => ( | ||
<TextIcon | ||
icon={<Icon id={ICON_BLOCK.id} viewBox={ICON_BLOCK.viewBox} size="small" />} | ||
spacing="tight" | ||
> | ||
<Translate zh_hant={TEXT.zh_hant.blockUser} zh_hans={TEXT.zh_hans.block} /> | ||
</TextIcon> | ||
) | ||
|
||
const TextIconUnblock = () => ( | ||
<TextIcon | ||
icon={ | ||
<Icon id={ICON_UNBLOCK.id} viewBox={ICON_UNBLOCK.viewBox} size="small" /> | ||
} | ||
spacing="tight" | ||
> | ||
<Translate | ||
zh_hant={TEXT.zh_hant.unblockUser} | ||
zh_hans={TEXT.zh_hans.unblockUser} | ||
/> | ||
</TextIcon> | ||
) | ||
|
||
const BlockUserButton = ({ | ||
user, | ||
isShown, | ||
hideDropdown | ||
}: { | ||
user: BlockUser | ||
isShown: boolean | ||
hideDropdown: () => void | ||
}) => { | ||
const [unblockUser] = useMutation<UnblockUser>(UNBLOCK_USER, { | ||
variables: { id: user.id }, | ||
optimisticResponse: { | ||
unblockUser: { | ||
id: user.id, | ||
isBlocked: false, | ||
__typename: 'User' | ||
} | ||
} | ||
}) | ||
|
||
return ( | ||
<> | ||
{user.isBlocked && ( | ||
<button | ||
type="button" | ||
onClick={() => { | ||
unblockUser() | ||
hideDropdown() | ||
}} | ||
> | ||
<TextIconUnblock /> | ||
|
||
<style jsx>{styles}</style> | ||
</button> | ||
)} | ||
|
||
{!user.isBlocked && ( | ||
<ModalSwitch modalId="blockUserModal"> | ||
{(open: any) => ( | ||
<button | ||
type="button" | ||
onClick={() => { | ||
open() | ||
hideDropdown() | ||
}} | ||
> | ||
<TextIconBlock /> | ||
|
||
<style jsx>{styles}</style> | ||
</button> | ||
)} | ||
</ModalSwitch> | ||
)} | ||
|
||
{isShown && ( | ||
<ModalInstance modalId="blockUserModal" title="blockUser"> | ||
{(props: ModalInstanceProps) => ( | ||
<BlocKUserModal {...props} user={user} /> | ||
)} | ||
</ModalInstance> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
BlockUserButton.fragments = fragments | ||
|
||
export default BlockUserButton |
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,3 @@ | ||
button { | ||
font-size: var(--font-size-sm); | ||
} |
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,62 @@ | ||
import gql from 'graphql-tag' | ||
|
||
import { Button, Translate } from '~/components' | ||
import { useMutation } from '~/components/GQL' | ||
import { UnblockUser } from '~/components/GQL/mutations/__generated__/UnblockUser' | ||
import UNBLOCK_USER from '~/components/GQL/mutations/unblockUser' | ||
|
||
import { ANALYTICS_EVENTS, TEXT } from '~/common/enums' | ||
import { analytics } from '~/common/utils' | ||
|
||
import { UnblockButtonUser } from './__generated__/UnblockButtonUser' | ||
|
||
const fragments = { | ||
user: gql` | ||
fragment UnblockButtonUser on User { | ||
id | ||
isBlocked | ||
} | ||
` | ||
} | ||
|
||
const Unblock = ({ | ||
user, | ||
size = 'small' | ||
}: { | ||
user: UnblockButtonUser | ||
size?: 'small' | 'default' | ||
}) => { | ||
const [unblockUser] = useMutation<UnblockUser>(UNBLOCK_USER, { | ||
variables: { id: user.id }, | ||
optimisticResponse: { | ||
unblockUser: { | ||
id: user.id, | ||
isBlocked: false, | ||
__typename: 'User' | ||
} | ||
} | ||
}) | ||
|
||
return ( | ||
<Button | ||
size={size} | ||
style={size === 'small' ? { width: '4rem' } : { width: '5.5rem' }} | ||
onClick={() => { | ||
unblockUser() | ||
analytics.trackEvent(ANALYTICS_EVENTS.UNFOLLOW_USER, { | ||
id: user.id | ||
}) | ||
}} | ||
bgColor="green" | ||
> | ||
<Translate | ||
zh_hant={TEXT.zh_hant.unblockUser} | ||
zh_hans={TEXT.zh_hans.unblockUser} | ||
/> | ||
</Button> | ||
) | ||
} | ||
|
||
Unblock.fragments = fragments | ||
|
||
export default Unblock |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.