fix: contributor card state (#430)
Co-authored-by: guoqqqi <72343596+guoqqqi@users.noreply.github.com>
diff --git a/website/src/pages/index.js b/website/src/pages/index.js
index 1ba05e6..4edbfa5 100644
--- a/website/src/pages/index.js
+++ b/website/src/pages/index.js
@@ -259,20 +259,23 @@
};
const Contributor200Poster = () => {
- const [display, setDisplay] = useState(true);
+ const [display, setDisplay] = useState(false);
const [theme, setTheme] = useState('light');
useEffect(() => {
addEventListener('click', () => {
- if (localStorage.getItem('theme') !== theme) {
- setTheme(localStorage.getItem('theme'));
- };
+ setTheme(localStorage.getItem('theme'));
});
- }, [theme]);
-
- if (!display || (typeof window !== 'undefined' && localStorage.getItem('SHOW_200_CONTRIBUTOR_EVENT_ENTRY'))) {
- return null;
- }
+ if (localStorage.getItem("theme")) {
+ setTheme(localStorage.getItem('theme'));
+ };
+ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ setTheme('dark');
+ }
+ if (!localStorage.getItem('SHOW_200_CONTRIBUTOR_EVENT_ENTRY')) {
+ setDisplay(true);
+ };
+ }, []);
const onClose = () => {
setDisplay(false);
@@ -281,6 +284,10 @@
}
};
+ if (!display) {
+ return null;
+ }
+
return (
<div className="pic-wrapper">
<button className="pic-wrapper-close" onClick={onClose}>