mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
add debouncing to selected theme
This commit is contained in:
@@ -25,14 +25,17 @@ export const ThemeCover: React.FC<ThemeCoverProps> = ({
|
|||||||
const handleThemeClick = async () => {
|
const handleThemeClick = async () => {
|
||||||
if (isEditMode) return;
|
if (isEditMode) return;
|
||||||
if (downloaded) {
|
if (downloaded) {
|
||||||
|
// move the theme from temporary storage to SEQTAs storage
|
||||||
await sendThemeUpdate(theme as DownloadedTheme, true)
|
await sendThemeUpdate(theme as DownloadedTheme, true)
|
||||||
|
// remove from temp storage
|
||||||
await browser.runtime.sendMessage({
|
await browser.runtime.sendMessage({
|
||||||
type: 'DeleteDownloadedTheme',
|
type: 'DeleteDownloadedTheme',
|
||||||
body: theme.id
|
body: theme.id
|
||||||
})
|
})
|
||||||
|
// set it!
|
||||||
setTheme(theme.id);
|
setTheme(theme.id);
|
||||||
} else {
|
} else {
|
||||||
console.log(theme)
|
console.debug(theme)
|
||||||
onThemeSelect(theme.id);
|
onThemeSelect(theme.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -79,10 +79,20 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchThemes();
|
fetchThemes();
|
||||||
|
|
||||||
|
/* const interval = setInterval(() => {
|
||||||
|
console.log("Done!");
|
||||||
|
if (isLoading == true) {
|
||||||
|
fetchThemes();
|
||||||
|
} else {
|
||||||
|
clearInterval(interval);
|
||||||
|
}
|
||||||
|
}, 1000); */
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleThemeSelect = useCallback(
|
const handleThemeSelect = useCallback(
|
||||||
async (themeId: string) => {
|
async (themeId: string) => {
|
||||||
|
console.log(themeId === settingsState.selectedTheme);
|
||||||
if (themeId === settingsState.selectedTheme) {
|
if (themeId === settingsState.selectedTheme) {
|
||||||
await disableTheme();
|
await disableTheme();
|
||||||
setSelectedTheme('');
|
setSelectedTheme('');
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import browser from 'webextension-polyfill'
|
import browser from 'webextension-polyfill'
|
||||||
|
import { debounce } from 'lodash';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CreateBackground,
|
CreateBackground,
|
||||||
@@ -11,13 +12,18 @@ import {
|
|||||||
} from '../../../SEQTA';
|
} from '../../../SEQTA';
|
||||||
import { updateBgDurations } from '../../ui/Animation';
|
import { updateBgDurations } from '../../ui/Animation';
|
||||||
import { getDarkMode, updateAllColors } from '../../ui/colors/Manager';
|
import { getDarkMode, updateAllColors } from '../../ui/colors/Manager';
|
||||||
import { appendBackgroundToUI } from '../../ui/ImageBackgrounds';
|
//import { appendBackgroundToUI } from '../../ui/ImageBackgrounds';
|
||||||
|
import { setTheme } from '../../ui/themes/setTheme';
|
||||||
|
import { disableTheme } from '../../ui/themes/disableTheme';
|
||||||
|
|
||||||
|
|
||||||
export default class StorageListener {
|
export default class StorageListener {
|
||||||
darkMode: any;
|
darkMode: any;
|
||||||
|
debouncedSetTheme: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.darkMode = getDarkMode();
|
this.darkMode = getDarkMode();
|
||||||
|
this.debouncedSetTheme = debounce(this.applyTheme, 300); // 300 ms debounce period
|
||||||
browser.storage.onChanged.addListener(this.handleStorageChanges.bind(this));
|
browser.storage.onChanged.addListener(this.handleStorageChanges.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,8 +88,8 @@ export default class StorageListener {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'theme':
|
case 'selectedTheme':
|
||||||
console.log(changes.theme.newValue)
|
this.debouncedSetTheme(changes.selectedTheme.newValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -92,6 +98,14 @@ export default class StorageListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyTheme(theme: string) {
|
||||||
|
if (theme === '') {
|
||||||
|
disableTheme();
|
||||||
|
} else {
|
||||||
|
setTheme(theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleSelectedColorChange(newColor: any) {
|
handleSelectedColorChange(newColor: any) {
|
||||||
try {
|
try {
|
||||||
updateAllColors(this.darkMode, newColor);
|
updateAllColors(this.darkMode, newColor);
|
||||||
|
|||||||
Reference in New Issue
Block a user