Fixed bug with weather logging. Fixed bug with search bar shortcuts

This commit is contained in:
Paweł Malak 2021-10-26 14:37:01 +02:00
parent df6d96f5b6
commit 3d3e2eed8c
4 changed files with 45 additions and 19 deletions

View file

@ -1,3 +1,8 @@
### v1.7.2 (TBA)
- Use search bar shortcuts when it's not focused ([#124](https://github.com/pawelmalak/flame/issues/124))
- Fixed bug with Weather API still logging with module being disabled ([#125](https://github.com/pawelmalak/flame/issues/125))
- Added option to disable search bar autofocus ([#127](https://github.com/pawelmalak/flame/issues/127))
### v1.7.1 (2021-10-22)
- Fixed search action not being triggered by Numpad Enter
- Added option to change date formatting ([#92](https://github.com/pawelmalak/flame/issues/92))

View file

@ -25,12 +25,28 @@ const SearchBar = (props: ComponentProps): JSX.Element => {
const inputRef = useRef<HTMLInputElement>(document.createElement('input'));
// Search bar autofocus
useEffect(() => {
if (!loading && !config.disableAutofocus) {
inputRef.current.focus();
}
}, [config]);
// Listen for keyboard events outside of search bar
useEffect(() => {
const keyOutsideFocus = (e: any) => {
const { key } = e as KeyboardEvent;
if (key === 'Escape') {
clearSearch();
}
};
window.addEventListener('keydown', keyOutsideFocus);
return () => window.removeEventListener('keydown', keyOutsideFocus);
}, []);
const clearSearch = () => {
inputRef.current.value = '';
setLocalSearch('');

View file

@ -5,14 +5,6 @@ const loadConfig = require('./loadConfig');
const getExternalWeather = async () => {
const { WEATHER_API_KEY: secret, lat, long } = await loadConfig();
if (!secret) {
throw new Error('API key was not found. Weather updated failed');
}
if (!lat || !long) {
throw new Error('Location was not found. Weather updated failed');
}
// Fetch data from external API
try {
const res = await axios.get(

View file

@ -3,20 +3,33 @@ const getExternalWeather = require('./getExternalWeather');
const clearWeatherData = require('./clearWeatherData');
const Sockets = require('../Sockets');
const Logger = require('./Logger');
const loadConfig = require('./loadConfig');
const logger = new Logger();
// Update weather data every 15 minutes
const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async () => {
try {
const weatherData = await getExternalWeather();
logger.log('Weather updated');
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
} catch (err) {
logger.log(err.message, 'ERROR');
const weatherJob = schedule.scheduleJob(
'updateWeather',
'0 */15 * * * *',
async () => {
const { WEATHER_API_KEY: secret } = await loadConfig();
try {
const weatherData = await getExternalWeather();
logger.log('Weather updated');
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
} catch (err) {
if (secret) {
logger.log(err.message, 'ERROR');
}
}
}
})
);
// Clear old weather data every 4 hours
const weatherCleanerJob = schedule.scheduleJob('clearWeather', '0 5 */4 * * *', async () => {
clearWeatherData();
})
const weatherCleanerJob = schedule.scheduleJob(
'clearWeather',
'0 5 */4 * * *',
async () => {
clearWeatherData();
}
);