import React , { Component } from 'react' ; import useReactRouter from 'use-react-router' ; import { useSelector , useStore } from 'react-redux' ; import { addBlock } from '@app/redux/actions/block' ; import { getUserInfo } from '@app/redux/reducers/user' ; import './styles/index.scss' ; interface Props { posts : any ; user : any ; comment : any ; children ? : any ; } export default function ( { user , posts , comment , children } ) { const { history } = useReactRouter ( ) ; const me = useSelector ( ( state ) => getUserInfo ( state ) ) ; const store = useStore ( ) ; const _addBlock = ( args ) => addBlock ( args ) ( store . dispatch , store . getState ) ; if ( ! me ) return null ; const stopPropagation = function ( e ) { e . stopPropagation ( ) ; } ; const edit = function ( e ) { e . stopPropagation ( ) ; if ( comment ) { $ ( '#editor-comment-modal' ) . modal ( { show : true } , { type : 'edit' , comment } ) ; } else { history . push ( `/new-posts?posts_id=${ posts . _id }` ) ; } } ; const block = async function ( e ) { e . stopPropagation ( ) ; let args = { } ; if ( posts ) { args . posts_id = posts . _id ; } else if ( user ) { args . people_id = user . _id ; } else if ( comment ) { args . comment_id = comment . _id ; } else { $ . toast ( { text : '缺少资源' , position : 'top-center' , showHideTransition : 'slide' , icon : 'error' , loader : false , allowToastClose : false } ) ; return ; } let [ err , res ] = await _addBlock ( { args } ) ; if ( res && res . success ) { $ . toast ( { text : '屏蔽成功' , position : 'top-center' , showHideTransition : 'slide' , icon : 'success' , loader : false , allowToastClose : false } ) ; } else if ( err && err . message ) { $ . toast ( { text : err . message , position : 'top-center' , showHideTransition : 'slide' , icon : 'error' , loader : false , allowToastClose : false } ) ; } } ; const report = function ( e ) { e . stopPropagation ( ) ; $ ( '#report' ) . modal ( { show : true } , { posts , user , comment } ) ; } ; let self = false ; if ( posts && posts . user_id . _id == me . _id || comment && comment . user_id . _id == me . _id || user && user . _id == me . _id ) { self = true ; } if ( self && user ) return null ; return ( < div styleName = "container" > < span styleName = "menu" className = "a text-secondary" data - toggle = "dropdown" onClick = { stopPropagation } > { children ? children : < svg > < use xlinkHref = "/feather-sprite.svg#more-horizontal" /> < /svg>} < /span> < div className = "dropdown-menu dropdown-menu-left" > { self && posts || self && comment ? < span className = "a dropdown-item" onClick = { edit } > 编辑 < /span> : null } { ! self && posts || ! self && comment || ! self && user ? < > < span className = "a dropdown-item" onClick = { block } > 不感兴趣 < /span> < span className = "a dropdown-item" onClick = { report } > 举报 < /span> < /> : null } < /div> < /div>); }