mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-29 12:49:20 +03:00
Hidden way to update the account info
Usually when avatar or name changes
This commit is contained in:
parent
4760efe837
commit
2a44f3a670
2 changed files with 23 additions and 4 deletions
|
@ -9,7 +9,7 @@ const SIZES = {
|
||||||
xxxl: 64,
|
xxxl: 64,
|
||||||
};
|
};
|
||||||
|
|
||||||
function Avatar({ url, size, alt = '' }) {
|
function Avatar({ url, size, alt = '', ...props }) {
|
||||||
size = SIZES[size] || size || SIZES.m;
|
size = SIZES[size] || size || SIZES.m;
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
|
@ -19,6 +19,7 @@ function Avatar({ url, size, alt = '' }) {
|
||||||
height: size,
|
height: size,
|
||||||
}}
|
}}
|
||||||
title={alt}
|
title={alt}
|
||||||
|
{...props}
|
||||||
>
|
>
|
||||||
{!!url && (
|
{!!url && (
|
||||||
<img src={url} width={size} height={size} alt={alt} loading="lazy" />
|
<img src={url} width={size} height={size} alt={alt} loading="lazy" />
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import './settings.css';
|
import './settings.css';
|
||||||
|
|
||||||
import { useRef, useState } from 'preact/hooks';
|
import { useReducer, useRef, useState } from 'preact/hooks';
|
||||||
import { useSnapshot } from 'valtio';
|
import { useSnapshot } from 'valtio';
|
||||||
|
|
||||||
import Avatar from '../components/avatar';
|
import Avatar from '../components/avatar';
|
||||||
|
@ -27,6 +27,8 @@ function Settings({ onClose }) {
|
||||||
const moreThanOneAccount = accounts.length > 1;
|
const moreThanOneAccount = accounts.length > 1;
|
||||||
const [currentDefault, setCurrentDefault] = useState(0);
|
const [currentDefault, setCurrentDefault] = useState(0);
|
||||||
|
|
||||||
|
const [_, reload] = useReducer((x) => x + 1, 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="settings-container" class="sheet" tabIndex="-1">
|
<div id="settings-container" class="sheet" tabIndex="-1">
|
||||||
<main>
|
<main>
|
||||||
|
@ -40,14 +42,30 @@ function Settings({ onClose }) {
|
||||||
const isCurrent = account.info.id === currentAccount;
|
const isCurrent = account.info.id === currentAccount;
|
||||||
const isDefault = i === (currentDefault || 0);
|
const isDefault = i === (currentDefault || 0);
|
||||||
return (
|
return (
|
||||||
<li>
|
<li key={i + account.id}>
|
||||||
<div>
|
<div>
|
||||||
{moreThanOneAccount && (
|
{moreThanOneAccount && (
|
||||||
<span class={`current ${isCurrent ? 'is-current' : ''}`}>
|
<span class={`current ${isCurrent ? 'is-current' : ''}`}>
|
||||||
<Icon icon="check-circle" alt="Current" />
|
<Icon icon="check-circle" alt="Current" />
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<Avatar url={account.info.avatarStatic} size="xxl" />
|
<Avatar
|
||||||
|
url={account.info.avatarStatic}
|
||||||
|
size="xxl"
|
||||||
|
onDblClick={async () => {
|
||||||
|
if (isCurrent) {
|
||||||
|
try {
|
||||||
|
const info = await masto.v1.accounts.fetch(
|
||||||
|
account.info.id,
|
||||||
|
);
|
||||||
|
console.log('fetched account info', info);
|
||||||
|
account.info = info;
|
||||||
|
store.local.setJSON('accounts', accounts);
|
||||||
|
reload();
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<NameText
|
<NameText
|
||||||
account={account.info}
|
account={account.info}
|
||||||
showAcct
|
showAcct
|
||||||
|
|
Loading…
Add table
Reference in a new issue