about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/community_timeline/components
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-05-27 21:28:24 +0200
committerThibG <thib@sitedethib.com>2018-12-18 21:39:35 +0100
commita693d6e2f2f9e3345e502b9b7c68130780600d91 (patch)
tree7b03a49fd5bf4eb81f647f9c59c5465c1667c189 /app/javascript/flavours/glitch/features/community_timeline/components
parent593f88acb159f53a1213562d1c29333439c7da65 (diff)
[Glitch] Hide section headline for timelines in production
Port 4eeda6772796bcd08b8c63ec2e1f3e68a95cbca4 to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch/features/community_timeline/components')
-rw-r--r--app/javascript/flavours/glitch/features/community_timeline/components/section_headline.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/features/community_timeline/components/section_headline.js b/app/javascript/flavours/glitch/features/community_timeline/components/section_headline.js
new file mode 100644
index 000000000..c7176d04b
--- /dev/null
+++ b/app/javascript/flavours/glitch/features/community_timeline/components/section_headline.js
@@ -0,0 +1,59 @@
+import PropTypes from 'prop-types';
+import React, { Component, Fragment } from 'react';
+import { FormattedMessage } from 'react-intl';
+import { NavLink } from 'react-router-dom';
+
+export default class SectionHeadline extends Component {
+
+  static propTypes = {
+    timelineId: PropTypes.string.isRequired,
+    to: PropTypes.string.isRequired,
+    pinned: PropTypes.bool.isRequired,
+    onlyMedia: PropTypes.bool.isRequired,
+    onClick: PropTypes.func,
+  };
+
+  shouldComponentUpdate (nextProps) {
+    return (
+      this.props.onlyMedia !== nextProps.onlyMedia ||
+      this.props.pinned !== nextProps.pinned ||
+      this.props.to !== nextProps.to ||
+      this.props.timelineId !== nextProps.timelineId
+    );
+  }
+
+  handleClick = e => {
+    const { onClick } = this.props;
+
+    if (typeof onClick === 'function') {
+      e.preventDefault();
+
+      onClick.call(this, e);
+    }
+  }
+
+  render () {
+    const { timelineId, to, pinned, onlyMedia } = this.props;
+
+    return (
+      <div className={`${timelineId}-timeline__section-headline`}>
+        {pinned ? (
+          <Fragment>
+            <a href={to} className={!onlyMedia ? 'active' : undefined} onClick={this.handleClick}>
+              <FormattedMessage id='timeline.posts' defaultMessage='Toots' />
+            </a>
+            <a href={`${to}/media`} className={onlyMedia ? 'active' : undefined} onClick={this.handleClick}>
+              <FormattedMessage id='timeline.media' defaultMessage='Media' />
+            </a>
+          </Fragment>
+        ) : (
+          <Fragment>
+            <NavLink exact to={to} replace><FormattedMessage id='timeline.posts' defaultMessage='Toots' /></NavLink>
+            <NavLink exact to={`${to}/media`} replace><FormattedMessage id='timeline.media' defaultMessage='Media' /></NavLink>
+          </Fragment>
+        )}
+      </div>
+    );
+  }
+
+}