homeflowjs 0.9.8 → 0.9.11

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/README.md CHANGED
@@ -12,6 +12,7 @@ Please see the [HomeflowJS developer documentation](https://developer.homeflow.c
12
12
 
13
13
  To work on this package locally, use `yarn link` to link the theme directly to your local copy of homeflowjs (or just specify `file:~/projects/homeflowjs` in the theme's `package.json` file).
14
14
 
15
+
15
16
  Make sure you have cache disabled in Webpack or your changes to HomeflowJS may not be updated locally. You can set this in your Webpack config in whichever theme you are using for testing:
16
17
 
17
18
  ```
@@ -57,7 +57,7 @@ const hfInitialize = () => {
57
57
  if (hash.includes('flash/')) {
58
58
  const flash = hash.split('flash/')[1];
59
59
  const message = Homeflow.get(`flash-message-${flash}`);
60
- const type = hashTypes[flash];
60
+ const type = flash.includes('error') ? 'error' : hashTypes[flash];
61
61
 
62
62
  notify(message, type, { duration: 10000 });
63
63
  }
package/app/notify.js CHANGED
@@ -6,7 +6,20 @@ import { sanitizeText } from '../utils/index';
6
6
  const notify = (message, type, config = {}) => {
7
7
  if (!message) return;
8
8
 
9
+ const customStyle = Homeflow.get('custom_toastify_styles') || null;
9
10
  const color = { error: '#dc3545' }[type] || '#28a745'; // default is success
11
+ let className = '';
12
+ let style = { background: color };
13
+
14
+ if (type === 'error' && customStyle !== null) {
15
+ className = `${customStyle.className} ${customStyle.className}-error`;
16
+ style = { ...customStyle.error };
17
+ }
18
+
19
+ if (type === 'success' && customStyle !== null) {
20
+ className = `${customStyle.className} ${customStyle.className}-success`;
21
+ style = { ...customStyle.success };
22
+ }
10
23
 
11
24
  Toastify({
12
25
  duration: 3000,
@@ -16,7 +29,8 @@ const notify = (message, type, config = {}) => {
16
29
  stopOnFocus: true,
17
30
  text: sanitizeText(message),
18
31
  escapeMarkup: false,
19
- style: { background: color },
32
+ className,
33
+ style,
20
34
  ...config,
21
35
  }).showToast();
22
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.9.8",
3
+ "version": "0.9.11",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
  import { connect } from 'react-redux';
3
3
 
4
+ import PropTypes from 'prop-types';
5
+
4
6
  import { addSavedProperty, removeSavedProperty } from '../../actions/properties.actions';
5
7
  import notify from '../../app/notify';
6
8
 
@@ -14,9 +16,10 @@ const SavePropertyButton = (props) => {
14
16
  addSavedProperty,
15
17
  removeSavedProperty,
16
18
  style,
19
+ notificationMessage,
17
20
  } = props;
18
21
 
19
- const isSaved = !!savedProperties.find(p => p.property_id === parseInt(propertyId, 10));
22
+ const isSaved = !!savedProperties.find((p) => p.property_id === parseInt(propertyId, 10));
20
23
 
21
24
  const toggleProperty = (e) => {
22
25
  e.preventDefault();
@@ -24,14 +27,15 @@ const SavePropertyButton = (props) => {
24
27
 
25
28
  if (isSaved) {
26
29
  removeSavedProperty(propertyId);
27
- notify('Saved property removed.', 'success');
30
+ notify(notificationMessage || 'Saved property removed.', 'success');
28
31
  } else {
29
32
  addSavedProperty(propertyId);
30
- notify('Property saved.', 'success');
33
+ notify(notificationMessage || 'Property saved.', 'success');
31
34
  }
32
35
  };
33
36
 
34
37
  return (
38
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/anchor-is-valid
35
39
  <a
36
40
  style={style}
37
41
  onClick={toggleProperty}
@@ -42,8 +46,23 @@ const SavePropertyButton = (props) => {
42
46
  );
43
47
  };
44
48
 
49
+ SavePropertyButton.propTypes = {
50
+ propertyId: PropTypes.number.isRequired,
51
+ savedProperties: PropTypes.array,
52
+ notificationMessage: PropTypes.string,
53
+ className: PropTypes.string,
54
+ style: PropTypes.object,
55
+ UnsavedComponent: PropTypes.element.isRequired,
56
+ SavedComponent: PropTypes.element.isRequired,
57
+ addSavedProperty: PropTypes.func.isRequired,
58
+ removeSavedProperty: PropTypes.func.isRequired,
59
+ };
60
+
45
61
  SavePropertyButton.defaultProps = {
46
62
  savedProperties: [],
63
+ notificationMessage: null,
64
+ className: '',
65
+ style: {},
47
66
  };
48
67
 
49
68
  const mapStateToProps = (state) => ({
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
  import { connect } from 'react-redux';
3
3
 
4
+ import PropTypes from 'prop-types';
5
+
4
6
  import { addSavedSearchAsync, removeSavedSearchAsync } from '../../actions/search.actions';
5
7
  import { findSavedSearch } from '../../utils';
6
8
  import notify from '../../app/notify';
@@ -9,12 +11,14 @@ const SaveSearchButton = (props) => {
9
11
  const {
10
12
  search,
11
13
  className,
12
- savedSearches = [],
14
+ savedSearches,
13
15
  UnsavedComponent,
14
16
  SavedComponent,
15
17
  addSavedSearchAsync,
16
18
  removeSavedSearchAsync,
17
19
  style,
20
+ notificationMessage,
21
+ showNotification,
18
22
  } = props;
19
23
 
20
24
  const savedSearch = findSavedSearch(savedSearches, search);
@@ -22,17 +26,17 @@ const SaveSearchButton = (props) => {
22
26
  const toggleSearch = (e) => {
23
27
  e.preventDefault();
24
28
 
25
-
26
29
  if (savedSearch) {
27
30
  removeSavedSearchAsync(savedSearch);
28
- notify('Saved search removed.', 'success');
31
+ notify((showNotification && notificationMessage) ? notificationMessage : 'Saved search removed.', 'success');
29
32
  } else {
30
33
  addSavedSearchAsync(search);
31
- notify('Search saved.', 'success');
34
+ notify(notificationMessage || 'Search saved.', 'success');
32
35
  }
33
- }
36
+ };
34
37
 
35
38
  return (
39
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/anchor-is-valid
36
40
  <a
37
41
  style={style}
38
42
  onClick={toggleSearch}
@@ -43,7 +47,28 @@ const SaveSearchButton = (props) => {
43
47
  );
44
48
  };
45
49
 
46
- const mapStateToProps = state => ({
50
+ SaveSearchButton.propTypes = {
51
+ search: PropTypes.object.isRequired,
52
+ className: PropTypes.string,
53
+ savedSearches: PropTypes.array,
54
+ UnsavedComponent: PropTypes.element.isRequired,
55
+ SavedComponent: PropTypes.element.isRequired,
56
+ addSavedSearchAsync: PropTypes.func.isRequired,
57
+ removeSavedSearchAsync: PropTypes.func.isRequired,
58
+ style: PropTypes.object,
59
+ notificationMessage: PropTypes.string,
60
+ showNotification: PropTypes.bool,
61
+ };
62
+
63
+ SaveSearchButton.defaultProps = {
64
+ savedSearches: [],
65
+ notificationMessage: null,
66
+ className: '',
67
+ style: {},
68
+ showNotification: false,
69
+ };
70
+
71
+ const mapStateToProps = (state) => ({
47
72
  search: state.search.currentSearch,
48
73
  savedSearches: state.search.savedSearches,
49
74
  });