homeflowjs 0.9.34 → 0.9.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js CHANGED
@@ -4,6 +4,7 @@ module.exports = {
4
4
  fetch: 'readonly',
5
5
  Homeflow: 'readonly',
6
6
  document: 'readonly',
7
+ location: 'readonly',
7
8
  FormData: 'readonly',
8
9
  window: 'readonly',
9
10
  describe: 'readonly',
package/README.md CHANGED
@@ -69,5 +69,5 @@ This is a known issue with peer dependencies, see this comment and containing th
69
69
 
70
70
  ## Deploy
71
71
 
72
- To create a new version of HomeflowJS when merging to master, keep an eye on the Jenkins build, it pauses and waits for publish confirmation where you can enter the new version number and publish:
72
+ To create a new version of HomeflowJS when merging to master, keep an eye on the Jenkins build, it pauses and waits for publish confirmation where you can enter the new version number and publish.
73
73
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-cycle */
1
2
  import UserActionTypes from './user.types';
2
3
  import { fetchSavedProperties, setSavedProperties } from './properties.actions';
3
4
  import { fetchSavedSearches, setSavedSearches } from './search.actions';
@@ -153,11 +154,15 @@ export const signOutUser = () => (dispatch) => (
153
154
  fetch('/session', {
154
155
  method: 'DELETE',
155
156
  })
156
- .then(() => {
157
- dispatch(setCurrentUser(INITIAL_USER_DATA));
158
- dispatch(setLocalUser(INITIAL_USER_DATA));
159
- dispatch(setUserCredentials({ email: '', password: '' }));
160
- dispatch(setSavedProperties([]));
161
- dispatch(setSavedSearches([]));
157
+ .then((response) => {
158
+ if (response.ok) {
159
+ dispatch(setCurrentUser(INITIAL_USER_DATA));
160
+ dispatch(setLocalUser(INITIAL_USER_DATA));
161
+ dispatch(setUserCredentials({ email: '', password: '' }));
162
+ dispatch(setSavedProperties([]));
163
+ dispatch(setSavedSearches([]));
164
+ }
165
+
166
+ return response.ok;
162
167
  })
163
168
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.9.34",
3
+ "version": "0.9.36",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect } from 'react';
1
+ import React from 'react';
2
2
  import { useDispatch, useSelector } from 'react-redux';
3
3
  import { Checkbox } from 'pretty-checkbox-react';
4
4
 
@@ -37,34 +37,38 @@ const NormalCheckBox = ({
37
37
  };
38
38
 
39
39
  const StatusCheckbox = (props) => {
40
- const { pretty, value, uncheckedValue } = props;
41
-
42
- const dispatch = useDispatch();
43
-
44
40
  const defaultSearchStatus = useSelector((state) => state.app.themePreferences.defaultSearchStatus || 'all');
45
41
  const currentSearchStatus = useSelector((state) => state.search.currentSearch.status);
46
42
 
47
- const calculateChecked = () => {
48
- // if no current status then checked if value matches default
49
- if (currentSearchStatus && currentSearchStatus === value) return true;
43
+ const { pretty, value: propValue, uncheckedValue: propUncheckedValue } = props;
50
44
 
51
- if (currentSearchStatus) return false;
45
+ const calculateValue = (thisValue, otherValue, defaultValue) => {
46
+ if (thisValue) return thisValue;
47
+ if (otherValue !== defaultValue) return defaultValue;
52
48
 
53
- // when there is no status set
54
- return value === defaultSearchStatus;
55
- };
49
+ // The other option is the default value and this one is not provided so this one is opposite of default
50
+ return defaultValue === 'all' ? 'available' : 'all';
51
+ }
52
+
53
+ const value = calculateValue(propValue, propUncheckedValue, defaultSearchStatus);
54
+ const uncheckedValue = calculateValue(propUncheckedValue, propValue, defaultSearchStatus);
56
55
 
57
- const [checked, setChecked] = useState(calculateChecked());
56
+ const dispatch = useDispatch();
58
57
 
59
- useEffect(() => {
60
- setChecked(calculateChecked());
61
- }, [defaultSearchStatus, currentSearchStatus]);
58
+ const calculateChecked = () => {
59
+ if (typeof currentSearchStatus !== 'undefined') {
60
+ if (currentSearchStatus === value) return true;
61
+ if (currentSearchStatus === uncheckedValue) return false;
62
+ }
62
63
 
63
- const handleChange = (e) => {
64
- const newValue = checked ? (uncheckedValue || '') : value;
64
+ return value === defaultSearchStatus; // Unknown search status make checkbox be default
65
+ };
66
+
67
+ const checked = calculateChecked();
65
68
 
69
+ const handleChange = (e) => {
70
+ const newValue = checked ? uncheckedValue : value;
66
71
  dispatch(setSearchField({ status: newValue === defaultSearchStatus ? '' : newValue }));
67
- setChecked(calculateChecked());
68
72
  };
69
73
 
70
74
  if (pretty) return <PrettyCheckBox {...props} handleChange={handleChange} checked={checked} />;
@@ -1,23 +1,39 @@
1
1
  import React from 'react';
2
+ import { useHistory } from 'react-router-dom';
2
3
  import { connect } from 'react-redux';
3
4
  import PropTypes from 'prop-types';
4
5
 
5
6
  import { signOutUser } from '../../actions/user.actions';
6
7
  import notify from '../../app/notify';
7
8
 
8
- const SignOutButton = ({ signOutUser, children, ...otherProps }) => (
9
- <button
10
- type="button"
11
- onClick={(e) => {
12
- e.preventDefault();
13
- signOutUser()
14
- .then(() => notify('You have been signed out', 'success'));
15
- }}
16
- {...otherProps}
17
- >
18
- {children}
19
- </button>
20
- );
9
+ const SignOutButton = ({
10
+ signOutUser, pushHistory, reload, children, ...otherProps
11
+ }) => {
12
+ const history = useHistory();
13
+ const handleClick = (e) => {
14
+ e.preventDefault();
15
+ signOutUser()
16
+ .then((success) => {
17
+ if (success) {
18
+ notify('You have been signed out', 'success');
19
+ if (pushHistory) history.push('/');
20
+ if (reload) location.reload(false);
21
+ } else {
22
+ notify('There was an error signing out', 'error');
23
+ }
24
+ });
25
+ };
26
+
27
+ return (
28
+ <button
29
+ type="button"
30
+ onClick={(e) => handleClick(e)}
31
+ {...otherProps}
32
+ >
33
+ {children}
34
+ </button>
35
+ );
36
+ };
21
37
 
22
38
  SignOutButton.propTypes = {
23
39
  signOutUser: PropTypes.func.isRequired,
@@ -25,6 +41,13 @@ SignOutButton.propTypes = {
25
41
  PropTypes.element,
26
42
  PropTypes.string,
27
43
  ]).isRequired,
44
+ pushHistory: PropTypes.bool,
45
+ reload: PropTypes.bool,
46
+ };
47
+
48
+ SignOutButton.defaultProps = {
49
+ pushHistory: false,
50
+ reload: false,
28
51
  };
29
52
 
30
53
  const mapDispatchToProps = {