about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-03-28 19:56:46 +0200
committerThibaut Girka <thib@sitedethib.com>2018-04-22 19:19:01 +0200
commit64d8d0464dedeabf09b5a651151f177dba2053df (patch)
tree0de37076e213287faa9e397561960f4cbf997cf3
parent2888f74c1219e53e0aca28263ea8289d17264c21 (diff)
Add show more/less toggle for entire threads in web UI
Inspired from b6003afcdb1b89eb967a2b211e3b4e26aed9ac9d but using component
properties instead of redux store for hidden/revealed state.
-rw-r--r--app/javascript/flavours/glitch/components/column_header.js27
-rw-r--r--app/javascript/flavours/glitch/components/status.js8
-rw-r--r--app/javascript/flavours/glitch/components/status_content.js8
-rw-r--r--app/javascript/flavours/glitch/features/status/components/detailed_status.js6
-rw-r--r--app/javascript/flavours/glitch/features/status/index.js21
-rw-r--r--app/javascript/flavours/glitch/styles/components/columns.scss4
6 files changed, 54 insertions, 20 deletions
diff --git a/app/javascript/flavours/glitch/components/column_header.js b/app/javascript/flavours/glitch/components/column_header.js
index cd977c4ca..bfad6467d 100644
--- a/app/javascript/flavours/glitch/components/column_header.js
+++ b/app/javascript/flavours/glitch/components/column_header.js
@@ -23,11 +23,12 @@ export default class ColumnHeader extends React.PureComponent {
 
   static propTypes = {
     intl: PropTypes.object.isRequired,
-    title: PropTypes.node.isRequired,
-    icon: PropTypes.string.isRequired,
+    title: PropTypes.node,
+    icon: PropTypes.string,
     active: PropTypes.bool,
     localSettings : ImmutablePropTypes.map,
     multiColumn: PropTypes.bool,
+    extraButton: PropTypes.node,
     showBackButton: PropTypes.bool,
     notifCleaning: PropTypes.bool, // true only for the notification column
     notifCleaningActive: PropTypes.bool,
@@ -86,7 +87,7 @@ export default class ColumnHeader extends React.PureComponent {
   }
 
   render () {
-    const { intl, icon, active, children, pinned, onPin, multiColumn, showBackButton, intl: { formatMessage }, notifCleaning, notifCleaningActive } = this.props;
+    const { intl, icon, active, children, pinned, onPin, multiColumn, extraButton, showBackButton, intl: { formatMessage }, notifCleaning, notifCleaningActive } = this.props;
     const { collapsed, animating, animatingNCD } = this.state;
 
     let title = this.props.title;
@@ -162,18 +163,26 @@ export default class ColumnHeader extends React.PureComponent {
     }
 
     if (children || multiColumn) {
-      collapseButton = <button className={collapsibleButtonClassName} aria-label={formatMessage(collapsed ? messages.show : messages.hide)} aria-pressed={collapsed ? 'false' : 'true'} onClick={this.handleToggleClick}><i className='fa fa-sliders' /></button>;
+      collapseButton = <button className={collapsibleButtonClassName} title={formatMessage(collapsed ? messages.show : messages.hide)} aria-label={formatMessage(collapsed ? messages.show : messages.hide)} aria-pressed={collapsed ? 'false' : 'true'} onClick={this.handleToggleClick}><i className='fa fa-sliders' /></button>;
     }
 
+    const hasTitle = icon && title;
+
     return (
       <div className={wrapperClassName}>
         <h1 className={buttonClassName}>
-          <button onClick={this.handleTitleClick}>
-            <i className={`fa fa-fw fa-${icon} column-header__icon`} />
-            {title}
-          </button>
+          {hasTitle && (
+            <button onClick={this.handleTitleClick}>
+              <i className={`fa fa-fw fa-${icon} column-header__icon`} />
+              {title}
+            </button>
+          )}
+
+          {!hasTitle && backButton}
+
           <div className='column-header__buttons'>
-            {backButton}
+            {hasTitle && backButton}
+            {extraButton}
             { notifCleaning ? (
               <button
                 aria-label={msgEnterNotifCleaning}
diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js
index 2c011bb2a..0ea959895 100644
--- a/app/javascript/flavours/glitch/components/status.js
+++ b/app/javascript/flavours/glitch/components/status.js
@@ -47,10 +47,11 @@ export default class Status extends ImmutablePureComponent {
     onMoveDown: PropTypes.func,
     getScrollPosition: PropTypes.func,
     updateScrollBottom: PropTypes.func,
+    expanded: PropTypes.bool,
   };
 
   state = {
-    isExpanded: false,
+    isExpanded: this.props.expanded,
     isCollapsed: false,
     autoCollapsed: false,
   }
@@ -92,6 +93,9 @@ export default class Status extends ImmutablePureComponent {
       nextProps.collapse !== this.props.collapse &&
       nextProps.collapse !== undefined
     ) this.setCollapsed(nextProps.collapse);
+    if (nextProps.expanded !== this.props.expanded &&
+      nextProps.expanded !== undefined
+    ) this.setExpansion(nextProps.expanded);
   }
 
   //  When mounting, we just check to see if our status should be collapsed,
@@ -465,7 +469,7 @@ export default class Status extends ImmutablePureComponent {
             media={media}
             mediaIcon={mediaIcon}
             expanded={isExpanded}
-            setExpansion={setExpansion}
+            onExpandedToggle={this.handleExpandedToggle}
             parseClick={parseClick}
             disabled={!router}
           />
diff --git a/app/javascript/flavours/glitch/components/status_content.js b/app/javascript/flavours/glitch/components/status_content.js
index 26d5b7c0f..32b0770cb 100644
--- a/app/javascript/flavours/glitch/components/status_content.js
+++ b/app/javascript/flavours/glitch/components/status_content.js
@@ -12,7 +12,7 @@ export default class StatusContent extends React.PureComponent {
     status: ImmutablePropTypes.map.isRequired,
     expanded: PropTypes.bool,
     collapsed: PropTypes.bool,
-    setExpansion: PropTypes.func,
+    onExpandedToggle: PropTypes.func,
     media: PropTypes.element,
     mediaIcon: PropTypes.string,
     parseClick: PropTypes.func,
@@ -112,8 +112,8 @@ export default class StatusContent extends React.PureComponent {
   handleSpoilerClick = (e) => {
     e.preventDefault();
 
-    if (this.props.setExpansion) {
-      this.props.setExpansion(!this.props.expanded);
+    if (this.props.onExpandedToggle) {
+      this.props.onExpandedToggle();
     } else {
       this.setState({ hidden: !this.state.hidden });
     }
@@ -132,7 +132,7 @@ export default class StatusContent extends React.PureComponent {
       disabled,
     } = this.props;
 
-    const hidden = this.props.setExpansion ? !this.props.expanded : this.state.hidden;
+    const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
 
     const content = { __html: status.get('contentHtml') };
     const spoilerContent = { __html: status.get('spoilerHtml') };
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 dddfd36b0..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;
@@ -115,7 +117,7 @@ export default class DetailedStatus extends ImmutablePureComponent {
           mediaIcon={mediaIcon}
           expanded={expanded}
           collapsed={false}
-          setExpansion={setExpansion}
+          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 a1783d94a..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 = () => {
@@ -77,6 +80,7 @@ export default class Status extends ImmutablePureComponent {
   state = {
     fullscreen: false,
     isExpanded: false,
+    threadExpanded: null,
   };
 
   componentWillMount () {
@@ -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}
       />
@@ -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/styles/components/columns.scss b/app/javascript/flavours/glitch/styles/components/columns.scss
index 933aea919..34175685e 100644
--- a/app/javascript/flavours/glitch/styles/components/columns.scss
+++ b/app/javascript/flavours/glitch/styles/components/columns.scss
@@ -265,6 +265,10 @@
     flex: 1;
   }
 
+  & > .column-header__back-button {
+    color: $ui-highlight-color;
+  }
+
   &.active {
     box-shadow: 0 1px 0 rgba($ui-highlight-color, 0.3);