Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand number of lines in collapsed posts #4

Merged
merged 1 commit into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/javascript/flavours/glitch/components/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import StatusHeader from './status_header';
import StatusIcons from './status_icons';
import StatusContent from './status_content';
import StatusActionBar from './status_action_bar';
import StatusExpandButton from './status_expand_button';
import AttachmentList from './attachment_list';
import Card from '../features/status/components/card';
import { injectIntl, FormattedMessage } from 'react-intl';
Expand Down Expand Up @@ -793,6 +794,14 @@ class Status extends ImmutablePureComponent {
tagLinks={settings.get('tag_misleading_links')}
rewriteMentions={settings.get('rewrite_mentions')}
/>
{/* Only show expand button if collapsed and no spoiler tag is present */}
{isCollapsed && status.get('spoiler_text').length===0 ? (
<StatusExpandButton
hidden={isCollapsed}
handleSpoilerClick={parseClick}
mediaIcons={contentMediaIcons}
/>
) : null}

{!isCollapsed || !(muted || !settings.getIn(['collapsed', 'show_action_bar'])) ? (
<StatusActionBar
Expand Down
41 changes: 6 additions & 35 deletions app/javascript/flavours/glitch/components/status_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import classnames from 'classnames';
import Icon from 'flavours/glitch/components/icon';
import { autoPlayGif } from 'flavours/glitch/initial_state';
import { decode as decodeIDNA } from 'flavours/glitch/utils/idna';
import StatusExpandButton from './status_expand_button';

const textMatchesTarget = (text, origin, host) => {
return (text === origin || text === host
Expand Down Expand Up @@ -289,38 +290,6 @@ export default class StatusContent extends React.PureComponent {
</Permalink>
)).reduce((aggregate, item) => [...aggregate, item, ' '], []);

let toggleText = null;
if (hidden) {
toggleText = [
<FormattedMessage
id='status.show_more'
defaultMessage='Show more'
key='0'
/>,
];
if (mediaIcons) {
mediaIcons.forEach((mediaIcon, idx) => {
toggleText.push(
<Icon
fixedWidth
className='status__content__spoiler-icon'
id={mediaIcon}
aria-hidden='true'
key={`icon-${idx}`}
/>,
);
});
}
} else {
toggleText = (
<FormattedMessage
id='status.show_less'
defaultMessage='Show less'
key='0'
/>
);
}

if (hidden) {
mentionsPlaceholder = <div>{mentionLinks}</div>;
}
Expand All @@ -332,9 +301,11 @@ export default class StatusContent extends React.PureComponent {
>
<span dangerouslySetInnerHTML={spoilerContent} className='translate' lang={lang} />
{' '}
<button type='button' className='status__content__spoiler-link' onClick={this.handleSpoilerClick} aria-expanded={!hidden}>
{toggleText}
</button>
<StatusExpandButton
hidden={hidden}
handleSpoilerClick={this.handleSpoilerClick}
mediaIcons={mediaIcons}
/>
</p>

{mentionsPlaceholder}
Expand Down
71 changes: 71 additions & 0 deletions app/javascript/flavours/glitch/components/status_expand_button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import Icon from './icon';


const StatusExpandButton=(
{
hidden,
handleSpoilerClick,
mediaIcons,
},
)=>{
const makeToggleText = () => {
let newText;
if (hidden) {
newText = [
<FormattedMessage
id='status.show_more'
defaultMessage='Show more'
key='0'
/>,
];
if (mediaIcons) {
mediaIcons.forEach((mediaIcon, idx) => {
newText.push(
<Icon
fixedWidth
className='status__content__spoiler-icon'
id={mediaIcon}
aria-hidden='true'
key={`icon-${idx}`}
/>,
);
});
}
} else {
newText = (
<FormattedMessage
id='status.show_less'
defaultMessage='Show less'
key='0'
/>
);
}
return(newText);
};

// const [hidden, setHidden] = useState(false);
const [toggleText, setToggleText] = useState(makeToggleText());

// Change the text when the hidden state changes
useEffect(() => {
setToggleText(makeToggleText());
}, [hidden]);

return(
<button type='button' className='status__content__spoiler-link' onClick={handleSpoilerClick} aria-expanded={!hidden}>
{toggleText}
</button>
);
};

StatusExpandButton.propTypes = {
hidden: PropTypes.bool,
handleSpoilerClick: PropTypes.func,
mediaIcons: PropTypes.arrayOf(PropTypes.string),
};

export default StatusExpandButton;
8 changes: 4 additions & 4 deletions app/javascript/flavours/glitch/styles/components/status.scss
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,22 @@
}

.status__content {
height: 20px;
max-height: 6em;
overflow: hidden;
text-overflow: ellipsis;
padding-top: 0;
//padding-top: 0;

&:after {
content: "";
position: absolute;
top: 0;
height: 40%;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(rgba($ui-base-color, 0), rgba($ui-base-color, 1));
pointer-events: none;
}

a:hover {
text-decoration: none;
}
Expand Down