From ced30a9602392e06a57500050a16c9e69443a292 Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
Date: Sun, 22 Oct 2023 23:09:04 +0800
Subject: [PATCH] Fix default tag always wrong location

Feel so dumb looking back at this code lol
---
 src/pages/accounts.jsx | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/pages/accounts.jsx b/src/pages/accounts.jsx
index d43a33fb..7647e815 100644
--- a/src/pages/accounts.jsx
+++ b/src/pages/accounts.jsx
@@ -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" />