Fix #38 - Unread indicator when new content appears above the fold
This commit is contained in:
		
							parent
							
								
									f338cc6c94
								
							
						
					
					
						commit
						5997bb47a8
					
				@ -15,6 +15,7 @@ export const NOTIFICATIONS_EXPAND_SUCCESS = 'NOTIFICATIONS_EXPAND_SUCCESS';
 | 
			
		||||
export const NOTIFICATIONS_EXPAND_FAIL    = 'NOTIFICATIONS_EXPAND_FAIL';
 | 
			
		||||
 | 
			
		||||
export const NOTIFICATIONS_CLEAR      = 'NOTIFICATIONS_CLEAR';
 | 
			
		||||
export const NOTIFICATIONS_SCROLL_TOP = 'NOTIFICATIONS_SCROLL_TOP';
 | 
			
		||||
 | 
			
		||||
const fetchRelatedRelationships = (dispatch, notifications) => {
 | 
			
		||||
  const accountIds = notifications.filter(item => item.type === 'follow').map(item => item.account.id);
 | 
			
		||||
@ -151,3 +152,10 @@ export function clearNotifications() {
 | 
			
		||||
    api(getState).post('/api/v1/notifications/clear');
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export function scrollTopNotifications(top) {
 | 
			
		||||
  return {
 | 
			
		||||
    type: NOTIFICATIONS_SCROLL_TOP,
 | 
			
		||||
    top
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,7 @@ const StatusList = React.createClass({
 | 
			
		||||
    onScroll: React.PropTypes.func,
 | 
			
		||||
    trackScroll: React.PropTypes.bool,
 | 
			
		||||
    isLoading: React.PropTypes.bool,
 | 
			
		||||
    isUnread: React.PropTypes.bool,
 | 
			
		||||
    prepend: React.PropTypes.node,
 | 
			
		||||
    emptyMessage: React.PropTypes.node
 | 
			
		||||
  },
 | 
			
		||||
@ -72,18 +73,25 @@ const StatusList = React.createClass({
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  render () {
 | 
			
		||||
    const { statusIds, onScrollToBottom, trackScroll, isLoading, prepend, emptyMessage } = this.props;
 | 
			
		||||
    const { statusIds, onScrollToBottom, trackScroll, isLoading, isUnread, prepend, emptyMessage } = this.props;
 | 
			
		||||
 | 
			
		||||
    let loadMore       = '';
 | 
			
		||||
    let scrollableArea = '';
 | 
			
		||||
    let unread         = '';
 | 
			
		||||
 | 
			
		||||
    if (!isLoading && statusIds.size > 0) {
 | 
			
		||||
      loadMore = <LoadMore onClick={this.handleLoadMore} />;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (isUnread) {
 | 
			
		||||
      unread = <div className='status-list__unread-indicator' />;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (isLoading || statusIds.size > 0 || !emptyMessage) {
 | 
			
		||||
      scrollableArea = (
 | 
			
		||||
        <div className='scrollable' ref={this.setRef}>
 | 
			
		||||
          {unread}
 | 
			
		||||
 | 
			
		||||
          <div>
 | 
			
		||||
            {prepend}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@ const messages = defineMessages({
 | 
			
		||||
const Header = React.createClass({
 | 
			
		||||
 | 
			
		||||
  propTypes: {
 | 
			
		||||
    account: ImmutablePropTypes.map.isRequired,
 | 
			
		||||
    account: ImmutablePropTypes.map,
 | 
			
		||||
    me: React.PropTypes.number.isRequired,
 | 
			
		||||
    onFollow: React.PropTypes.func.isRequired,
 | 
			
		||||
    intl: React.PropTypes.object.isRequired
 | 
			
		||||
@ -25,6 +25,10 @@ const Header = React.createClass({
 | 
			
		||||
  render () {
 | 
			
		||||
    const { account, me, intl } = this.props;
 | 
			
		||||
 | 
			
		||||
    if (!account) {
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let displayName = account.get('display_name');
 | 
			
		||||
    let info        = '';
 | 
			
		||||
    let actionBtn   = '';
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,7 @@ import { connect } from 'react-redux';
 | 
			
		||||
import PureRenderMixin from 'react-addons-pure-render-mixin';
 | 
			
		||||
import ImmutablePropTypes from 'react-immutable-proptypes';
 | 
			
		||||
import Column from '../ui/components/column';
 | 
			
		||||
import { expandNotifications, clearNotifications } from '../../actions/notifications';
 | 
			
		||||
import { expandNotifications, clearNotifications, scrollTopNotifications } from '../../actions/notifications';
 | 
			
		||||
import NotificationContainer from './containers/notification_container';
 | 
			
		||||
import { ScrollContainer } from 'react-router-scroll';
 | 
			
		||||
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
 | 
			
		||||
@ -23,7 +23,8 @@ const getNotifications = createSelector([
 | 
			
		||||
 | 
			
		||||
const mapStateToProps = state => ({
 | 
			
		||||
  notifications: getNotifications(state),
 | 
			
		||||
  isLoading: state.getIn(['notifications', 'isLoading'], true)
 | 
			
		||||
  isLoading: state.getIn(['notifications', 'isLoading'], true),
 | 
			
		||||
  isUnread: state.getIn(['notifications', 'unread']) > 0
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const Notifications = React.createClass({
 | 
			
		||||
@ -33,7 +34,8 @@ const Notifications = React.createClass({
 | 
			
		||||
    dispatch: React.PropTypes.func.isRequired,
 | 
			
		||||
    trackScroll: React.PropTypes.bool,
 | 
			
		||||
    intl: React.PropTypes.object.isRequired,
 | 
			
		||||
    isLoading: React.PropTypes.bool
 | 
			
		||||
    isLoading: React.PropTypes.bool,
 | 
			
		||||
    isUnread: React.PropTypes.bool
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  getDefaultProps () {
 | 
			
		||||
@ -51,6 +53,10 @@ const Notifications = React.createClass({
 | 
			
		||||
 | 
			
		||||
    if (250 > offset && !this.props.isLoading) {
 | 
			
		||||
      this.props.dispatch(expandNotifications());
 | 
			
		||||
    } else if (scrollTop < 100) {
 | 
			
		||||
      this.props.dispatch(scrollTopNotifications(true));
 | 
			
		||||
    } else {
 | 
			
		||||
      this.props.dispatch(scrollTopNotifications(false));
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
@ -74,18 +80,25 @@ const Notifications = React.createClass({
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  render () {
 | 
			
		||||
    const { intl, notifications, trackScroll, isLoading } = this.props;
 | 
			
		||||
    const { intl, notifications, trackScroll, isLoading, isUnread } = this.props;
 | 
			
		||||
 | 
			
		||||
    let loadMore       = '';
 | 
			
		||||
    let scrollableArea = '';
 | 
			
		||||
    let unread         = '';
 | 
			
		||||
 | 
			
		||||
    if (!isLoading && notifications.size > 0) {
 | 
			
		||||
      loadMore = <LoadMore onClick={this.handleLoadMore} />;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (isUnread) {
 | 
			
		||||
      unread = <div className='notifications__unread-indicator' />;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (isLoading || notifications.size > 0) {
 | 
			
		||||
      scrollableArea = (
 | 
			
		||||
        <div className='scrollable' onScroll={this.handleScroll} ref={this.setRef}>
 | 
			
		||||
          {unread}
 | 
			
		||||
 | 
			
		||||
          <div>
 | 
			
		||||
            {notifications.map(item => <NotificationContainer key={item.get('id')} notification={item} accountId={item.get('account')} />)}
 | 
			
		||||
            {loadMore}
 | 
			
		||||
@ -102,7 +115,7 @@ const Notifications = React.createClass({
 | 
			
		||||
 | 
			
		||||
    if (trackScroll) {
 | 
			
		||||
      return (
 | 
			
		||||
        <Column icon='bell' heading={intl.formatMessage(messages.title)}>
 | 
			
		||||
        <Column icon='bell' active={isUnread} heading={intl.formatMessage(messages.title)}>
 | 
			
		||||
          <ColumnSettingsContainer />
 | 
			
		||||
          <ClearColumnButton onClick={this.handleClear} />
 | 
			
		||||
          <ScrollContainer scrollKey='notifications'>
 | 
			
		||||
@ -112,7 +125,7 @@ const Notifications = React.createClass({
 | 
			
		||||
      );
 | 
			
		||||
    } else {
 | 
			
		||||
      return (
 | 
			
		||||
        <Column icon='bell' heading={intl.formatMessage(messages.title)}>
 | 
			
		||||
        <Column icon='bell' active={isUnread} heading={intl.formatMessage(messages.title)}>
 | 
			
		||||
          <ColumnSettingsContainer />
 | 
			
		||||
          <ClearColumnButton onClick={this.handleClear} />
 | 
			
		||||
          {scrollableArea}
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,8 @@ const Column = React.createClass({
 | 
			
		||||
  propTypes: {
 | 
			
		||||
    heading: React.PropTypes.string,
 | 
			
		||||
    icon: React.PropTypes.string,
 | 
			
		||||
    children: React.PropTypes.node
 | 
			
		||||
    children: React.PropTypes.node,
 | 
			
		||||
    active: React.PropTypes.bool
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  mixins: [PureRenderMixin],
 | 
			
		||||
@ -51,12 +52,12 @@ const Column = React.createClass({
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  render () {
 | 
			
		||||
    const { heading, icon, children } = this.props;
 | 
			
		||||
    const { heading, icon, children, active } = this.props;
 | 
			
		||||
 | 
			
		||||
    let header = '';
 | 
			
		||||
 | 
			
		||||
    if (heading) {
 | 
			
		||||
      header = <ColumnHeader icon={icon} type={heading} onClick={this.handleHeaderClick} />;
 | 
			
		||||
      header = <ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} />;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@ const ColumnHeader = React.createClass({
 | 
			
		||||
  propTypes: {
 | 
			
		||||
    icon: React.PropTypes.string,
 | 
			
		||||
    type: React.PropTypes.string,
 | 
			
		||||
    active: React.PropTypes.bool,
 | 
			
		||||
    onClick: React.PropTypes.func
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
@ -15,6 +16,8 @@ const ColumnHeader = React.createClass({
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  render () {
 | 
			
		||||
    const { type, active } = this.props;
 | 
			
		||||
 | 
			
		||||
    let icon = '';
 | 
			
		||||
 | 
			
		||||
    if (this.props.icon) {
 | 
			
		||||
@ -22,9 +25,9 @@ const ColumnHeader = React.createClass({
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
      <div className='column-header' onClick={this.handleClick}>
 | 
			
		||||
      <div className={`column-header ${active ? 'active' : ''}`} onClick={this.handleClick}>
 | 
			
		||||
        {icon}
 | 
			
		||||
        {this.props.type}
 | 
			
		||||
        {type}
 | 
			
		||||
      </div>
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@ import Immutable from 'immutable';
 | 
			
		||||
import { createSelector } from 'reselect';
 | 
			
		||||
import { debounce } from 'react-decoration';
 | 
			
		||||
 | 
			
		||||
const getStatusIds = createSelector([
 | 
			
		||||
const makeGetStatusIds = () => createSelector([
 | 
			
		||||
  (state, { type }) => state.getIn(['settings', type], Immutable.Map()),
 | 
			
		||||
  (state, { type }) => state.getIn(['timelines', type, 'items'], Immutable.List()),
 | 
			
		||||
  (state)           => state.get('statuses'),
 | 
			
		||||
@ -34,10 +34,17 @@ const getStatusIds = createSelector([
 | 
			
		||||
  return showStatus;
 | 
			
		||||
}));
 | 
			
		||||
 | 
			
		||||
const mapStateToProps = (state, props) => ({
 | 
			
		||||
const makeMapStateToProps = () => {
 | 
			
		||||
  const getStatusIds = makeGetStatusIds();
 | 
			
		||||
 | 
			
		||||
  const mapStateToProps = (state, props) => ({
 | 
			
		||||
    statusIds: getStatusIds(state, props),
 | 
			
		||||
  isLoading: state.getIn(['timelines', props.type, 'isLoading'], true)
 | 
			
		||||
});
 | 
			
		||||
    isLoading: state.getIn(['timelines', props.type, 'isLoading'], true),
 | 
			
		||||
    isUnread: state.getIn(['timelines', props.type, 'unread']) > 0
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return mapStateToProps;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const mapDispatchToProps = (dispatch, { type, id }) => ({
 | 
			
		||||
 | 
			
		||||
@ -59,4 +66,4 @@ const mapDispatchToProps = (dispatch, { type, id }) => ({
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export default connect(mapStateToProps, mapDispatchToProps)(StatusList);
 | 
			
		||||
export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,8 @@ import {
 | 
			
		||||
  NOTIFICATIONS_EXPAND_REQUEST,
 | 
			
		||||
  NOTIFICATIONS_REFRESH_FAIL,
 | 
			
		||||
  NOTIFICATIONS_EXPAND_FAIL,
 | 
			
		||||
  NOTIFICATIONS_CLEAR
 | 
			
		||||
  NOTIFICATIONS_CLEAR,
 | 
			
		||||
  NOTIFICATIONS_SCROLL_TOP
 | 
			
		||||
} from '../actions/notifications';
 | 
			
		||||
import { ACCOUNT_BLOCK_SUCCESS } from '../actions/accounts';
 | 
			
		||||
import Immutable from 'immutable';
 | 
			
		||||
@ -14,6 +15,8 @@ import Immutable from 'immutable';
 | 
			
		||||
const initialState = Immutable.Map({
 | 
			
		||||
  items: Immutable.List(),
 | 
			
		||||
  next: null,
 | 
			
		||||
  top: true,
 | 
			
		||||
  unread: 0,
 | 
			
		||||
  loaded: false,
 | 
			
		||||
  isLoading: true
 | 
			
		||||
});
 | 
			
		||||
@ -26,6 +29,10 @@ const notificationToMap = notification => Immutable.Map({
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const normalizeNotification = (state, notification) => {
 | 
			
		||||
  if (!state.get('top')) {
 | 
			
		||||
    state = state.update('unread', unread => unread + 1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return state.update('items', list => list.unshift(notificationToMap(notification)));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -64,6 +71,14 @@ const filterNotifications = (state, relationship) => {
 | 
			
		||||
  return state.update('items', list => list.filterNot(item => item.get('account') === relationship.id));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const updateTop = (state, top) => {
 | 
			
		||||
  if (top) {
 | 
			
		||||
    state = state.set('unread', 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return state.set('top', top);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default function notifications(state = initialState, action) {
 | 
			
		||||
  switch(action.type) {
 | 
			
		||||
  case NOTIFICATIONS_REFRESH_REQUEST:
 | 
			
		||||
@ -71,6 +86,8 @@ export default function notifications(state = initialState, action) {
 | 
			
		||||
  case NOTIFICATIONS_REFRESH_FAIL:
 | 
			
		||||
  case NOTIFICATIONS_EXPAND_FAIL:
 | 
			
		||||
    return state.set('isLoading', true);
 | 
			
		||||
  case NOTIFICATIONS_SCROLL_TOP:
 | 
			
		||||
    return updateTop(state, action.top);
 | 
			
		||||
  case NOTIFICATIONS_UPDATE:
 | 
			
		||||
    return normalizeNotification(state, action.notification);
 | 
			
		||||
  case NOTIFICATIONS_REFRESH_SUCCESS:
 | 
			
		||||
 | 
			
		||||
@ -36,6 +36,7 @@ const initialState = Immutable.Map({
 | 
			
		||||
    isLoading: false,
 | 
			
		||||
    loaded: false,
 | 
			
		||||
    top: true,
 | 
			
		||||
    unread: 0,
 | 
			
		||||
    items: Immutable.List()
 | 
			
		||||
  }),
 | 
			
		||||
 | 
			
		||||
@ -45,6 +46,7 @@ const initialState = Immutable.Map({
 | 
			
		||||
    isLoading: false,
 | 
			
		||||
    loaded: false,
 | 
			
		||||
    top: true,
 | 
			
		||||
    unread: 0,
 | 
			
		||||
    items: Immutable.List()
 | 
			
		||||
  }),
 | 
			
		||||
 | 
			
		||||
@ -55,6 +57,7 @@ const initialState = Immutable.Map({
 | 
			
		||||
    isLoading: false,
 | 
			
		||||
    loaded: false,
 | 
			
		||||
    top: true,
 | 
			
		||||
    unread: 0,
 | 
			
		||||
    items: Immutable.List()
 | 
			
		||||
  }),
 | 
			
		||||
 | 
			
		||||
@ -65,6 +68,7 @@ const initialState = Immutable.Map({
 | 
			
		||||
    id: null,
 | 
			
		||||
    loaded: false,
 | 
			
		||||
    top: true,
 | 
			
		||||
    unread: 0,
 | 
			
		||||
    items: Immutable.List()
 | 
			
		||||
  }),
 | 
			
		||||
 | 
			
		||||
@ -155,6 +159,10 @@ const updateTimeline = (state, timeline, status, references) => {
 | 
			
		||||
 | 
			
		||||
  state = normalizeStatus(state, status);
 | 
			
		||||
 | 
			
		||||
  if (!top) {
 | 
			
		||||
    state = state.updateIn([timeline, 'unread'], unread => unread + 1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  state = state.updateIn([timeline, 'items'], Immutable.List(), list => {
 | 
			
		||||
    if (top && list.size > 40) {
 | 
			
		||||
      list = list.take(20);
 | 
			
		||||
@ -249,6 +257,14 @@ const resetTimeline = (state, timeline, id) => {
 | 
			
		||||
  return state;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const updateTop = (state, timeline, top) => {
 | 
			
		||||
  if (top) {
 | 
			
		||||
    state = state.setIn([timeline, 'unread'], 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return state.setIn([timeline, 'top'], top);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default function timelines(state = initialState, action) {
 | 
			
		||||
  switch(action.type) {
 | 
			
		||||
  case TIMELINE_REFRESH_REQUEST:
 | 
			
		||||
@ -280,7 +296,7 @@ export default function timelines(state = initialState, action) {
 | 
			
		||||
  case ACCOUNT_BLOCK_SUCCESS:
 | 
			
		||||
    return filterTimelines(state, action.relationship, action.statuses);
 | 
			
		||||
  case TIMELINE_SCROLL_TOP:
 | 
			
		||||
    return state.setIn([action.timeline, 'top'], action.top);
 | 
			
		||||
    return updateTop(state, action.timeline, action.top);
 | 
			
		||||
  default:
 | 
			
		||||
    return state;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -1079,6 +1079,11 @@ button.active i.fa-retweet {
 | 
			
		||||
  background: lighten($color1, 4%);
 | 
			
		||||
  flex: 0 0 auto;
 | 
			
		||||
  cursor: pointer;
 | 
			
		||||
 | 
			
		||||
  &.active {
 | 
			
		||||
    color: $color4;
 | 
			
		||||
    text-shadow: 0 0 10px rgba($color4, 0.4);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.search {
 | 
			
		||||
@ -1201,3 +1206,14 @@ button.active i.fa-retweet {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.status-list__unread-indicator, .notifications__unread-indicator {
 | 
			
		||||
  position: absolute;
 | 
			
		||||
  top: 48px;
 | 
			
		||||
  left: 0;
 | 
			
		||||
  width: 100%;
 | 
			
		||||
  pointer-events: none;
 | 
			
		||||
  height: 30px;
 | 
			
		||||
  z-index: 2;
 | 
			
		||||
  background: linear-gradient(to bottom, rgba($color4, 0.3) 0%, rgba($color4, 0) 60%);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user