diff --git a/app/javascript/gabsocial/actions/timelines.js b/app/javascript/gabsocial/actions/timelines.js index 4214cbde..78f372b2 100644 --- a/app/javascript/gabsocial/actions/timelines.js +++ b/app/javascript/gabsocial/actions/timelines.js @@ -7,6 +7,7 @@ export const TIMELINE_DELETE = 'TIMELINE_DELETE'; export const TIMELINE_CLEAR = 'TIMELINE_CLEAR'; export const TIMELINE_UPDATE_QUEUE = 'TIMELINE_UPDATE_QUEUE'; export const TIMELINE_DEQUEUE = 'TIMELINE_DEQUEUE'; +export const TIMELINE_SCROLL_TOP = 'TIMELINE_SCROLL_TOP'; export const TIMELINE_EXPAND_REQUEST = 'TIMELINE_EXPAND_REQUEST'; export const TIMELINE_EXPAND_SUCCESS = 'TIMELINE_EXPAND_SUCCESS'; @@ -210,3 +211,11 @@ export function disconnectTimeline(timeline) { timeline, }; }; + +export function scrollTopTimeline(timeline, top) { + return { + type: TIMELINE_SCROLL_TOP, + timeline, + top, + }; +}; diff --git a/app/javascript/gabsocial/components/scrollable_list.js b/app/javascript/gabsocial/components/scrollable_list.js index ad7a078b..6de613d5 100644 --- a/app/javascript/gabsocial/components/scrollable_list.js +++ b/app/javascript/gabsocial/components/scrollable_list.js @@ -26,6 +26,8 @@ export default class ScrollableList extends PureComponent { alwaysPrepend: PropTypes.bool, emptyMessage: PropTypes.node, children: PropTypes.node, + onScrollToTop: PropTypes.func, + onScroll: PropTypes.func, }; state = { diff --git a/app/javascript/gabsocial/features/ui/containers/status_list_container.js b/app/javascript/gabsocial/features/ui/containers/status_list_container.js index ee58b9ed..f130f9f4 100644 --- a/app/javascript/gabsocial/features/ui/containers/status_list_container.js +++ b/app/javascript/gabsocial/features/ui/containers/status_list_container.js @@ -5,6 +5,7 @@ import { createSelector } from 'reselect'; import { debounce } from 'lodash'; import { me } from '../../../initial_state'; import { dequeueTimeline } from 'gabsocial/actions/timelines'; +import { scrollTopTimeline } from '../../../actions/timelines'; const makeGetStatusIds = () => createSelector([ (state, { type }) => state.getIn(['settings', type], ImmutableMap()), @@ -45,6 +46,12 @@ const mapDispatchToProps = (dispatch, ownProps) => ({ onDequeueTimeline(timelineId) { dispatch(dequeueTimeline(timelineId, ownProps.onLoadMore)); }, + onScrollToTop: debounce(() => { + dispatch(scrollTopTimeline(ownProps.timelineId, true)); + }, 100), + onScroll: debounce(() => { + dispatch(scrollTopTimeline(ownProps.timelineId, false)); + }, 100), }); export default connect(mapStateToProps, mapDispatchToProps)(StatusList); diff --git a/app/javascript/gabsocial/reducers/timelines.js b/app/javascript/gabsocial/reducers/timelines.js index b0c1babf..11acf1e6 100644 --- a/app/javascript/gabsocial/reducers/timelines.js +++ b/app/javascript/gabsocial/reducers/timelines.js @@ -10,6 +10,7 @@ import { TIMELINE_UPDATE_QUEUE, TIMELINE_DEQUEUE, MAX_QUEUED_ITEMS, + TIMELINE_SCROLL_TOP, } from '../actions/timelines'; import { ACCOUNT_BLOCK_SUCCESS, @@ -137,6 +138,13 @@ const filterTimelines = (state, relationship, statuses) => { return state; }; +const updateTop = (state, timeline, top) => { + return state.update(timeline, initialTimeline, map => map.withMutations(mMap => { + if (top) mMap.set('unread', 0); + mMap.set('top', top); + })); +}; + const filterTimeline = (timeline, state, relationship, statuses) => state.updateIn([timeline, 'items'], ImmutableList(), list => list.filterNot(statusId => @@ -171,6 +179,8 @@ export default function timelines(state = initialState, action) { return filterTimeline('home', state, action.relationship, action.statuses); case TIMELINE_CONNECT: return state.update(action.timeline, initialTimeline, map => map.set('online', true)); + case TIMELINE_SCROLL_TOP: + return updateTop(state, action.timeline, action.top); case TIMELINE_DISCONNECT: return state.update( action.timeline,