diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js index e99ad9fdb..8f6345508 100644 --- a/app/soapbox/actions/auth.js +++ b/app/soapbox/actions/auth.js @@ -190,8 +190,8 @@ export function logOut() { }; } -export function switchAccount(accountId) { - return { type: SWITCH_ACCOUNT, accountId }; +export function switchAccount(accountId, reload = true) { + return { type: SWITCH_ACCOUNT, accountId, reload }; } export function fetchOwnAccounts() { diff --git a/app/soapbox/components/dropdown_menu.js b/app/soapbox/components/dropdown_menu.js index abaea33fe..2f2412928 100644 --- a/app/soapbox/components/dropdown_menu.js +++ b/app/soapbox/components/dropdown_menu.js @@ -117,21 +117,40 @@ class DropdownMenu extends React.PureComponent { } } + handleMiddleClick = e => { + const i = Number(e.currentTarget.getAttribute('data-index')); + const { middleClick } = this.props.items[i]; + + this.props.onClose(); + + if (e.button === 1 && typeof middleClick === 'function') { + e.preventDefault(); + middleClick(e); + } + } + + handleAuxClick = e => { + if (e.button === 1) { + this.handleMiddleClick(e); + } + } + renderItem(option, i) { if (option === null) { return
  • ; } - const { text, href = '#', newTab, isLogout } = option; + const { text, href, to, newTab, isLogout } = option; return (
  • { + return e => { + this.props.dispatch(switchAccount(account.get('id'), false)); + window.open('/', '_blank', 'noopener,noreferrer'); + e.preventDefault(); + }; + } + fetchOwnAccounts = throttle(() => { this.props.dispatch(fetchOwnAccounts()); }, 2000); @@ -80,7 +88,7 @@ class ProfileDropdown extends React.PureComponent { return (
    -
    +
    @@ -98,7 +106,7 @@ class ProfileDropdown extends React.PureComponent { menu.push({ text: this.renderAccount(account), to: `/@${account.get('acct')}` }); otherAccounts.forEach(account => { - menu.push({ text: this.renderAccount(account), action: this.handleSwitchAccount(account) }); + menu.push({ text: this.renderAccount(account), action: this.handleSwitchAccount(account), href: '/', middleClick: this.handleMiddleClick(account) }); }); menu.push(null); diff --git a/app/soapbox/reducers/auth.js b/app/soapbox/reducers/auth.js index 51b1be464..96a22fbc8 100644 --- a/app/soapbox/reducers/auth.js +++ b/app/soapbox/reducers/auth.js @@ -54,9 +54,12 @@ const migrateLegacy = state => { }); }; +const persistAuth = state => localStorage.setItem('soapbox:auth', JSON.stringify(state.toJS())); +const persistSession = state => sessionStorage.setItem('soapbox:auth:me', state.get('me')); + const persistState = state => { - localStorage.setItem('soapbox:auth', JSON.stringify(state.toJS())); - sessionStorage.setItem('soapbox:auth:me', state.get('me')); + persistAuth(state); + persistSession(state); }; const initialize = state => { @@ -151,6 +154,7 @@ const userSwitched = (oldState, state) => { }; const maybeReload = (oldState, state, action) => { + if (action.reload === false) return; if (userSwitched(oldState, state)) { reload(state); } @@ -159,9 +163,14 @@ const maybeReload = (oldState, state, action) => { export default function auth(oldState = initialState, action) { const state = reducer(oldState, action); - // Persist the state in localStorage if (!state.equals(oldState)) { - persistState(state); + // Persist the state in localStorage + persistAuth(state); + + // Persist the session + if (action.reload !== false) { + persistSession(state); + } // Reload the page under some conditions maybeReload(oldState, state, action);