From 8180cc357e40b683d07e78dc5eefb77c5a9d9219 Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
Date: Sun, 29 Oct 2023 11:47:20 +0800
Subject: [PATCH] Fix loadAcounts firing twice

---
 src/components/generic-accounts.jsx | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/components/generic-accounts.jsx b/src/components/generic-accounts.jsx
index 11070c0c..0f38e472 100644
--- a/src/components/generic-accounts.jsx
+++ b/src/components/generic-accounts.jsx
@@ -1,6 +1,6 @@
 import './generic-accounts.css';
 
-import { useEffect, useState } from 'preact/hooks';
+import { useEffect, useRef, useState } from 'preact/hooks';
 import { InView } from 'react-intersection-observer';
 import { useSnapshot } from 'valtio';
 
@@ -56,15 +56,18 @@ export default function GenericAccounts({ onClose = () => {} }) {
     })();
   };
 
+  const firstLoad = useRef(true);
   useEffect(() => {
     if (staticAccounts?.length > 0) {
       setAccounts(staticAccounts);
     } else {
       loadAccounts(true);
+      firstLoad.current = false;
     }
   }, [staticAccounts, fetchAccounts]);
 
   useEffect(() => {
+    if (firstLoad.current) return;
     // reloadGenericAccounts contains value like {id: 'mute', counter: 1}
     // We only need to reload if the id matches
     if (snapStates.reloadGenericAccounts?.id === id) {