feat: add update frequency settings for quotes and backgrounds

- Introduced frequency settings for quotes and background updates in multiple languages.
- Added new localization keys for "Update Frequency" and its options.
- Implemented a new hook `useFrequencyInterval` to manage update intervals based on user settings.
- Created a `frequencyManager` utility to handle frequency intervals and update logic.
- Updated default settings to include frequency preferences for both quotes and backgrounds.
This commit is contained in:
alexsparkes
2026-01-31 17:44:29 +00:00
parent 7415b9cd5c
commit f7a799fe34
42 changed files with 786 additions and 70 deletions

View File

@@ -12,6 +12,7 @@ import {
} from 'components/Layout/Settings';
import { Checkbox, Dropdown, Textarea } from 'components/Form/Settings';
import { Button } from 'components/Elements';
import { FREQUENCY_OPTIONS } from 'utils/frequencyManager';
const QuoteOptions = ({ currentSubSection, onSubSectionChange, sectionName }) => {
const getCustom = () => {
@@ -123,6 +124,39 @@ const QuoteOptions = ({ currentSubSection, onSubSectionChange, sectionName }) =>
);
};
const FrequencyOptions = () => {
return (
<Row>
<Content
title={variables.getMessage(`${QUOTE_SECTION}.frequency.title`)}
subtitle={variables.getMessage(`${QUOTE_SECTION}.frequency.subtitle`)}
/>
<Action>
<Dropdown
name="quoteFrequency"
label={variables.getMessage(`${QUOTE_SECTION}.frequency.title`)}
onChange={(value) => {
localStorage.setItem('quoteStartTime', Date.now());
// Clear queue if switching from refresh to time-based frequency
const oldValue = localStorage.getItem('quoteFrequency');
if (oldValue === 'refresh' && value !== 'refresh') {
localStorage.removeItem('quoteQueue');
}
// Notify the frequency interval hook that the frequency changed
window.dispatchEvent(new CustomEvent('frequencyChanged', {
detail: { type: 'quote' }
}));
}}
items={FREQUENCY_OPTIONS.map((opt) => ({
value: opt.value,
text: variables.getMessage(opt.text),
}))}
/>
</Action>
</Row>
);
};
const AdditionalOptions = () => {
return (
<Row final={true}>
@@ -282,6 +316,7 @@ const QuoteOptions = ({ currentSubSection, onSubSectionChange, sectionName }) =>
<SourceDropdown />
</Section>
<ButtonOptions />
<FrequencyOptions />
<AdditionalOptions />
</PreferencesWrapper>
)}