about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/public_timeline
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-05-27 21:26:33 +0200
committerThibG <thib@sitedethib.com>2018-12-18 21:39:35 +0100
commit593f88acb159f53a1213562d1c29333439c7da65 (patch)
treea0352971ca4d5523e8f0c09c9dbe2f18b068b41d /app/javascript/flavours/glitch/features/public_timeline
parentc03cbb9471be1437f3cf1671b7592966db9c5c0b (diff)
[Glitch] Change column params on pinned timeline
Port 06252ec71ed67cb84e6730fe7148552dc6481c7a to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch/features/public_timeline')
-rw-r--r--app/javascript/flavours/glitch/features/public_timeline/index.js35
1 files changed, 31 insertions, 4 deletions
diff --git a/app/javascript/flavours/glitch/features/public_timeline/index.js b/app/javascript/flavours/glitch/features/public_timeline/index.js
index 8e27bcd7c..e1561ae41 100644
--- a/app/javascript/flavours/glitch/features/public_timeline/index.js
+++ b/app/javascript/flavours/glitch/features/public_timeline/index.js
@@ -1,13 +1,13 @@
 import React from 'react';
 import { connect } from 'react-redux';
 import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
-import { NavLink, Link } from 'react-router-dom';
+import { NavLink } from 'react-router-dom';
 import PropTypes from 'prop-types';
 import StatusListContainer from 'flavours/glitch/features/ui/containers/status_list_container';
 import Column from 'flavours/glitch/components/column';
 import ColumnHeader from 'flavours/glitch/components/column_header';
 import { expandPublicTimeline } from 'flavours/glitch/actions/timelines';
-import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/columns';
+import { addColumn, removeColumn, moveColumn, changeColumnParams } from 'flavours/glitch/actions/columns';
 import ColumnSettingsContainer from './containers/column_settings_container';
 import { connectPublicStream } from 'flavours/glitch/actions/streaming';
 
@@ -62,6 +62,16 @@ export default class PublicTimeline extends React.PureComponent {
     this.disconnect = dispatch(connectPublicStream({ onlyMedia }));
   }
 
+  componentDidUpdate (prevProps) {
+    if (prevProps.onlyMedia !== this.props.onlyMedia) {
+      const { dispatch, onlyMedia } = this.props;
+
+      this.disconnect();
+      dispatch(expandPublicTimeline({ onlyMedia }));
+      this.disconnect = dispatch(connectPublicStream({ onlyMedia }));
+    }
+  }
+
   componentWillUnmount () {
     if (this.disconnect) {
       this.disconnect();
@@ -79,14 +89,31 @@ export default class PublicTimeline extends React.PureComponent {
     dispatch(expandPublicTimeline({ maxId, onlyMedia }));
   }
 
+  shouldUpdateScroll = (prevRouterProps, { location }) => {
+    return !(location.state && location.state.mastodonModalOpen)
+  }
+
+  handleHeadlineLinkClick = e => {
+    e.preventDefault();
+
+    const { columnId, dispatch } = this.props;
+    const onlyMedia = /\/media$/.test(e.currentTarget.href);
+
+    dispatch(changeColumnParams(columnId, { other: { onlyMedia } }));
+  }
+
   render () {
     const { intl, columnId, hasUnread, multiColumn, onlyMedia } = this.props;
     const pinned = !!columnId;
 
     const headline = pinned ? (
       <div className='public-timeline__section-headline'>
-        <Link to='/timelines/public' replace className={!onlyMedia ? 'active' : undefined}><FormattedMessage id='timeline.posts' defaultMessage='Toots' /></Link>
-        <Link to='/timelines/public/media' replace className={onlyMedia ? 'active' : undefined}><FormattedMessage id='timeline.media' defaultMessage='Media' /></Link>
+        <a href='/timelines/public' className={!onlyMedia ? 'active' : undefined} onClick={this.handleHeadlineLinkClick}>
+          <FormattedMessage id='timeline.posts' defaultMessage='Toots' />
+        </a>
+        <a href='/timelines/public/media' className={onlyMedia ? 'active' : undefined} onClick={this.handleHeadlineLinkClick}>
+          <FormattedMessage id='timeline.media' defaultMessage='Media' />
+        </a>
       </div>
     ) : (
       <div className='public-timeline__section-headline'>