Middle-click account to open it in a new tab, fixes #603

bundle-emoji
Alex Gleason 2021-03-29 23:22:54 -05:00
rodzic 870e94643f
commit db201707bf
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
4 zmienionych plików z 45 dodań i 9 usunięć

Wyświetl plik

@ -190,8 +190,8 @@ export function logOut() {
}; };
} }
export function switchAccount(accountId) { export function switchAccount(accountId, reload = true) {
return { type: SWITCH_ACCOUNT, accountId }; return { type: SWITCH_ACCOUNT, accountId, reload };
} }
export function fetchOwnAccounts() { export function fetchOwnAccounts() {

Wyświetl plik

@ -117,6 +117,24 @@ 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) { renderItem(option, i) {
if (option === null) { if (option === null) {
return <li key={`sep-${i}`} className='dropdown-menu__separator' />; return <li key={`sep-${i}`} className='dropdown-menu__separator' />;
@ -132,6 +150,7 @@ class DropdownMenu extends React.PureComponent {
tabIndex='0' tabIndex='0'
ref={i === 0 ? this.setFocusRef : null} ref={i === 0 ? this.setFocusRef : null}
onClick={this.handleClick} onClick={this.handleClick}
onAuxClick={this.handleAuxClick}
onKeyDown={this.handleItemKeyDown} onKeyDown={this.handleItemKeyDown}
data-index={i} data-index={i}
target={newTab ? '_blank' : null} target={newTab ? '_blank' : null}

Wyświetl plik

@ -64,6 +64,14 @@ class ProfileDropdown extends React.PureComponent {
}; };
} }
handleMiddleClick = account => {
return e => {
this.props.dispatch(switchAccount(account.get('id'), false));
window.open('/', '_blank', 'noopener,noreferrer');
e.preventDefault();
};
}
fetchOwnAccounts = throttle(() => { fetchOwnAccounts = throttle(() => {
this.props.dispatch(fetchOwnAccounts()); this.props.dispatch(fetchOwnAccounts());
}, 2000); }, 2000);
@ -80,7 +88,7 @@ class ProfileDropdown extends React.PureComponent {
return ( return (
<div className='account'> <div className='account'>
<div className='account__wrapper'> <div className='account__wrapper'>
<div className='account__display-name' title={account.get('acct')} href={`/@${account.get('acct')}`} to={`/@${account.get('acct')}`}> <div className='account__display-name'>
<div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div> <div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
<DisplayName account={account} /> <DisplayName account={account} />
</div> </div>
@ -95,10 +103,10 @@ class ProfileDropdown extends React.PureComponent {
let menu = []; let menu = [];
menu.push({ text: this.renderAccount(account), to: `/@${account.get('acct')}` }); menu.push({ text: this.renderAccount(account), to: `/@${account.get('acct')}`, href: '/', middleClick: this.handleMiddleClick(account) });
otherAccounts.forEach(account => { 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); menu.push(null);

Wyświetl plik

@ -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 => { const persistState = state => {
localStorage.setItem('soapbox:auth', JSON.stringify(state.toJS())); persistAuth(state);
sessionStorage.setItem('soapbox:auth:me', state.get('me')); persistSession(state);
}; };
const initialize = state => { const initialize = state => {
@ -151,6 +154,7 @@ const userSwitched = (oldState, state) => {
}; };
const maybeReload = (oldState, state, action) => { const maybeReload = (oldState, state, action) => {
if (action.reload === false) return;
if (userSwitched(oldState, state)) { if (userSwitched(oldState, state)) {
reload(state); reload(state);
} }
@ -159,9 +163,14 @@ const maybeReload = (oldState, state, action) => {
export default function auth(oldState = initialState, action) { export default function auth(oldState = initialState, action) {
const state = reducer(oldState, action); const state = reducer(oldState, action);
// Persist the state in localStorage
if (!state.equals(oldState)) { 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 // Reload the page under some conditions
maybeReload(oldState, state, action); maybeReload(oldState, state, action);