Fix default tag always wrong location

Feel so dumb looking back at this code lol
This commit is contained in:
Lim Chee Aun 2023-10-22 23:09:04 +08:00
parent 4e53b1e17f
commit ced30a9602

View file

@ -2,6 +2,7 @@ import './accounts.css';
import { Menu, MenuDivider, MenuItem } from '@szhsin/react-menu';
import { useReducer, useState } from 'preact/hooks';
import { useReducer } from 'preact/hooks';
import Avatar from '../components/avatar';
import Icon from '../components/icon';
@ -18,7 +19,6 @@ function Accounts({ onClose }) {
const accounts = store.local.getJSON('accounts');
const currentAccount = store.session.get('currentAccount');
const moreThanOneAccount = accounts.length > 1;
const [currentDefault, setCurrentDefault] = useState(0);
const [_, reload] = useReducer((x) => x + 1, 0);
@ -37,9 +37,9 @@ function Accounts({ onClose }) {
<ul class="accounts-list">
{accounts.map((account, i) => {
const isCurrent = account.info.id === currentAccount;
const isDefault = i === (currentDefault || 0);
const isDefault = i === 0; // first account is always default
return (
<li key={i + account.id}>
<li key={account.info.id}>
<div>
{moreThanOneAccount && (
<span class={`current ${isCurrent ? 'is-current' : ''}`}>
@ -120,7 +120,7 @@ function Accounts({ onClose }) {
accounts.splice(i, 1);
accounts.unshift(account);
store.local.setJSON('accounts', accounts);
setCurrentDefault(i);
reload();
}}
>
<Icon icon="check-circle" />