From b3ff35a75cf04e4aba2712a9d0897257cf79af82 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 25 Sep 2018 14:46:14 +0200 Subject: [PATCH] Move URLs to backend in their own file --- .../glitch/components/status_action_bar.js | 17 ++++++++++--- .../features/account/components/action_bar.js | 12 ++++++--- .../features/composer/direct_warning/index.js | 4 ++- .../glitch/features/composer/warning/index.js | 7 +++++- .../glitch/features/drawer/account/index.js | 25 +++++++++++-------- .../glitch/features/drawer/header/index.js | 3 ++- .../glitch/features/getting_started/index.js | 5 ++-- .../local_settings/navigation/index.js | 3 ++- .../features/status/components/action_bar.js | 17 ++++++++++--- .../flavours/glitch/util/backend_links.js | 6 +++++ 10 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 app/javascript/flavours/glitch/util/backend_links.js diff --git a/app/javascript/flavours/glitch/components/status_action_bar.js b/app/javascript/flavours/glitch/components/status_action_bar.js index f7e741d2d..16abcab4e 100644 --- a/app/javascript/flavours/glitch/components/status_action_bar.js +++ b/app/javascript/flavours/glitch/components/status_action_bar.js @@ -7,6 +7,7 @@ import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { me, isStaff } from 'flavours/glitch/util/initial_state'; import RelativeTimestamp from './relative_timestamp'; +import { accountAdminLink, statusAdminLink } from 'flavours/glitch/util/backend_links'; const messages = defineMessages({ delete: { id: 'status.delete', defaultMessage: 'Delete' }, @@ -188,10 +189,20 @@ export default class StatusActionBar extends ImmutablePureComponent { menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick }); menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick }); menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport }); - if (isStaff) { + if (isStaff && (accountAdminLink || statusAdminLink)) { menu.push(null); - menu.push({ text: intl.formatMessage(messages.admin_account, { name: status.getIn(['account', 'username']) }), href: `/admin/accounts/${status.getIn(['account', 'id'])}` }); - menu.push({ text: intl.formatMessage(messages.admin_status), href: `/admin/accounts/${status.getIn(['account', 'id'])}/statuses/${status.get('id')}` }); + if (accountAdminLink !== undefined) { + menu.push({ + text: intl.formatMessage(messages.admin_account, { name: status.getIn(['account', 'username']) }), + href: accountAdminLink(status.getIn(['account', 'id'])), + }); + } + if (statusAdminLink !== undefined) { + menu.push({ + text: intl.formatMessage(messages.admin_status), + href: statusAdminLink(status.getIn(['account', 'id']), status.get('id')), + }); + } } } diff --git a/app/javascript/flavours/glitch/features/account/components/action_bar.js b/app/javascript/flavours/glitch/features/account/components/action_bar.js index acbe46f8a..ffa5b7e5e 100644 --- a/app/javascript/flavours/glitch/features/account/components/action_bar.js +++ b/app/javascript/flavours/glitch/features/account/components/action_bar.js @@ -5,6 +5,7 @@ import DropdownMenuContainer from 'flavours/glitch/containers/dropdown_menu_cont import { NavLink } from 'react-router-dom'; import { defineMessages, injectIntl, FormattedMessage, FormattedNumber } from 'react-intl'; import { me, isStaff } from 'flavours/glitch/util/initial_state'; +import { profileLink, accountAdminLink } from 'flavours/glitch/util/backend_links'; const messages = defineMessages({ mention: { id: 'account.mention', defaultMessage: 'Mention @{name}' }, @@ -77,7 +78,9 @@ export default class ActionBar extends React.PureComponent { menu.push(null); if (account.get('id') === me) { - menu.push({ text: intl.formatMessage(messages.edit_profile), href: '/settings/profile' }); + if (profileLink !== undefined) { + menu.push({ text: intl.formatMessage(messages.edit_profile), href: profileLink }); + } } else { if (account.getIn(['relationship', 'following'])) { if (account.getIn(['relationship', 'showing_reblogs'])) { @@ -131,9 +134,12 @@ export default class ActionBar extends React.PureComponent { } } - if (account.get('id') !== me && isStaff) { + if (account.get('id') !== me && isStaff && (accountAdminLink !== undefined)) { menu.push(null); - menu.push({ text: intl.formatMessage(messages.admin_account, { name: account.get('username') }), href: `/admin/accounts/${account.get('id')}` }); + menu.push({ + text: intl.formatMessage(messages.admin_account, { name: account.get('username') }), + href: accountAdminLink(account.get('id')), + }); } return ( diff --git a/app/javascript/flavours/glitch/features/composer/direct_warning/index.js b/app/javascript/flavours/glitch/features/composer/direct_warning/index.js index d1febdd1b..3b1369acd 100644 --- a/app/javascript/flavours/glitch/features/composer/direct_warning/index.js +++ b/app/javascript/flavours/glitch/features/composer/direct_warning/index.js @@ -2,6 +2,7 @@ import React from 'react'; import Motion from 'flavours/glitch/util/optional_motion'; import spring from 'react-motion/lib/spring'; import { defineMessages, FormattedMessage } from 'react-intl'; +import { termsLink} from 'flavours/glitch/util/backend_links'; // This is the spring used with our motion. const motionSpring = spring(1, { damping: 35, stiffness: 400 }); @@ -42,7 +43,8 @@ export default function ComposerDirectWarning () { }} > - + + { termsLink !== undefined && } )} diff --git a/app/javascript/flavours/glitch/features/composer/warning/index.js b/app/javascript/flavours/glitch/features/composer/warning/index.js index c225b50e8..8be8acbce 100644 --- a/app/javascript/flavours/glitch/features/composer/warning/index.js +++ b/app/javascript/flavours/glitch/features/composer/warning/index.js @@ -2,6 +2,7 @@ import React from 'react'; import Motion from 'flavours/glitch/util/optional_motion'; import spring from 'react-motion/lib/spring'; import { defineMessages, FormattedMessage } from 'react-intl'; +import { profileLink } from 'flavours/glitch/util/backend_links'; // This is the spring used with our motion. const motionSpring = spring(1, { damping: 35, stiffness: 400 }); @@ -20,6 +21,10 @@ const messages = defineMessages({ // The component. export default function ComposerWarning () { + let lockedLink = ; + if (profileLink !== undefined) { + lockedLink = {lockedLink}; + } return ( }} + values={{ locked: lockedLink }} /> )} diff --git a/app/javascript/flavours/glitch/features/drawer/account/index.js b/app/javascript/flavours/glitch/features/drawer/account/index.js index 168d0c2cf..552848641 100644 --- a/app/javascript/flavours/glitch/features/drawer/account/index.js +++ b/app/javascript/flavours/glitch/features/drawer/account/index.js @@ -12,6 +12,7 @@ import Permalink from 'flavours/glitch/components/permalink'; // Utils. import { hiddenComponent } from 'flavours/glitch/util/react_helpers'; +import { profileLink } from 'flavours/glitch/util/backend_links'; // Messages. const messages = defineMessages({ @@ -28,12 +29,14 @@ export default function DrawerAccount ({ account }) { if (!account) { return (
- - - + { profileLink !== undefined && ( + + + + )}
); } @@ -59,10 +62,12 @@ export default function DrawerAccount ({ account }) { > @{account.get('acct')} - + { profileLink !== undefined && ( + + )} ); } diff --git a/app/javascript/flavours/glitch/features/drawer/header/index.js b/app/javascript/flavours/glitch/features/drawer/header/index.js index 7fefd32c9..da5599732 100644 --- a/app/javascript/flavours/glitch/features/drawer/header/index.js +++ b/app/javascript/flavours/glitch/features/drawer/header/index.js @@ -10,6 +10,7 @@ import Icon from 'flavours/glitch/components/icon'; // Utils. import { conditionalRender } from 'flavours/glitch/util/react_helpers'; +import { signOutLink } from 'flavours/glitch/util/backend_links'; // Messages. const messages = defineMessages({ @@ -109,7 +110,7 @@ export default function DrawerHeader ({ diff --git a/app/javascript/flavours/glitch/features/getting_started/index.js b/app/javascript/flavours/glitch/features/getting_started/index.js index ce1ae50e4..c87f76c5e 100644 --- a/app/javascript/flavours/glitch/features/getting_started/index.js +++ b/app/javascript/flavours/glitch/features/getting_started/index.js @@ -13,6 +13,7 @@ import { fetchFollowRequests } from 'flavours/glitch/actions/accounts'; import { List as ImmutableList } from 'immutable'; import { createSelector } from 'reselect'; import { fetchLists } from 'flavours/glitch/actions/lists'; +import { preferencesLink, profileLink, signOutLink } from 'flavours/glitch/util/backend_links'; const messages = defineMessages({ heading: { id: 'getting_started.heading', defaultMessage: 'Getting started' }, @@ -157,9 +158,9 @@ export default class GettingStarted extends ImmutablePureComponent { {listItems} - + { preferencesLink !== undefined && } - +
diff --git a/app/javascript/flavours/glitch/features/local_settings/navigation/index.js b/app/javascript/flavours/glitch/features/local_settings/navigation/index.js index cf02101cf..ce10e3f51 100644 --- a/app/javascript/flavours/glitch/features/local_settings/navigation/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/navigation/index.js @@ -5,6 +5,7 @@ import { injectIntl, defineMessages } from 'react-intl'; // Our imports import LocalSettingsNavigationItem from './item'; +import { preferencesLink } from 'flavours/glitch/util/backend_links'; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -71,7 +72,7 @@ export default class LocalSettingsNavigation extends React.PureComponent { /> `/admin/accounts/${id}`; +export const statusAdminLink = (account_id, status_id) => `/admin/accounts/${account_id}/statuses/${status_id}`;