about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features
diff options
context:
space:
mode:
authorbeatrix <beatrix.bitrot@gmail.com>2018-04-26 11:34:14 -0400
committerGitHub <noreply@github.com>2018-04-26 11:34:14 -0400
commitf4ed38272be7cce814e3d3e7e5a2d1f352279e19 (patch)
tree4e26499478b18d2338be90f21428f1bd76481b89 /app/javascript/flavours/glitch/features
parent8f12afb5996c58ddf41ceaa20f6c4e036273d3a6 (diff)
parentb383c0688a0939d25b9184e61dac72cda71f6926 (diff)
Merge pull request #401 from ThibG/glitch-soc/features/unfold-thread
Port the “unfold thread” feature from Mastodon's UI to glitch-soc flavour
Diffstat (limited to 'app/javascript/flavours/glitch/features')
-rw-r--r--app/javascript/flavours/glitch/features/status/components/detailed_status.js7
-rw-r--r--app/javascript/flavours/glitch/features/status/index.js27
-rw-r--r--app/javascript/flavours/glitch/features/ui/components/column_header.js20
3 files changed, 37 insertions, 17 deletions
diff --git a/app/javascript/flavours/glitch/features/status/components/detailed_status.js b/app/javascript/flavours/glitch/features/status/components/detailed_status.js
index 066499da8..16f7ae830 100644
--- a/app/javascript/flavours/glitch/features/status/components/detailed_status.js
+++ b/app/javascript/flavours/glitch/features/status/components/detailed_status.js
@@ -24,6 +24,8 @@ export default class DetailedStatus extends ImmutablePureComponent {
     settings: ImmutablePropTypes.map.isRequired,
     onOpenMedia: PropTypes.func.isRequired,
     onOpenVideo: PropTypes.func.isRequired,
+    onToggleHidden: PropTypes.func.isRequired,
+    expanded: PropTypes.bool,
   };
 
   handleAccountClick = (e) => {
@@ -41,7 +43,7 @@ export default class DetailedStatus extends ImmutablePureComponent {
 
   render () {
     const status = this.props.status.get('reblog') ? this.props.status.get('reblog') : this.props.status;
-    const { expanded, setExpansion, settings } = this.props;
+    const { expanded, onToggleHidden, settings } = this.props;
 
     let media           = '';
     let mediaIcon       = null;
@@ -114,7 +116,8 @@ export default class DetailedStatus extends ImmutablePureComponent {
           media={media}
           mediaIcon={mediaIcon}
           expanded={expanded}
-          setExpansion={setExpansion}
+          collapsed={false}
+          onExpandedToggle={onToggleHidden}
         />
 
         <div className='detailed-status__meta'>
diff --git a/app/javascript/flavours/glitch/features/status/index.js b/app/javascript/flavours/glitch/features/status/index.js
index 717f99d4a..7e1658dbb 100644
--- a/app/javascript/flavours/glitch/features/status/index.js
+++ b/app/javascript/flavours/glitch/features/status/index.js
@@ -29,6 +29,7 @@ import { initReport } from 'flavours/glitch/actions/reports';
 import { makeGetStatus } from 'flavours/glitch/selectors';
 import { ScrollContainer } from 'react-router-scroll-4';
 import ColumnBackButton from 'flavours/glitch/components/column_back_button';
+import ColumnHeader from '../../components/column_header';
 import StatusContainer from 'flavours/glitch/containers/status_container';
 import { openModal } from 'flavours/glitch/actions/modal';
 import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
@@ -41,6 +42,8 @@ const messages = defineMessages({
   deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
   deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
   blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' },
+  revealAll: { id: 'status.show_more_all', defaultMessage: 'Show more for all' },
+  hideAll: { id: 'status.show_less_all', defaultMessage: 'Show less for all' },
 });
 
 const makeMapStateToProps = () => {
@@ -76,7 +79,8 @@ export default class Status extends ImmutablePureComponent {
 
   state = {
     fullscreen: false,
-    isExpanded: null,
+    isExpanded: false,
+    threadExpanded: null,
   };
 
   componentWillMount () {
@@ -96,7 +100,7 @@ export default class Status extends ImmutablePureComponent {
 
   handleExpandedToggle = () => {
     if (this.props.status.get('spoiler_text')) {
-      this.setExpansion(this.state.isExpanded ? null : true);
+      this.setExpansion(!this.state.isExpanded);
     }
   };
 
@@ -190,6 +194,11 @@ export default class Status extends ImmutablePureComponent {
     }
   }
 
+  handleToggleAll = () => {
+    const { isExpanded } = this.state;
+    this.setState({ isExpanded: !isExpanded, threadExpanded: !isExpanded });
+  }
+
   handleBlockClick = (account) => {
     const { dispatch, intl } = this.props;
 
@@ -285,6 +294,7 @@ export default class Status extends ImmutablePureComponent {
       <StatusContainer
         key={id}
         id={id}
+        expanded={this.state.threadExpanded}
         onMoveUp={this.handleMoveUp}
         onMoveDown={this.handleMoveDown}
       />
@@ -292,7 +302,7 @@ export default class Status extends ImmutablePureComponent {
   }
 
   setExpansion = value => {
-    this.setState({ isExpanded: value ? true : null });
+    this.setState({ isExpanded: value });
   }
 
   setRef = c => {
@@ -327,7 +337,7 @@ export default class Status extends ImmutablePureComponent {
   render () {
     let ancestors, descendants;
     const { setExpansion } = this;
-    const { status, settings, ancestorsIds, descendantsIds } = this.props;
+    const { status, settings, ancestorsIds, descendantsIds, intl } = this.props;
     const { fullscreen, isExpanded } = this.state;
 
     if (status === null) {
@@ -360,7 +370,12 @@ export default class Status extends ImmutablePureComponent {
 
     return (
       <Column>
-        <ColumnBackButton />
+        <ColumnHeader
+          showBackButton
+          extraButton={(
+            <button className='column-header__button' title={intl.formatMessage(!isExpanded ? messages.revealAll : messages.hideAll)} aria-label={intl.formatMessage(!isExpanded ? messages.revealAll : messages.hideAll)} onClick={this.handleToggleAll} aria-pressed={!isExpanded ? 'false' : 'true'}><i className={`fa fa-${!isExpanded ? 'eye-slash' : 'eye'}`} /></button>
+          )}
+        />
 
         <ScrollContainer scrollKey='thread'>
           <div className={classNames('scrollable', 'detailed-status__wrapper', { fullscreen })} ref={this.setRef}>
@@ -374,7 +389,7 @@ export default class Status extends ImmutablePureComponent {
                   onOpenVideo={this.handleOpenVideo}
                   onOpenMedia={this.handleOpenMedia}
                   expanded={isExpanded}
-                  setExpansion={setExpansion}
+                  onToggleHidden={this.handleExpandedToggle}
                 />
 
                 <ActionBar
diff --git a/app/javascript/flavours/glitch/features/ui/components/column_header.js b/app/javascript/flavours/glitch/features/ui/components/column_header.js
index af195ea9c..e8bdd8054 100644
--- a/app/javascript/flavours/glitch/features/ui/components/column_header.js
+++ b/app/javascript/flavours/glitch/features/ui/components/column_header.js
@@ -1,5 +1,6 @@
 import React from 'react';
 import PropTypes from 'prop-types';
+import classNames from 'classnames';
 
 export default class ColumnHeader extends React.PureComponent {
 
@@ -16,19 +17,20 @@ export default class ColumnHeader extends React.PureComponent {
   }
 
   render () {
-    const { type, active, columnHeaderId } = this.props;
+    const { icon, type, active, columnHeaderId } = this.props;
+    let iconElement = '';
 
-    let icon = '';
-
-    if (this.props.icon) {
-      icon = <i className={`fa fa-fw fa-${this.props.icon} column-header__icon`} />;
+    if (icon) {
+      iconElement = <i className={`fa fa-fw fa-${icon} column-header__icon`} />;
     }
 
     return (
-      <div role='heading' tabIndex='0' className={`column-header ${active ? 'active' : ''}`} onClick={this.handleClick} id={columnHeaderId || null}>
-        {icon}
-        {type}
-      </div>
+      <h1 className={classNames('column-header', { active })} id={columnHeaderId || null}>
+        <button onClick={this.handleClick}>
+          {iconElement}
+          {type}
+        </button>
+      </h1>
     );
   }