Skip to content

Commit

Permalink
Update favs on favsChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Oct 29, 2021
1 parent 5e992d9 commit fcbe8c4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/actions/sounding.js
Expand Up @@ -16,7 +16,7 @@ export const SET_HEIGHT = "SDG.SET_HEIGHT";
export const SET_METRIC_TEMP = "SDG.SET_METRIC_TEMP";
export const SET_METRIC_ALTITUDE = "SDG.SET_METRIC_ALTITUDE";
export const SET_METRIC_SPEED = "SDG.SET_METRIC_SPEED";
export const ADD_FAVORITE = "SDG.ADD_FAVORITE";
export const SET_FAVORITES = "SDG.SET_FAVORITES";
export const FETCH_PARAMS = "SDG.FETCH_PARAMS";
export const RECEIVE_PARAMS = "SDG.RECEIVE_PARAMS";
export const TOGGLE_ZOOM = "SDG.TOGGLE_ZOOM";
Expand All @@ -30,9 +30,9 @@ export const toggleZoom = () => ({
type: TOGGLE_ZOOM,
});

export const addFavorite = (favorite) => ({
type: ADD_FAVORITE,
payload: favorite,
export const setFavorites = (favorites) => ({
type: SET_FAVORITES,
payload: favorites,
});

export const setMetricTemp = (metric) => ({
Expand Down
8 changes: 7 additions & 1 deletion src/plugin.js
Expand Up @@ -3,6 +3,7 @@ import {
cancelSubscriptions,
removeMarker,
setActive,
setFavorites,
setLocation,
setModelName,
setTime,
Expand All @@ -23,6 +24,7 @@ import pluginHtml from "./plugin.html";
const windyMap = W.require("map").map || W.require("map");
const windyRootScope = W.require("rootScope");
const windyUtils = W.require("utils");
const windyFavs = W.require("favs");

W.loadPlugin(
/* eslint-disable */
Expand Down Expand Up @@ -125,14 +127,18 @@ W.loadPlugin(
const pickerOpened = windyPicker.on("pickerOpened", ({ lat, lon }) => {
store.dispatch(setLocation(lat, lon));
});

store.dispatch(addSubscription(() => windyPicker.off(pickerOpened)));

const pickerMoved = windyPicker.on("pickerMoved", ({ lat, lon }) => {
store.dispatch(setLocation(lat, lon));
});
store.dispatch(addSubscription(() => windyPicker.off(pickerMoved)));

const favsChanged = windyFavs.on("favsChanged", () => {
store.dispatch(setFavorites(windyFavs.getArray()));
});
store.dispatch(addSubscription(() => windyFavs.off(favsChanged)));

store.dispatch(setActive(true));
}

Expand Down
6 changes: 3 additions & 3 deletions src/reducers/sounding.js
@@ -1,14 +1,14 @@
import * as atm from "../atmosphere";

import {
ADD_FAVORITE,
ADD_SUBSCRIPTION,
DELETE_SUBSCRIPTION,
FETCH_PARAMS,
MOVE_MARKER,
RECEIVE_PARAMS,
REMOVE_MARKER,
SET_ACTIVE,
SET_FAVORITES,
SET_HEIGHT,
SET_LOCATION,
SET_METRIC_ALTITUDE,
Expand Down Expand Up @@ -92,8 +92,8 @@ function plugin(state = { subscriptions: [], favorites: [], zoom: true }, action
return { ...state, width: action.payload };
case SET_HEIGHT:
return { ...state, height: action.payload };
case ADD_FAVORITE: {
return { ...state, favorites: [...state.favorites, action.payload] };
case SET_FAVORITES: {
return { ...state, favorites: [...action.payload] };
}
case TOGGLE_ZOOM:
return { ...state, zoom: !state.zoom };
Expand Down
2 changes: 1 addition & 1 deletion src/selectors/sounding.js
Expand Up @@ -231,7 +231,7 @@ export const wheelHandler = createSelector(updateTime, (updateTime) => (e) => {
const changeDay = e.shiftKey || e.ctrlKey;
const direction = Math.sign(e.deltaY);
updateTime({ direction, changeDay });
nextWheelMove = Date.now() + (changeDay ? 800 : 100);
nextWheelMove = Date.now() + (changeDay ? 800 : 20);
}
e.stopPropagation();
e.preventDefault();
Expand Down
7 changes: 0 additions & 7 deletions src/store.js
Expand Up @@ -9,7 +9,6 @@ import thunk from "redux-thunk";
// TODO: remove `W.require("$")` after the TS windy API is released.
const $ = W.require("utils").$ || W.require("$");
const windyStore = W.require("store");
const favorites = W.require("favs");

let store;

Expand All @@ -32,12 +31,6 @@ export function getStore() {

updateMetrics(store);

setTimeout(() => {
favorites.getArray().forEach((f) => {
store.dispatch(soundingAct.addFavorite(f));
});
}, 1000);

store.dispatch(skewTAct.setPMin(400));

return store;
Expand Down

0 comments on commit fcbe8c4

Please sign in to comment.