import React , { useState , useEffect } from 'react' ; import { connect , useStore , useSelector } from 'react-redux' ; import { getUserInfo } from '@app/redux/reducers/user' ; import { getFeedListById } from '@app/redux/reducers/feed' ; import { refreshFeedListById } from '@app/redux/actions/feed' ; import { loadTips } from '@app/redux/actions/tips' ; import { loadUserInfo } from '@app/redux/actions/user' ; import { getTipsById } from '@app/redux/reducers/tips' ; import './styles/index.scss' ; interface Props { topicId : string ; } export default function ( { topicId } ) { const me = useSelector ( ( state ) => getUserInfo ( state ) ) ; if ( ! me ) { return null ; } const hasNew = useSelector ( ( state ) => getTipsById ( state , topicId ) ) ; const _getFeedListById = useSelector ( ( state ) => getFeedListById ( state , topicId ) ) ; const store = useStore ( ) ; const _refreshPostsListById = ( args ) => refreshFeedListById ( args ) ( store . dispatch , store . getState ) ; const _loadTips = ( params ) => loadTips ( params ) ( store . dispatch , store . getState ) ; const _loadUserInfo = ( args ) => loadUserInfo ( args ) ( store . dispatch , store . getState ) ; const start = async function ( ) { let date = me [ `last_find_${ topicId == 'favorite' ? 'subscribe' : topicId }_at` ] || '' ; if ( ! date ) return ; let { data = null } = _getFeedListById || { } ; if ( ! data ) { setTimeout ( async ( ) => { await _loadUserInfo ( { } ) ; _loadTips ( 'new-feed' ) ; } , 1000 ) ; } } ; const loadNewPosts = async function ( ) { await _refreshPostsListById ( topicId ) ; await _loadUserInfo ( { } ) ; _loadTips ( 'new-feed' ) ; } ; useEffect ( ( ) => { start ( ) ; } , [ ] ) ; if ( ! hasNew ) return null ; return < span styleName = "bar" className = "a" onClick = { loadNewPosts } > 有新的动态 < /span>; }