Skip to content

Commit b5cf3ba

Browse files
committed
Revert "Change in-app links to keep you in-app (mastodon#20540)"
This reverts commit 0722908. Signed-off-by: lindwurm <lindwurm.q@gmail.com>
1 parent 91a88fe commit b5cf3ba

File tree

21 files changed

+94
-52
lines changed

21 files changed

+94
-52
lines changed

app/javascript/mastodon/components/account.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
33
import PropTypes from 'prop-types';
44
import Avatar from './avatar';
55
import DisplayName from './display_name';
6+
import Permalink from './permalink';
67
import IconButton from './icon_button';
78
import { defineMessages, injectIntl } from 'react-intl';
89
import ImmutablePureComponent from 'react-immutable-pure-component';
910
import { me } from '../initial_state';
1011
import RelativeTimestamp from './relative_timestamp';
1112
import Skeleton from 'mastodon/components/skeleton';
12-
import { Link } from 'react-router-dom';
1313

1414
const messages = defineMessages({
1515
follow: { id: 'account.follow', defaultMessage: 'Follow' },
@@ -140,11 +140,11 @@ class Account extends ImmutablePureComponent {
140140
return (
141141
<div className='account'>
142142
<div className='account__wrapper'>
143-
<Link key={account.get('id')} className='account__display-name' title={account.get('acct')} to={`/@${account.get('acct')}`}>
143+
<Permalink key={account.get('id')} className='account__display-name' title={account.get('acct')} href={account.get('url')} to={`/@${account.get('acct')}`}>
144144
<div className='account__avatar-wrapper'><Avatar account={account} size={size} /></div>
145145
{mute_expires_at}
146146
<DisplayName account={account} />
147-
</Link>
147+
</Permalink>
148148

149149
<div className='account__relationship'>
150150
{buttons}

app/javascript/mastodon/components/admin/Trends.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class Trends extends React.PureComponent {
5050
<Hashtag
5151
key={hashtag.name}
5252
name={hashtag.name}
53-
to={`/admin/tags/${hashtag.id}`}
53+
href={`/admin/tags/${hashtag.id}`}
5454
people={hashtag.history[0].accounts * 1 + hashtag.history[1].accounts * 1}
5555
uses={hashtag.history[0].uses * 1 + hashtag.history[1].uses * 1}
5656
history={hashtag.history.reverse().map(day => day.uses)}

app/javascript/mastodon/components/hashtag.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Sparklines, SparklinesCurve } from 'react-sparklines';
44
import { FormattedMessage } from 'react-intl';
55
import PropTypes from 'prop-types';
66
import ImmutablePropTypes from 'react-immutable-proptypes';
7-
import { Link } from 'react-router-dom';
7+
import Permalink from './permalink';
88
import ShortNumber from 'mastodon/components/short_number';
99
import Skeleton from 'mastodon/components/skeleton';
1010
import classNames from 'classnames';
@@ -53,6 +53,7 @@ export const accountsCountRenderer = (displayNumber, pluralReady) => (
5353
export const ImmutableHashtag = ({ hashtag }) => (
5454
<Hashtag
5555
name={hashtag.get('name')}
56+
href={hashtag.get('url')}
5657
to={`/tags/${hashtag.get('name')}`}
5758
people={hashtag.getIn(['history', 0, 'accounts']) * 1 + hashtag.getIn(['history', 1, 'accounts']) * 1}
5859
history={hashtag.get('history').reverse().map((day) => day.get('uses')).toArray()}
@@ -63,12 +64,12 @@ ImmutableHashtag.propTypes = {
6364
hashtag: ImmutablePropTypes.map.isRequired,
6465
};
6566

66-
const Hashtag = ({ name, to, people, uses, history, className, description, withGraph }) => (
67+
const Hashtag = ({ name, href, to, people, uses, history, className, description, withGraph }) => (
6768
<div className={classNames('trends__item', className)}>
6869
<div className='trends__item__name'>
69-
<Link to={to}>
70+
<Permalink href={href} to={to}>
7071
{name ? <React.Fragment>#<span>{name}</span></React.Fragment> : <Skeleton width={50} />}
71-
</Link>
72+
</Permalink>
7273

7374
{description ? (
7475
<span>{description}</span>
@@ -97,6 +98,7 @@ const Hashtag = ({ name, to, people, uses, history, className, description, with
9798

9899
Hashtag.propTypes = {
99100
name: PropTypes.string,
101+
href: PropTypes.string,
100102
to: PropTypes.string,
101103
people: PropTypes.number,
102104
description: PropTypes.node,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
export default class Permalink extends React.PureComponent {
5+
6+
static contextTypes = {
7+
router: PropTypes.object,
8+
};
9+
10+
static propTypes = {
11+
className: PropTypes.string,
12+
href: PropTypes.string.isRequired,
13+
to: PropTypes.string.isRequired,
14+
children: PropTypes.node,
15+
onInterceptClick: PropTypes.func,
16+
};
17+
18+
handleClick = e => {
19+
if (this.props.onInterceptClick && this.props.onInterceptClick()) {
20+
e.preventDefault();
21+
return;
22+
}
23+
24+
if (this.context.router && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
25+
e.preventDefault();
26+
this.context.router.history.push(this.props.to);
27+
}
28+
}
29+
30+
render () {
31+
const { href, children, className, onInterceptClick, ...other } = this.props;
32+
33+
return (
34+
<a target='_blank' href={href} onClick={this.handleClick} {...other} className={`permalink${className ? ' ' + className : ''}`}>
35+
{children}
36+
</a>
37+
);
38+
}
39+
40+
}

app/javascript/mastodon/components/status.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ class Status extends ImmutablePureComponent {
378378
prepend = (
379379
<div className='status__prepend'>
380380
<div className='status__prepend-icon-wrapper'><Icon id='retweet' className='status__prepend-icon' fixedWidth /></div>
381-
<FormattedMessage id='status.reblogged_by' defaultMessage='{name} boosted' values={{ name: <a onClick={this.handlePrependAccountClick} data-id={status.getIn(['account', 'id'])} href={`/@${status.getIn(['account', 'acct'])}`} className='status__display-name muted'><bdi><strong dangerouslySetInnerHTML={display_name_html} /></bdi></a> }} />
381+
<FormattedMessage id='status.reblogged_by' defaultMessage='{name} boosted' values={{ name: <a onClick={this.handlePrependAccountClick} data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} className='status__display-name muted'><bdi><strong dangerouslySetInnerHTML={display_name_html} /></bdi></a> }} />
382382
</div>
383383
);
384384

@@ -392,7 +392,7 @@ class Status extends ImmutablePureComponent {
392392
prepend = (
393393
<div className='status__prepend'>
394394
<div className='status__prepend-icon-wrapper'><Icon id='reply' className='status__prepend-icon' fixedWidth /></div>
395-
<FormattedMessage id='status.replied_to' defaultMessage='Replied to {name}' values={{ name: <a onClick={this.handlePrependAccountClick} data-id={status.getIn(['account', 'id'])} href={`/@${status.getIn(['account', 'acct'])}`} className='status__display-name muted'><bdi><strong dangerouslySetInnerHTML={display_name_html} /></bdi></a> }} />
395+
<FormattedMessage id='status.replied_to' defaultMessage='Replied to {name}' values={{ name: <a onClick={this.handlePrependAccountClick} data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} className='status__display-name muted'><bdi><strong dangerouslySetInnerHTML={display_name_html} /></bdi></a> }} />
396396
</div>
397397
);
398398
}
@@ -511,12 +511,12 @@ class Status extends ImmutablePureComponent {
511511

512512
<div className={classNames('status', `status-${status.get('visibility')}`, { 'status-reply': !!status.get('in_reply_to_id'), muted: this.props.muted })} data-id={status.get('id')}>
513513
<div className='status__info'>
514-
<a onClick={this.handleClick} href={`/@${status.getIn(['account', 'acct'])}\/${status.get('id')}`} className='status__relative-time' target='_blank' rel='noopener noreferrer'>
514+
<a onClick={this.handleClick} href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener noreferrer'>
515515
<span className='status__visibility-icon'><Icon id={visibilityIcon.icon} title={visibilityIcon.text} /></span>
516516
<RelativeTimestamp timestamp={status.get('created_at')} />{status.get('edited_at') && <abbr title={intl.formatMessage(messages.edited, { date: intl.formatDate(status.get('edited_at'), { hour12: false, year: 'numeric', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }) })}> *</abbr>}
517517
</a>
518518

519-
<a onClick={this.handleAccountClick} href={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='status__display-name' target='_blank' rel='noopener noreferrer'>
519+
<a onClick={this.handleAccountClick} href={status.getIn(['account', 'url'])} title={status.getIn(['account', 'acct'])} className='status__display-name' target='_blank' rel='noopener noreferrer'>
520520
<div className='status__avatar'>
521521
{statusAvatar}
522522
</div>

app/javascript/mastodon/components/status_content.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import ImmutablePropTypes from 'react-immutable-proptypes';
33
import PropTypes from 'prop-types';
44
import { FormattedMessage, injectIntl } from 'react-intl';
5-
import { Link } from 'react-router-dom';
5+
import Permalink from './permalink';
66
import classnames from 'classnames';
77
import PollContainer from 'mastodon/containers/poll_container';
88
import Icon from 'mastodon/components/icon';
@@ -96,10 +96,8 @@ class StatusContent extends React.PureComponent {
9696
if (mention) {
9797
link.addEventListener('click', this.onMentionClick.bind(this, mention), false);
9898
link.setAttribute('title', mention.get('acct'));
99-
link.setAttribute('href', `/@${mention.get('acct')}`);
10099
} else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
101100
link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
102-
link.setAttribute('href', `/tags/${link.text.slice(1)}`);
103101
} else {
104102
link.setAttribute('title', link.href);
105103
link.classList.add('unhandled-link');
@@ -249,9 +247,9 @@ class StatusContent extends React.PureComponent {
249247
let mentionsPlaceholder = '';
250248

251249
const mentionLinks = status.get('mentions').map(item => (
252-
<Link to={`/@${item.get('acct')}`} key={item.get('id')} className='status-link mention'>
250+
<Permalink to={`/@${item.get('acct')}`} href={item.get('url')} key={item.get('id')} className='status-link mention'>
253251
@<span>{item.get('username')}</span>
254-
</Link>
252+
</Permalink>
255253
)).reduce((aggregate, item) => [...aggregate, item, ' '], []);
256254

257255
const toggleText = hidden ? <FormattedMessage id='status.show_more' defaultMessage='Show more' /> : <FormattedMessage id='status.show_less' defaultMessage='Show less' />;

app/javascript/mastodon/features/account/components/featured_tags.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class FeaturedTags extends ImmutablePureComponent {
3939
<Hashtag
4040
key={featuredTag.get('name')}
4141
name={featuredTag.get('name')}
42+
href={featuredTag.get('url')}
4243
to={`/@${account.get('acct')}/tagged/${featuredTag.get('name')}`}
4344
uses={featuredTag.get('statuses_count') * 1}
4445
withGraph={false}

app/javascript/mastodon/features/account_gallery/components/media_item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export default class MediaItem extends ImmutablePureComponent {
129129

130130
return (
131131
<div className='account-gallery__item' style={{ width, height }}>
132-
<a className='media-gallery__item-thumbnail' href={`/@${status.getIn(['account', 'acct'])}\/${status.get('id')}`} onClick={this.handleClick} title={title} target='_blank' rel='noopener noreferrer'>
132+
<a className='media-gallery__item-thumbnail' href={status.get('url')} onClick={this.handleClick} title={title} target='_blank' rel='noopener noreferrer'>
133133
<Blurhash
134134
hash={attachment.get('blurhash')}
135135
className={classNames('media-gallery__preview', { 'media-gallery__preview--hidden': visible && loaded })}

app/javascript/mastodon/features/account_timeline/components/moved_note.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl';
44
import ImmutablePureComponent from 'react-immutable-pure-component';
55
import AvatarOverlay from '../../../components/avatar_overlay';
66
import DisplayName from '../../../components/display_name';
7-
import { Link } from 'react-router-dom';
7+
import Permalink from 'mastodon/components/permalink';
88

99
export default class MovedNote extends ImmutablePureComponent {
1010

@@ -23,12 +23,12 @@ export default class MovedNote extends ImmutablePureComponent {
2323
</div>
2424

2525
<div className='moved-account-banner__action'>
26-
<Link to={`/@${to.get('acct')}`} className='detailed-status__display-name'>
26+
<Permalink href={to.get('url')} to={`/@${to.get('acct')}`} className='detailed-status__display-name'>
2727
<div className='detailed-status__display-avatar'><AvatarOverlay account={to} friend={from} /></div>
2828
<DisplayName account={to} />
29-
</Link>
29+
</Permalink>
3030

31-
<Link to={`/@${to.get('acct')}`} className='button'><FormattedMessage id='account.go_to_profile' defaultMessage='Go to profile' /></Link>
31+
<Permalink href={to.get('url')} to={`/@${to.get('acct')}`} className='button'><FormattedMessage id='account.go_to_profile' defaultMessage='Go to profile' /></Permalink>
3232
</div>
3333
</div>
3434
);

app/javascript/mastodon/features/compose/components/navigation_bar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import ImmutablePropTypes from 'react-immutable-proptypes';
44
import ActionBar from './action_bar';
55
import Avatar from '../../../components/avatar';
6-
import { Link } from 'react-router-dom';
6+
import Permalink from '../../../components/permalink';
77
import IconButton from '../../../components/icon_button';
88
import { FormattedMessage } from 'react-intl';
99
import ImmutablePureComponent from 'react-immutable-pure-component';
@@ -19,15 +19,15 @@ export default class NavigationBar extends ImmutablePureComponent {
1919
render () {
2020
return (
2121
<div className='navigation-bar'>
22-
<Link to={`/@${this.props.account.get('acct')}`}>
22+
<Permalink href={this.props.account.get('url')} to={`/@${this.props.account.get('acct')}`}>
2323
<span style={{ display: 'none' }}>{this.props.account.get('acct')}</span>
2424
<Avatar account={this.props.account} size={46} />
25-
</Link>
25+
</Permalink>
2626

2727
<div className='navigation-bar__profile'>
28-
<Link to={`/@${this.props.account.get('acct')}`}>
28+
<Permalink href={this.props.account.get('url')} to={`/@${this.props.account.get('acct')}`}>
2929
<strong className='navigation-bar__profile-account'>@{this.props.account.get('acct')}</strong>
30-
</Link>
30+
</Permalink>
3131

3232
<a href='/settings/profile' className='navigation-bar__profile-edit'><FormattedMessage id='navigation_bar.edit_profile' defaultMessage='Edit profile' /></a>
3333
</div>

0 commit comments

Comments
 (0)