Skip to content

Commit 3737503

Browse files
committed
showing refresh interval as part of UI and checks to prevent errorneous setting from being saved.
1 parent 7ff2f42 commit 3737503

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

src/l10n/locale/de.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
"Reset to default": "Zurücksetzen",
2020
'HackerNews Settings': 'Wörterbuch Einstellungen',
2121
'Refresh Interval': 'Refresh Interval',
22-
'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be considered as 60 seconds.': 'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be considered as 60 seconds.',
22+
'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be reverted to 60 seconds.': 'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be reverted to 60 seconds.',
2323
'Language': 'Sprache',
2424
'The Language the Plugin will use to search for Definitions and Pronunciations.': 'Die Sprache, welche von dieser Erweiterung verwendet wird, um nach Definitionen zu suchen.',
2525
'Synonym Suggestions': 'Synonym Vorschläge',

src/l10n/locale/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
"Reset to default": "Reset to default",
2020
'HackerNews Settings': 'HackerNews Settings',
2121
'Refresh Interval': 'Refresh Interval',
22-
'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be considered as 60 seconds.': 'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be considered as 60 seconds.',
22+
'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be reverted to 60 seconds.': 'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be reverted to 60 seconds.',
2323
'Language': 'Language',
2424
'The Language the Plugin will use to search for Definitions and Pronunciations.': 'The Language the Plugin will use to search for Definitions and Pronunciations.',
2525
'Synonym Suggestions': 'Synonym Suggestions',

src/l10n/locale/zh-cn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
//settingsTab.ts
1818
'HackerNews Settings': '词典设置',
1919
'Refresh Interval': 'Refresh Interval',
20-
'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be considered as 60 seconds.': 'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be considered as 60 seconds.',
20+
'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be reverted to 60 seconds.': 'The time interval in seconds after which the next top story will be fetched. Default and invalid values will be reverted to 60 seconds.',
2121
'Language': '语言',
2222
'The Language the Plugin will use to search for Definitions and Pronunciations.': '插件会根据该语言来搜索语义以及发音',
2323
'Synonym Suggestions': '同义词建议',

src/ui/dictionary/dictionaryView.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import t from "src/l10n/helpers";
1111
1212
export let manager: APIManager;
13+
export let refreshInterval: string;
1314
1415
export let query: string = "";
1516
let promise: Promise<DictionaryWord>;
@@ -56,6 +57,9 @@
5657
<p class="hn-read">
5758
<a href="{ dataHN.url }" target="_blank">Read more →</a>
5859
</p>
60+
<p class="hn-meta">
61+
Refreshes every { refreshInterval } seconds.
62+
</p>
5963
</div>
6064
</div>
6165
{/if}
@@ -73,6 +77,11 @@
7377
margin-top: 0.5em;
7478
}
7579
80+
.hn-meta {
81+
font-size: 0.7em;
82+
color: #aaa;
83+
}
84+
7685
.results {
7786
display: flex;
7887
flex-wrap: wrap;

src/ui/dictionary/dictionaryView.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export default class DictionaryView extends ItemView {
4747
localDictionary: this.plugin.localDictionary,
4848
}
4949
});
50+
this._view.$set({
51+
refreshInterval: this.plugin.settings.defaultRefreshInterval,
52+
});
5053
addEventListener('dictionary-open-language-switcher', () => {
5154
new LanguageChooser(this.app, this.plugin).open();
5255
});

src/ui/settings/settingsTab.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ export default class SettingsTab extends PluginSettingTab {
2222

2323
new Setting(containerEl)
2424
.setName(t('Refresh Interval'))
25-
.setDesc(t('The time interval in seconds after which the next top story will be fetched. Default and invalid values will be considered as 60 seconds.'))
25+
.setDesc(t('The time interval in seconds after which the next top story will be fetched. Default and invalid values will be reverted to 60 seconds.'))
2626
.addText(text => text
2727
.setPlaceholder('60')
2828
.setValue(plugin.settings.defaultRefreshInterval)
2929
.onChange(async (value) => {
30-
plugin.settings.defaultRefreshInterval = value;
30+
let refreshInterval = parseInt(value)
31+
if (Number.isNaN(refreshInterval) || refreshInterval <= 0) { refreshInterval = 60 }
32+
plugin.settings.defaultRefreshInterval = `${refreshInterval}`;
3133
await this.save();
3234
}));
3335
new Setting(containerEl)

0 commit comments

Comments
 (0)