-
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 #383 from dappforce/deploy/global-moderation
App Moderator Integration
- Loading branch information
Showing
30 changed files
with
765 additions
and
85 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Alert } from 'antd' | ||
import CustomLink from '../referral/CustomLink' | ||
import { CONTENT_POLICY_LINK } from './utils' | ||
|
||
export default function BlockedAlert({ customPrefix = 'This account' }: { customPrefix?: string }) { | ||
return ( | ||
<Alert | ||
type='warning' | ||
message={ | ||
<span> | ||
{customPrefix} was blocked due to a violation of{' '} | ||
<CustomLink href={CONTENT_POLICY_LINK}>Grill's content policy.</CustomLink> | ||
</span> | ||
} | ||
/> | ||
) | ||
} |
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,32 @@ | ||
import { Button } from 'antd' | ||
import CustomLink from '../referral/CustomLink' | ||
import CustomModal from '../utils/CustomModal' | ||
import { APPEAL_LINK, CONTENT_POLICY_LINK } from './utils' | ||
|
||
export default function BlockedModal({ ...props }: { visible: boolean; onCancel: () => void }) { | ||
return ( | ||
<CustomModal | ||
{...props} | ||
title={ | ||
<span> | ||
Your account was blocked due to a violation of{' '} | ||
<CustomLink href={CONTENT_POLICY_LINK}>Grill's content policy.</CustomLink> | ||
</span> | ||
} | ||
subtitle='You are now restricted from taking actions on Grill, but can still manage your locked SUB, and use other applications running on the Subsocial network.' | ||
> | ||
<div className='GapNormal' style={{ display: 'grid', gridTemplateColumns: '1fr 1fr' }}> | ||
<CustomLink href='/c/staking'> | ||
<Button size='large' type='primary' className='w-100'> | ||
Manage SUB | ||
</Button> | ||
</CustomLink> | ||
<CustomLink href={APPEAL_LINK}> | ||
<Button size='large' className='w-100'> | ||
Appeal | ||
</Button> | ||
</CustomLink> | ||
</div> | ||
</CustomModal> | ||
) | ||
} |
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,37 @@ | ||
import clsx from 'clsx' | ||
import { CSSProperties } from 'react' | ||
import { useIsAdmin } from 'src/rtk/features/moderation/hooks' | ||
|
||
export default function SubTeamLabel({ | ||
address, | ||
className, | ||
style, | ||
}: { | ||
address: string | ||
className?: string | ||
style?: CSSProperties | ||
}) { | ||
const isAdmin = useIsAdmin(address) | ||
if (!isAdmin) return null | ||
|
||
return ( | ||
<div | ||
className={clsx('RoundedHuge', className)} | ||
style={{ padding: '0.125rem 0.5rem', background: '#F8FAFC', ...style }} | ||
> | ||
<span | ||
className='FontTiny' | ||
style={{ | ||
color: 'transparent', | ||
display: 'block', | ||
backgroundClip: 'text', | ||
WebkitBackgroundClip: 'text', | ||
backgroundImage: 'linear-gradient(94deg, #FB339E 3.57%, #DB35F8 102.73%)', | ||
WebkitTextFillColor: 'transparent', | ||
}} | ||
> | ||
SUB Team | ||
</span> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const CONTENT_POLICY_LINK = '/legal/content-policy' | ||
export const APPEAL_LINK = '/c/appeal' |
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,10 @@ | ||
import { useIsAdmin } from 'src/rtk/features/moderation/hooks' | ||
import { useModerationContext } from './ModerationProvider' | ||
|
||
export default function ModerateButton({ postId }: { postId: string }) { | ||
const isAdmin = useIsAdmin() | ||
const { openModal } = useModerationContext() | ||
if (!isAdmin) return null | ||
|
||
return <div onClick={() => openModal(postId)}>Moderate</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, { ReactNode, useEffect, useMemo, useRef, useState } from 'react' | ||
import { useIsAdmin } from 'src/rtk/features/moderation/hooks' | ||
import { parseGrillMessage } from 'src/utils/iframe' | ||
import { useMyAddress } from '../auth/MyAccountsContext' | ||
import GrillIframeModal from '../utils/GrillIframe' | ||
|
||
type State = { | ||
openModal: (postId: string) => void | ||
} | ||
|
||
const Context = React.createContext<State>({ openModal: () => undefined }) | ||
|
||
export default function ModerationProvider({ children }: { children: ReactNode }) { | ||
const [isOpenModal, setIsOpenModal] = useState(false) | ||
const iframeRef = useRef<HTMLIFrameElement | null>(null) | ||
const myAddress = useMyAddress() | ||
const isAdmin = useIsAdmin(myAddress) | ||
|
||
useEffect(() => { | ||
const listener = (event: MessageEvent<any>) => { | ||
const message = parseGrillMessage(event.data + '') | ||
if (!message) return | ||
|
||
const { name, value } = message | ||
if (name === 'moderation' && value === 'close') { | ||
setIsOpenModal(false) | ||
} | ||
} | ||
window.addEventListener('message', listener) | ||
return () => window.removeEventListener('message', listener) | ||
}, []) | ||
|
||
const value = useMemo(() => { | ||
return { | ||
openModal: (postId: string) => { | ||
iframeRef.current?.contentWindow?.postMessage( | ||
{ | ||
type: 'grill:moderate', | ||
payload: postId, | ||
}, | ||
'*', | ||
) | ||
setIsOpenModal(true) | ||
}, | ||
} | ||
}, []) | ||
|
||
return ( | ||
<Context.Provider value={value}> | ||
{children} | ||
{isAdmin && ( | ||
<GrillIframeModal | ||
pathname='/widget/moderation' | ||
style={{ zIndex: 20 }} | ||
isOpen={isOpenModal} | ||
ref={iframeRef} | ||
/> | ||
)} | ||
</Context.Provider> | ||
) | ||
} | ||
|
||
export function useModerationContext() { | ||
return React.useContext(Context) | ||
} |
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
Oops, something went wrong.