mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
add closeThemeCreator error handling
This commit is contained in:
@@ -20,7 +20,6 @@ interface ThemeSelectorProps {
|
|||||||
|
|
||||||
const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> & RefAttributes<any>> = forwardRef(({ isEditMode = false }, ref) => {
|
const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> & RefAttributes<any>> = forwardRef(({ isEditMode = false }, ref) => {
|
||||||
const [themes, setThemes] = useState<Omit<CustomTheme, 'CustomImages'>[]>([]);
|
const [themes, setThemes] = useState<Omit<CustomTheme, 'CustomImages'>[]>([]);
|
||||||
const [downloadedThemes, setDownloadedThemes] = useState<DownloadedTheme[]>([]);
|
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||||
const [isDragging, setIsDragging] = useState<boolean>(false);
|
const [isDragging, setIsDragging] = useState<boolean>(false);
|
||||||
const [tempTheme, setTempTheme] = useState<any>(null);
|
const [tempTheme, setTempTheme] = useState<any>(null);
|
||||||
@@ -82,19 +81,10 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
const fetchThemes = async () => {
|
const fetchThemes = async () => {
|
||||||
try {
|
try {
|
||||||
const { themes, selectedTheme } = await listThemes();
|
const { themes, selectedTheme } = await listThemes();
|
||||||
const tempDownloadedThemes = await getDownloadedThemes();
|
let tempDownloadedThemes = await getDownloadedThemes();
|
||||||
|
|
||||||
setThemes(themes);
|
setThemes(themes);
|
||||||
//setDownloadedThemes(tempDownloadedThemes);
|
|
||||||
setSelectedTheme(selectedTheme ? selectedTheme : '');
|
setSelectedTheme(selectedTheme ? selectedTheme : '');
|
||||||
|
|
||||||
console.log(tempDownloadedThemes)
|
|
||||||
|
|
||||||
tempDownloadedThemes.forEach(async (theme) => {
|
|
||||||
console.log('Updating theme:', theme)
|
|
||||||
await sendThemeUpdate(theme as DownloadedTheme, true, false)
|
|
||||||
DeleteDownloadedTheme(theme.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
const matchingThemes = themes.filter(theme =>
|
const matchingThemes = themes.filter(theme =>
|
||||||
tempDownloadedThemes.some(downloadedTheme => downloadedTheme.id === theme.id)
|
tempDownloadedThemes.some(downloadedTheme => downloadedTheme.id === theme.id)
|
||||||
@@ -103,13 +93,14 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
if (matchingThemes.length > 0) {
|
if (matchingThemes.length > 0) {
|
||||||
matchingThemes.forEach((theme) => {
|
matchingThemes.forEach((theme) => {
|
||||||
DeleteDownloadedTheme(theme.id);
|
DeleteDownloadedTheme(theme.id);
|
||||||
|
tempDownloadedThemes = tempDownloadedThemes.filter(downloadedTheme => downloadedTheme.id !== theme.id);
|
||||||
setDownloadedThemes(
|
|
||||||
downloadedThemes.filter(downloadedTheme => downloadedTheme.id !== theme.id)
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tempDownloadedThemes.forEach(async (theme) => {
|
||||||
|
await sendThemeUpdate(theme as DownloadedTheme, true, false)
|
||||||
|
DeleteDownloadedTheme(theme.id);
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching themes:', error);
|
console.error('Error fetching themes:', error);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -141,17 +132,9 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
|
|
||||||
const handleThemeDelete = useCallback(
|
const handleThemeDelete = useCallback(
|
||||||
async (themeId: string) => {
|
async (themeId: string) => {
|
||||||
console.log(themeId, downloadedThemes)
|
|
||||||
try {
|
try {
|
||||||
if (downloadedThemes.some((theme) => theme.id === themeId)) {
|
await deleteTheme(themeId);
|
||||||
console.log('Deleting downloaded theme:', themeId)
|
setThemes((prevThemes) => prevThemes.filter((theme) => theme.id !== themeId));
|
||||||
DeleteDownloadedTheme(themeId);
|
|
||||||
setDownloadedThemes((prevThemes) => prevThemes.filter((theme) => theme.id !== themeId));
|
|
||||||
} else {
|
|
||||||
console.log('False')
|
|
||||||
await deleteTheme(themeId);
|
|
||||||
setThemes((prevThemes) => prevThemes.filter((theme) => theme.id !== themeId));
|
|
||||||
}
|
|
||||||
if (themeId === settingsState.selectedTheme) {
|
if (themeId === settingsState.selectedTheme) {
|
||||||
setSelectedTheme('')
|
setSelectedTheme('')
|
||||||
disableTheme();
|
disableTheme();
|
||||||
@@ -240,25 +223,13 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{downloadedThemes.map((theme) => (
|
|
||||||
<ThemeCover
|
|
||||||
key={theme.id}
|
|
||||||
downloaded={true}
|
|
||||||
theme={theme}
|
|
||||||
isSelected={theme.id === settingsState.selectedTheme}
|
|
||||||
isEditMode={isEditMode}
|
|
||||||
onThemeSelect={handleThemeSelectDebounced}
|
|
||||||
onThemeDelete={handleThemeDelete}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{tempTheme && (
|
{tempTheme && (
|
||||||
<div className="flex justify-center w-full bg-gray-200 rounded-xl dark:bg-zinc-700/50 place-items-center aspect-theme animate-pulse">
|
<div className="flex justify-center w-full bg-gray-200 rounded-xl dark:bg-zinc-700/50 place-items-center aspect-theme animate-pulse">
|
||||||
<SpinnerIcon className='opacity-50' />
|
<SpinnerIcon className='opacity-50' />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{downloadedThemes.length + themes.length > 0 && <div
|
{ themes.length > 0 && <div
|
||||||
id="divider"
|
id="divider"
|
||||||
className="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600"
|
className="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600"
|
||||||
></div>}
|
></div>}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ type ThemeContent = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
|
export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
|
||||||
console.log(theme.themeContent.id);
|
|
||||||
if (!theme.themeContent.id) return;
|
if (!theme.themeContent.id) return;
|
||||||
|
|
||||||
const themeContent = await fetch(`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${theme.themeContent.id}/theme.json`);
|
const themeContent = await fetch(`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${theme.themeContent.id}/theme.json`);
|
||||||
|
|||||||
@@ -93,7 +93,12 @@ export class MessageHandler {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 'CloseThemeCreator':
|
case 'CloseThemeCreator':
|
||||||
CloseThemeCreator();
|
try {
|
||||||
|
CloseThemeCreator();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error closing theme creator:', error);
|
||||||
|
sendResponse({ status: 'error' });
|
||||||
|
}
|
||||||
sendResponse({ status: 'success' });
|
sendResponse({ status: 'success' });
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user