@@ -109,10 +90,21 @@ class ResultList extends Component {
}
}
+ResultList.propTypes = {
+ currentPos: PropTypes.object.isRequired,
+ savedResources: PropTypes.array.isRequired,
+ actions: PropTypes.object.isRequired,
+ saveItem: PropTypes.func,
+};
+
+ResultList.defaultProps = {
+ saveItem: null,
+};
+
function mapStateToProps(state) {
return {
- savedResource:
- state.savedResource.length > 0 ? state.savedResource : state.resource,
+ savedResources:
+ state.savedResources.length > 0 ? state.savedResources : state.resources,
};
}
diff --git a/src/components/MapPage/SplitScreenSlidingPane.js b/src/components/MapPage/SplitScreenSlidingPane.js
index 5ed6db52..7f6e57d8 100644
--- a/src/components/MapPage/SplitScreenSlidingPane.js
+++ b/src/components/MapPage/SplitScreenSlidingPane.js
@@ -5,10 +5,6 @@ import PropTypes from "prop-types";
import cx from "classnames";
class SplitScreenSlidingPane extends Component {
- static propTypes = {
- children: PropTypes.element.isRequired,
- };
-
state = {
isOpen: true,
};
@@ -35,4 +31,8 @@ class SplitScreenSlidingPane extends Component {
}
}
+SplitScreenSlidingPane.propTypes = {
+ children: PropTypes.element.isRequired,
+};
+
export default SplitScreenSlidingPane;
diff --git a/src/components/SavedResources/SavedResource.js b/src/components/SavedResources/SavedResource.js
index daa0aa31..72ff092c 100644
--- a/src/components/SavedResources/SavedResource.js
+++ b/src/components/SavedResources/SavedResource.js
@@ -4,7 +4,6 @@ import { connect } from "react-redux";
import { bindActionCreators, compose } from "redux";
import { withRouter } from "react-router";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import qs from "qs-lite";
import {
Alert,
Card,
@@ -13,31 +12,17 @@ import {
ModalHeader,
ModalBody,
} from "reactstrap";
+import { getQueryResources, encodeResources } from "../../utils/resourcesQuery";
import getDistance from "../../utils/distance";
import * as resourceAction from "../../action/resourceDataAction";
import SavedResourceButton from "./SavedResourceButton";
class SavedResource extends Component {
- static propTypes = {
- organization: PropTypes.object.isRequired,
- savedResource: PropTypes.array.isRequired,
- actions: PropTypes.object.isRequired,
- history: PropTypes.object.isRequired,
- currentPos: PropTypes.object,
+ state = {
+ visible: false,
};
- static defaultProps = {
- currentPos: null,
- };
-
- constructor(props) {
- super(props);
- this.state = {
- visible: false,
- };
- }
-
confirmationAlertToggle = () => {
this.setState(prevState => ({ visible: !prevState.visible }));
};
@@ -47,17 +32,11 @@ class SavedResource extends Component {
};
removalConfirmed = () => {
- const query = qs.parse(window.location.search.replace("?", ""));
- let resources = [];
-
- if (query.resources) {
- resources = query.resources.split(",");
- }
-
+ const resources = getQueryResources();
const indexOfResource = resources.indexOf(this.props.organization.id);
if (
- this.props.savedResource.some(
+ this.props.savedResources.some(
resource => resource.id === this.props.organization.id
)
) {
@@ -67,7 +46,7 @@ class SavedResource extends Component {
this.props.history.push({
pathname: window.location.pathname,
- search: `?resources=${resources.join(",")}`,
+ search: encodeResources(resources),
});
this.removeItem();
};
@@ -198,8 +177,20 @@ class SavedResource extends Component {
}
}
+SavedResource.propTypes = {
+ organization: PropTypes.object.isRequired,
+ savedResources: PropTypes.array.isRequired,
+ actions: PropTypes.object.isRequired,
+ history: PropTypes.object.isRequired,
+ currentPos: PropTypes.object,
+};
+
+SavedResource.defaultProps = {
+ currentPos: null,
+};
+
function mapStateToProps(state) {
- return { savedResource: state.savedResource };
+ return { savedResources: state.savedResources };
}
function mapDispatchToProps(dispatch) {
diff --git a/src/components/SavedResources/SavedResourcePanel.js b/src/components/SavedResources/SavedResourcePanel.js
index 4f2f2167..037884c2 100644
--- a/src/components/SavedResources/SavedResourcePanel.js
+++ b/src/components/SavedResources/SavedResourcePanel.js
@@ -1,28 +1,23 @@
import React from "react";
-import qs from "qs-lite";
import { Link, Route } from "react-router-dom";
import { Button } from "reactstrap";
import PropTypes from "prop-types";
import { faShare } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { getQueryResources, encodeResources } from "../../utils/resourcesQuery";
import SavedResources from "./SavedResourcesContainer";
const ToShareButton = ({ resourcePath }) => {
- const query = qs.parse(window.location.search.replace("?", ""));
- let resources = [];
- let tempUrl = "";
-
- if (query.resources) {
- resources = query.resources.split(",");
- tempUrl = `/${resourcePath}/?resources=${resources.join(",")}`;
- }
+ const resources = getQueryResources();
+ const query = encodeResources(resources);
+ const url = query && `/${resourcePath}/?${query}`;
return (