mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
Fixed bug with weather logging. Fixed bug with search bar shortcuts
This commit is contained in:
parent
df6d96f5b6
commit
3d3e2eed8c
4 changed files with 45 additions and 19 deletions
|
@ -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)
|
### v1.7.1 (2021-10-22)
|
||||||
- Fixed search action not being triggered by Numpad Enter
|
- Fixed search action not being triggered by Numpad Enter
|
||||||
- Added option to change date formatting ([#92](https://github.com/pawelmalak/flame/issues/92))
|
- Added option to change date formatting ([#92](https://github.com/pawelmalak/flame/issues/92))
|
||||||
|
|
|
@ -25,12 +25,28 @@ const SearchBar = (props: ComponentProps): JSX.Element => {
|
||||||
|
|
||||||
const inputRef = useRef<HTMLInputElement>(document.createElement('input'));
|
const inputRef = useRef<HTMLInputElement>(document.createElement('input'));
|
||||||
|
|
||||||
|
// Search bar autofocus
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!loading && !config.disableAutofocus) {
|
if (!loading && !config.disableAutofocus) {
|
||||||
inputRef.current.focus();
|
inputRef.current.focus();
|
||||||
}
|
}
|
||||||
}, [config]);
|
}, [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 = () => {
|
const clearSearch = () => {
|
||||||
inputRef.current.value = '';
|
inputRef.current.value = '';
|
||||||
setLocalSearch('');
|
setLocalSearch('');
|
||||||
|
|
|
@ -5,14 +5,6 @@ const loadConfig = require('./loadConfig');
|
||||||
const getExternalWeather = async () => {
|
const getExternalWeather = async () => {
|
||||||
const { WEATHER_API_KEY: secret, lat, long } = await loadConfig();
|
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
|
// Fetch data from external API
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(
|
const res = await axios.get(
|
||||||
|
|
|
@ -3,20 +3,33 @@ const getExternalWeather = require('./getExternalWeather');
|
||||||
const clearWeatherData = require('./clearWeatherData');
|
const clearWeatherData = require('./clearWeatherData');
|
||||||
const Sockets = require('../Sockets');
|
const Sockets = require('../Sockets');
|
||||||
const Logger = require('./Logger');
|
const Logger = require('./Logger');
|
||||||
|
const loadConfig = require('./loadConfig');
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
|
|
||||||
// Update weather data every 15 minutes
|
// Update weather data every 15 minutes
|
||||||
const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async () => {
|
const weatherJob = schedule.scheduleJob(
|
||||||
|
'updateWeather',
|
||||||
|
'0 */15 * * * *',
|
||||||
|
async () => {
|
||||||
|
const { WEATHER_API_KEY: secret } = await loadConfig();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const weatherData = await getExternalWeather();
|
const weatherData = await getExternalWeather();
|
||||||
logger.log('Weather updated');
|
logger.log('Weather updated');
|
||||||
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
|
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (secret) {
|
||||||
logger.log(err.message, 'ERROR');
|
logger.log(err.message, 'ERROR');
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Clear old weather data every 4 hours
|
// Clear old weather data every 4 hours
|
||||||
const weatherCleanerJob = schedule.scheduleJob('clearWeather', '0 5 */4 * * *', async () => {
|
const weatherCleanerJob = schedule.scheduleJob(
|
||||||
|
'clearWeather',
|
||||||
|
'0 5 */4 * * *',
|
||||||
|
async () => {
|
||||||
clearWeatherData();
|
clearWeatherData();
|
||||||
})
|
}
|
||||||
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue