mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-22 17:25:40 +03:00
Nav Menu show avatar if multiple accounts
Accounts sheet default to 'switch' when click on account
This commit is contained in:
parent
5be6481196
commit
e6da22a1e0
3 changed files with 89 additions and 26 deletions
25
src/app.css
25
src/app.css
|
@ -1433,6 +1433,31 @@ ul.link-list li a .icon {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NAV MENU BUTTON */
|
||||||
|
|
||||||
|
.nav-menu-button.with-avatar {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.nav-menu-button:is(:hover, :focus):not(:active) {
|
||||||
|
filter: none !important;
|
||||||
|
}
|
||||||
|
.nav-menu-button .avatar {
|
||||||
|
transition: box-shadow 0.3s ease-out;
|
||||||
|
}
|
||||||
|
.nav-menu-button:is(:hover, :focus, .active) .avatar {
|
||||||
|
box-shadow: 0 0 0 2px var(--bg-color), 0 0 0 4px var(--link-light-color);
|
||||||
|
}
|
||||||
|
.nav-menu-button.with-avatar .icon {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 4px;
|
||||||
|
right: 8px;
|
||||||
|
background-color: var(--bg-color);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
.nav-menu-button.with-avatar:hover:not(:active, .active) .icon {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
/* COLUMNS */
|
/* COLUMNS */
|
||||||
|
|
||||||
#columns {
|
#columns {
|
||||||
|
|
|
@ -1,17 +1,23 @@
|
||||||
import { Menu, MenuDivider, MenuItem } from '@szhsin/react-menu';
|
import { Menu, MenuDivider, MenuItem } from '@szhsin/react-menu';
|
||||||
|
import { useLongPress } from 'use-long-press';
|
||||||
import { useSnapshot } from 'valtio';
|
import { useSnapshot } from 'valtio';
|
||||||
|
|
||||||
import { api } from '../utils/api';
|
import { api } from '../utils/api';
|
||||||
import states from '../utils/states';
|
import states from '../utils/states';
|
||||||
import { getCurrentAccount } from '../utils/store-utils';
|
import store from '../utils/store';
|
||||||
|
|
||||||
|
import Avatar from './avatar';
|
||||||
import Icon from './icon';
|
import Icon from './icon';
|
||||||
import MenuLink from './MenuLink';
|
import MenuLink from './MenuLink';
|
||||||
|
|
||||||
function NavMenu(props) {
|
function NavMenu(props) {
|
||||||
const snapStates = useSnapshot(states);
|
const snapStates = useSnapshot(states);
|
||||||
const { instance, authenticated } = api();
|
const { instance, authenticated } = api();
|
||||||
const currentAccount = getCurrentAccount();
|
const accounts = store.local.getJSON('accounts');
|
||||||
|
const currentAccount = accounts.find(
|
||||||
|
(account) => account.info.id === store.session.get('currentAccount'),
|
||||||
|
);
|
||||||
|
const moreThanOneAccount = accounts.length > 1;
|
||||||
|
|
||||||
// Home = Following
|
// Home = Following
|
||||||
// But when in multi-column mode, Home becomes columns of anything
|
// But when in multi-column mode, Home becomes columns of anything
|
||||||
|
@ -21,6 +27,16 @@ function NavMenu(props) {
|
||||||
snapStates.settings.shortcutsColumnsMode &&
|
snapStates.settings.shortcutsColumnsMode &&
|
||||||
!snapStates.shortcuts.find((pin) => pin.type === 'following');
|
!snapStates.shortcuts.find((pin) => pin.type === 'following');
|
||||||
|
|
||||||
|
const bindLongPress = useLongPress(
|
||||||
|
() => {
|
||||||
|
states.showAccounts = true;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
detect: 'touch',
|
||||||
|
cancelOnMovement: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu
|
<Menu
|
||||||
portal={{
|
portal={{
|
||||||
|
@ -30,11 +46,31 @@ function NavMenu(props) {
|
||||||
overflow="auto"
|
overflow="auto"
|
||||||
viewScroll="close"
|
viewScroll="close"
|
||||||
boundingBoxPadding="8 8 8 8"
|
boundingBoxPadding="8 8 8 8"
|
||||||
menuButton={
|
menuButton={({ open }) => (
|
||||||
<button type="button" class="button plain">
|
<button
|
||||||
<Icon icon="menu" size="l" />
|
type="button"
|
||||||
|
class={`button plain nav-menu-button ${
|
||||||
|
moreThanOneAccount ? 'with-avatar' : ''
|
||||||
|
} ${open ? 'active' : ''}`}
|
||||||
|
style={{ position: 'relative' }}
|
||||||
|
onContextMenu={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
states.showAccounts = true;
|
||||||
|
}}
|
||||||
|
{...bindLongPress()}
|
||||||
|
>
|
||||||
|
{moreThanOneAccount && (
|
||||||
|
<Avatar
|
||||||
|
url={
|
||||||
|
currentAccount?.info?.avatar ||
|
||||||
|
currentAccount?.info?.avatarStatic
|
||||||
|
}
|
||||||
|
size="l"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<Icon icon="menu" size={moreThanOneAccount ? 's' : 'l'} />
|
||||||
</button>
|
</button>
|
||||||
}
|
)}
|
||||||
>
|
>
|
||||||
{!!snapStates.appVersion?.commitHash &&
|
{!!snapStates.appVersion?.commitHash &&
|
||||||
__COMMIT_HASH__ !== snapStates.appVersion.commitHash && (
|
__COMMIT_HASH__ !== snapStates.appVersion.commitHash && (
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import './settings.css';
|
import './settings.css';
|
||||||
|
|
||||||
import { Menu, MenuItem } from '@szhsin/react-menu';
|
import { Menu, MenuDivider, MenuItem } from '@szhsin/react-menu';
|
||||||
import { useReducer, useState } from 'preact/hooks';
|
import { useReducer, useState } from 'preact/hooks';
|
||||||
|
|
||||||
import Avatar from '../components/avatar';
|
import Avatar from '../components/avatar';
|
||||||
|
@ -25,11 +25,6 @@ function Accounts({ onClose }) {
|
||||||
<div id="settings-container" class="sheet" tabIndex="-1">
|
<div id="settings-container" class="sheet" tabIndex="-1">
|
||||||
<header class="header-grid">
|
<header class="header-grid">
|
||||||
<h2>Accounts</h2>
|
<h2>Accounts</h2>
|
||||||
<div class="header-side">
|
|
||||||
<Link to="/login" class="button plain" onClick={onClose}>
|
|
||||||
<Icon icon="plus" /> <span>Account</span>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<section>
|
<section>
|
||||||
|
@ -66,7 +61,12 @@ function Accounts({ onClose }) {
|
||||||
account={account.info}
|
account={account.info}
|
||||||
showAcct
|
showAcct
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
states.showAccount = `${account.info.username}@${account.instanceURL}`;
|
if (isCurrent) {
|
||||||
|
states.showAccount = `${account.info.username}@${account.instanceURL}`;
|
||||||
|
} else {
|
||||||
|
store.session.set('currentAccount', account.info.id);
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -76,18 +76,6 @@ function Accounts({ onClose }) {
|
||||||
<span class="tag">Default</span>{' '}
|
<span class="tag">Default</span>{' '}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{!isCurrent && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="light"
|
|
||||||
onClick={() => {
|
|
||||||
store.session.set('currentAccount', account.info.id);
|
|
||||||
location.reload();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Icon icon="transfer" /> Switch
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<Menu
|
<Menu
|
||||||
align="end"
|
align="end"
|
||||||
menuButton={
|
menuButton={
|
||||||
|
@ -100,6 +88,15 @@ function Accounts({ onClose }) {
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
<MenuItem
|
||||||
|
onClick={() => {
|
||||||
|
states.showAccount = `${account.info.username}@${account.instanceURL}`;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon icon="user" />
|
||||||
|
<span>View profile…</span>
|
||||||
|
</MenuItem>
|
||||||
|
<MenuDivider />
|
||||||
{moreThanOneAccount && (
|
{moreThanOneAccount && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
disabled={isDefault}
|
disabled={isDefault}
|
||||||
|
@ -127,7 +124,7 @@ function Accounts({ onClose }) {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon icon="exit" />
|
<Icon icon="exit" />
|
||||||
<span>Log out</span>
|
<span>Log out…</span>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
</div>
|
</div>
|
||||||
|
@ -135,6 +132,11 @@ function Accounts({ onClose }) {
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</ul>
|
</ul>
|
||||||
|
<p>
|
||||||
|
<Link to="/login" class="button plain2" onClick={onClose}>
|
||||||
|
<Icon icon="plus" /> <span>Add an existing account</span>
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
{moreThanOneAccount && (
|
{moreThanOneAccount && (
|
||||||
<p>
|
<p>
|
||||||
<small>
|
<small>
|
||||||
|
|
Loading…
Reference in a new issue