do not create a whats new if an open whats [x] already exists
do not create a whats around if an open whats around already exists
@@ -64,7 +64,13 @@ export function createWhatsNew() {
const state = getState();
const nodeUri = getIn(state, ["config", "defaultNodeUri"]);
const defaultContext = getIn(state, ["config", "theme", "defaultContext"]);
+ const openWhatsXNeeds = getIn(state, ["needs"]).filter(
+ need =>
+ need.get("state") === "won:Active" &&
+ (need.get("isWhatsAround") || need.get("isWhatsNew"))
+ );
+ if (openWhatsXNeeds.size == 0) {
const whatsNew = {
title: "What's New?",
type: "http://purl.org/webofneeds/model#DoTogether",
@@ -82,17 +88,10 @@ export function createWhatsNew() {
seeks: whatsNew,
};
- getIn(state, ["needs"])
- .filter(
- need =>
- need.get("state") === "won:Active" &&
- (need.get("isWhatsAround") || need.get("isWhatsNew"))
- )
- .map(need => {
- dispatch(actionCreators.needs__close(need.get("uri")));
- });
-
dispatch(actionCreators.needs__create(whatsNewObject, nodeUri));
+ } else {
+ console.log("WhatsXNeed already exists, we will not create a new one");
+ }
};
}
@@ -102,6 +101,9 @@ export function createWhatsAround() {
const state = getState();
const nodeUri = getIn(state, ["config", "defaultNodeUri"]);
const defaultContext = getIn(state, ["config", "theme", "defaultContext"]);
+ const openWhatsAroundNeeds = getIn(state, ["needs"]).filter(
+ need => need.get("state") === "won:Active" && need.get("isWhatsAround")
+ );
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(
@@ -110,8 +112,7 @@ export function createWhatsAround() {
const lng = currentLocation.coords.longitude;
const zoom = 13; // TODO use `currentLocation.coords.accuracy` to control coarseness of query / zoom-level
- // center map around current location
-
+ if (openWhatsAroundNeeds.size == 0) {
reverseSearchNominatim(lat, lng, zoom).then(searchResult => {
const location = nominatim2draftLocation(searchResult);
let whatsAround = {
@@ -129,8 +130,7 @@ export function createWhatsAround() {
getIn(state, ["needs"])
.filter(
need =>
- need.get("state") === "won:Active" &&
- (need.get("isWhatsAround") || need.get("isWhatsNew"))
+ need.get("state") === "won:Active" && need.get("isWhatsNew")
)
.map(need => {
dispatch(actionCreators.needs__close(need.get("uri")));
@@ -140,8 +140,15 @@ export function createWhatsAround() {
seeks: whatsAround,
};
- dispatch(actionCreators.needs__create(whatsAroundObject, nodeUri));
+ dispatch(
+ actionCreators.needs__create(whatsAroundObject, nodeUri)
+ );
});
+ } else {
+ console.log(
+ "WhatsAroundNeed already exists, we will not create a new one"
+ );
+ }
},
error => {
//error handler
