From 785cc54d3975f13c8ae5c530632a3b49dd8f6830 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Mon, 22 Apr 2024 12:58:02 +1000 Subject: [PATCH] I have literally lost track. Please save me, I am going crazy --- src/interface/components/ThemeCover.tsx | 2 +- src/interface/components/ThemeSelector.tsx | 11 ++++++++ src/interface/pages/Theme.tsx | 29 +++++++++++++++++----- src/seqta/ui/themes/downloadTheme.ts | 7 +++--- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/interface/components/ThemeCover.tsx b/src/interface/components/ThemeCover.tsx index 2ad30b0c..3fd17e80 100644 --- a/src/interface/components/ThemeCover.tsx +++ b/src/interface/components/ThemeCover.tsx @@ -66,7 +66,7 @@ export const ThemeCover: React.FC = ({ )} - { !isEditMode || !downloaded && + { isEditMode || !downloaded && <>
& setThemes(themes); setDownloadedThemes(await getDownloadedThemes()); setSelectedTheme(selectedTheme ? selectedTheme : ''); + + const matchingThemes = themes.filter(theme => downloadedThemes.some((downloadedTheme: DownloadedTheme) => downloadedTheme.id === theme.id)); + if (matchingThemes.length > 0) { + matchingThemes.forEach((theme) => { + browser.runtime.sendMessage({ + type: 'DeleteDownloadedTheme', + body: theme.id + }) + }) + } + } catch (error) { console.error('Error fetching themes:', error); } finally { diff --git a/src/interface/pages/Theme.tsx b/src/interface/pages/Theme.tsx index 61195e84..ef35f720 100644 --- a/src/interface/pages/Theme.tsx +++ b/src/interface/pages/Theme.tsx @@ -7,6 +7,7 @@ import { LinkIcon } from "@heroicons/react/24/outline"; import { ToastContainer, toast } from 'react-toastify'; import browser from 'webextension-polyfill'; import 'react-toastify/dist/ReactToastify.css'; +import localforage from "localforage"; const pb = new PocketBase('https://betterseqta.pockethost.io'); @@ -16,6 +17,7 @@ const Theme = () => { const [themeID, setThemeID] = useState(''); const [justCreated, setJustCreated] = useState(false); const [displayConfetti, setDisplayConfetti] = useState(true); + const [currentThemes, setCurrentThemes] = useState([]); useEffect(() => { const timer = setTimeout(() => { @@ -37,6 +39,9 @@ const Theme = () => { console.log(theme); setIsLoading(false); setTheme(theme); + + const availableThemes = await localforage.getItem('availableThemes') as string[]; + setCurrentThemes(availableThemes) } if (themeID && themeID !== 'null') { @@ -94,12 +99,24 @@ const Theme = () => {

{theme.name}

{theme.description}

- + { + /* currentThemes.includes((theme.theme as { id: string }).id) */ false ? + + : + + }
)} diff --git a/src/seqta/ui/themes/downloadTheme.ts b/src/seqta/ui/themes/downloadTheme.ts index 3b5b4305..616ee957 100644 --- a/src/seqta/ui/themes/downloadTheme.ts +++ b/src/seqta/ui/themes/downloadTheme.ts @@ -2,7 +2,6 @@ import localforage from 'localforage'; import { ThemesResponse } from '../../../interface/types/pocketbase-types'; import { CustomTheme } from '../../../interface/types/CustomThemes'; -import browser from 'webextension-polyfill'; const DownloadTheme = async (theme: ThemesResponse & { theme: CustomTheme & { images: { id: string, variableName: string }[] } }) => { const images: { imageData: Blob, imageID: string }[] = [] @@ -36,12 +35,12 @@ const DownloadTheme = async (theme: ThemesResponse & { theme: CustomTheme & { im CustomImages: theme.theme.images.map((image) => { return { ...image, - blob: images.find((i) => i.imageID.split('_')[0] === image.id)?.imageData + blob: images.find((img) => { + return image.id.includes(img.imageID.split('_')[0]); + })?.imageData } }) }); - - browser.runtime.sendMessage({ type: 'extensionPages', info: 'themeChanged' }); } export default DownloadTheme;