From 9af8f9b957e3dd805b2ff858b71a2af5dbe81f6a Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Sun, 8 Dec 2024 20:43:56 +0900 Subject: [PATCH] feat: add donation link card --- src/lib/components/DonationCard.tsx | 101 ++++++++++++++++++++++++++++ src/lib/components/Sidebar.tsx | 13 ---- src/lib/constants.ts | 1 + src/options.tsx | 4 ++ 4 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 src/lib/components/DonationCard.tsx diff --git a/src/lib/components/DonationCard.tsx b/src/lib/components/DonationCard.tsx new file mode 100644 index 0000000..4cf492b --- /dev/null +++ b/src/lib/components/DonationCard.tsx @@ -0,0 +1,101 @@ +import { Storage } from "@plasmohq/storage"; +import { useStorage } from "@plasmohq/storage/hook"; +import { AnimatePresence, motion } from "framer-motion"; +import React from "react"; +import { STORAGE_KEYS } from "~lib/constants"; +import { getMessageWithLink } from "~lib/utils"; + +const DonationCard = () => { + const [userClosed, setUserClosed] = useStorage( + { + key: STORAGE_KEYS.DONATION_CARD_USER_CLOSED, + instance: new Storage({ + area: "local", + }), + }, + false, + ); + const handleClose = () => { + setUserClosed(true); + setIsVisible(false); + }; + const handleDonationLinkClick = () => { + handleClose(); + window.open("https://ko-fi.com/kawamataryo", "_blank"); + }; + + const [isVisible, setIsVisible] = React.useState(false); + + React.useEffect(() => { + const showDonationCard = () => { + if (userClosed) return; + setIsVisible(true); + }; + const timeoutId = setTimeout(showDonationCard, 2000); + return () => clearTimeout(timeoutId); + }, [userClosed]); + + return ( + <> + + {isVisible && ( + +
+
+

+ dangerouslySetInnerHTML={{ + __html: getMessageWithLink("donate_message"), + }} + /> + +

+
+
+ +
+
+ )} +
+ + ); +}; + +export default React.memo(DonationCard); diff --git a/src/lib/components/Sidebar.tsx b/src/lib/components/Sidebar.tsx index cc9c289..1d96bf7 100644 --- a/src/lib/components/Sidebar.tsx +++ b/src/lib/components/Sidebar.tsx @@ -184,19 +184,6 @@ const Sidebar = ({ __html: getMessageWithLink("donate_message"), }} /> - - Buy Me a Coffee at ko-fi.com -
diff --git a/src/lib/constants.ts b/src/lib/constants.ts index e661463..c34bfc7 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -44,6 +44,7 @@ export const STORAGE_KEYS = { DETECTED_BSKY_USERS: `${STORAGE_PREFIX}_detected_bsky_users`, LIST_NAME: `${STORAGE_PREFIX}_list_name`, RENDER_KEY: `${STORAGE_PREFIX}_render_key`, + DONATION_CARD_USER_CLOSED: `${STORAGE_PREFIX}_donation_card_user_closed`, } as const; export const TARGET_URLS_REGEX = { diff --git a/src/options.tsx b/src/options.tsx index 2c81109..cf07844 100644 --- a/src/options.tsx +++ b/src/options.tsx @@ -8,6 +8,7 @@ import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/ import React from "react"; import ReSearchModal from "~components/ReSearchModal"; import DetectedUserListItem from "~lib/components/DetectedUserListItem"; +import DonationCard from "~lib/components/DonationCard"; const Option = () => { const { @@ -185,6 +186,9 @@ const Option = () => { ))} +
+ +