From 39efda9e38a66eb6fba826b209bf4a62cb0e798c Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
Date: Tue, 20 Dec 2022 19:14:50 +0800
Subject: [PATCH] Track spoilers

Turns out I'm using WeakMap wrong
---
 src/components/status.jsx | 14 +++++++++++---
 src/utils/states.js       |  3 ++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/components/status.jsx b/src/components/status.jsx
index 0bdd79c1..7eb1949f 100644
--- a/src/components/status.jsx
+++ b/src/components/status.jsx
@@ -130,7 +130,7 @@ function Status({
     }
   }
 
-  const [showSpoiler, setShowSpoiler] = useState(false);
+  const showSpoiler = snapStates.spoilers.has(id) || false;
 
   const debugHover = (e) => {
     if (e.shiftKey) {
@@ -293,7 +293,11 @@ function Status({
                 onClick={(e) => {
                   e.preventDefault();
                   e.stopPropagation();
-                  setShowSpoiler(!showSpoiler);
+                  if (showSpoiler) {
+                    states.spoilers.delete(id);
+                  } else {
+                    states.spoilers.set(id, true);
+                  }
                 }}
               >
                 <Icon icon={showSpoiler ? 'eye-open' : 'eye-close'} />{' '}
@@ -356,7 +360,11 @@ function Status({
               onClick={(e) => {
                 e.preventDefault();
                 e.stopPropagation();
-                setShowSpoiler(!showSpoiler);
+                if (showSpoiler) {
+                  states.spoilers.delete(id);
+                } else {
+                  states.spoilers.add(id);
+                }
               }}
             >
               <Icon icon={showSpoiler ? 'eye-open' : 'eye-close'} /> Sensitive
diff --git a/src/utils/states.js b/src/utils/states.js
index 31b14380..613e52ba 100644
--- a/src/utils/states.js
+++ b/src/utils/states.js
@@ -10,8 +10,9 @@ export default proxy({
   notifications: [],
   notificationsNew: [],
   notificationsLastFetchTime: null,
-  accounts: new WeakMap(),
+  accounts: new Map(),
   reloadStatusPage: 0,
+  spoilers: proxyMap([]),
   // Modals
   showCompose: false,
   showSettings: false,