Updated DisplayName, Avatar functionality for opening, closing UserInfoPopover
• Updated: - DisplayName, Avatar functionality for opening, closing UserInfoPopover • Todo: - Work out issues with closing after certain conditions are met
This commit is contained in:
parent
79330acb21
commit
eedde4a4a7
@ -1,5 +1,6 @@
|
|||||||
import ImmutablePropTypes from 'react-immutable-proptypes'
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component'
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
||||||
|
import debounce from 'lodash.debounce'
|
||||||
import { autoPlayGif } from '../initial_state'
|
import { autoPlayGif } from '../initial_state'
|
||||||
import { openPopover, closePopover } from '../actions/popover'
|
import { openPopover, closePopover } from '../actions/popover'
|
||||||
import Image from './image'
|
import Image from './image'
|
||||||
@ -54,23 +55,48 @@ class Avatar extends ImmutablePureComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount () {
|
||||||
|
document.removeEventListener('mousemove', this.handleMouseMove, true)
|
||||||
|
clearTimeout(this.mouseOverTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
handleMouseEnter = () => {
|
handleMouseEnter = () => {
|
||||||
this.setState({ hovering: true })
|
this.setState({ hovering: true })
|
||||||
|
|
||||||
if (this.mouseOverTimeout || this.props.noHover) return null
|
if (this.mouseOverTimeout || this.props.noHover) return null
|
||||||
|
|
||||||
this.mouseOverTimeout = setTimeout(() => {
|
this.mouseOverTimeout = setTimeout(() => {
|
||||||
this.props.openUserInfoPopover({
|
this.props.openUserInfoPopover({
|
||||||
targetRef: this.node,
|
targetRef: this.node,
|
||||||
position: 'top',
|
position: 'top',
|
||||||
account: this.props.account,
|
accountId: this.props.account.get('id'),
|
||||||
})
|
})
|
||||||
|
document.addEventListener('mousemove', this.handleMouseMove, true)
|
||||||
}, 650)
|
}, 650)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMouseLeave = () => {
|
handleMouseLeave = debounce((e) => {
|
||||||
this.setState({ hovering: false })
|
this.setState({ hovering: false })
|
||||||
|
this.attemptToHidePopover(e)
|
||||||
|
}, 250)
|
||||||
|
|
||||||
if (this.mouseOverTimeout && !this.props.noHover) {
|
handleMouseMove = debounce((e) => {
|
||||||
|
this.attemptToHidePopover(e)
|
||||||
|
}, 150)
|
||||||
|
|
||||||
|
attemptToHidePopover = (e) => {
|
||||||
|
const lastTarget = e.toElement || e.relatedTarget
|
||||||
|
if (!(lastTarget instanceof Element || lastTarget instanceof HTMLDocument)) return
|
||||||
|
|
||||||
|
const userInfoPopoverEl = document.getElementById('user-info-popover')
|
||||||
|
|
||||||
|
if (this.mouseOverTimeout &&
|
||||||
|
!this.props.noHover &&
|
||||||
|
(
|
||||||
|
(userInfoPopoverEl && lastTarget && !userInfoPopoverEl.contains(lastTarget)) ||
|
||||||
|
(!userInfoPopoverEl && lastTarget && this.node && !this.node.contains(lastTarget))
|
||||||
|
)) {
|
||||||
|
document.removeEventListener('mousemove', this.handleMouseMove, true)
|
||||||
clearTimeout(this.mouseOverTimeout)
|
clearTimeout(this.mouseOverTimeout)
|
||||||
this.mouseOverTimeout = null
|
this.mouseOverTimeout = null
|
||||||
this.props.closeUserInfoPopover()
|
this.props.closeUserInfoPopover()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import ImmutablePropTypes from 'react-immutable-proptypes'
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component'
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
||||||
|
import debounce from 'lodash.debounce'
|
||||||
import { me } from '../initial_state'
|
import { me } from '../initial_state'
|
||||||
import {
|
import {
|
||||||
CX,
|
CX,
|
||||||
@ -50,19 +51,43 @@ class DisplayName extends ImmutablePureComponent {
|
|||||||
|
|
||||||
mouseOverTimeout = null
|
mouseOverTimeout = null
|
||||||
|
|
||||||
|
componentWillUnmount () {
|
||||||
|
document.removeEventListener('mousemove', this.handleMouseMove, true)
|
||||||
|
clearTimeout(this.mouseOverTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
handleMouseEnter = () => {
|
handleMouseEnter = () => {
|
||||||
if (this.mouseOverTimeout) return null
|
if (this.mouseOverTimeout) return null
|
||||||
this.mouseOverTimeout = setTimeout(() => {
|
this.mouseOverTimeout = setTimeout(() => {
|
||||||
this.props.openUserInfoPopover({
|
this.props.openUserInfoPopover({
|
||||||
targetRef: this.node,
|
targetRef: this.node,
|
||||||
position: 'top',
|
position: 'top',
|
||||||
account: this.props.account,
|
accountId: this.props.account.get('id'),
|
||||||
})
|
})
|
||||||
|
document.addEventListener('mousemove', this.handleMouseMove, true)
|
||||||
}, 650)
|
}, 650)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMouseLeave = () => {
|
handleMouseLeave = debounce((e) => {
|
||||||
if (this.mouseOverTimeout) {
|
this.attemptToHidePopover(e)
|
||||||
|
}, 250)
|
||||||
|
|
||||||
|
handleMouseMove = debounce((e) => {
|
||||||
|
this.attemptToHidePopover(e)
|
||||||
|
}, 150)
|
||||||
|
|
||||||
|
attemptToHidePopover = (e) => {
|
||||||
|
const lastTarget = e.toElement || e.relatedTarget
|
||||||
|
if (!(lastTarget instanceof Element || lastTarget instanceof HTMLDocument)) return
|
||||||
|
|
||||||
|
const userInfoPopoverEl = document.getElementById('user-info-popover')
|
||||||
|
|
||||||
|
if (this.mouseOverTimeout &&
|
||||||
|
(
|
||||||
|
(userInfoPopoverEl && lastTarget && !userInfoPopoverEl.contains(lastTarget)) ||
|
||||||
|
(!userInfoPopoverEl && lastTarget && this.node && !this.node.contains(lastTarget))
|
||||||
|
)) {
|
||||||
|
document.removeEventListener('mousemove', this.handleMouseMove, true)
|
||||||
clearTimeout(this.mouseOverTimeout)
|
clearTimeout(this.mouseOverTimeout)
|
||||||
this.mouseOverTimeout = null
|
this.mouseOverTimeout = null
|
||||||
this.props.closeUserInfoPopover()
|
this.props.closeUserInfoPopover()
|
||||||
@ -132,9 +157,6 @@ class DisplayName extends ImmutablePureComponent {
|
|||||||
!!isComment ? 12 :
|
!!isComment ? 12 :
|
||||||
!!isSmall ? 14 : 15
|
!!isSmall ? 14 : 15
|
||||||
|
|
||||||
const domain = account.get('acct').split('@')[1]
|
|
||||||
const isRemoteUser = !!domain
|
|
||||||
|
|
||||||
let relationshipLabel
|
let relationshipLabel
|
||||||
if (me && account) {
|
if (me && account) {
|
||||||
const accountId = account.get('id')
|
const accountId = account.get('id')
|
||||||
@ -146,13 +168,11 @@ class DisplayName extends ImmutablePureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// {
|
// {
|
||||||
// /* : todo : audio-mute
|
// /* : todo : audio-mute, bot
|
||||||
// account.getIn(['relationship', 'muting'])
|
// account.getIn(['relationship', 'muting'])
|
||||||
// */
|
// */
|
||||||
// }
|
// }
|
||||||
|
// bot: { id: 'account.badges.bot', defaultMessage: 'Bot' },
|
||||||
// : todo : remote
|
|
||||||
// console.log("domain, isRemoteUser:", domain, isRemoteUser)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
Loading…
x
Reference in New Issue
Block a user