homeflowjs 0.13.62 → 0.13.64

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.
@@ -1,4 +1,4 @@
1
- /* eslint-disable import/no-cycle */
1
+ /* eslint-disable import/no-cycle, no-undef */
2
2
  import PropertiesActionTypes from './properties.types';
3
3
  import { buildQueryString } from '../search/property-search/property-search';
4
4
  import { setSearch } from './search.actions';
@@ -115,6 +115,33 @@ export const setPagination = (payload) => ({
115
115
  payload,
116
116
  });
117
117
 
118
+ export const postPropertyView = (payload) => () => {
119
+ const domain = location.hostname;
120
+ fetch('/property_views',
121
+ {
122
+ method: 'POST',
123
+ mode: 'no-cors',
124
+ headers: { 'Content-Type': 'application/json' },
125
+ body: JSON.stringify({ property_id: payload, domain }),
126
+ });
127
+ };
128
+
129
+ export const postBulkPropertyExposureCreation = (payload) => () => {
130
+ const domain = location.hostname;
131
+ const exposuresPublicUrl = Homeflow.get('exposures_public_url');
132
+
133
+ if (!exposuresPublicUrl) return;
134
+
135
+ const { propertyIds, eventType } = payload;
136
+ fetch(`${exposuresPublicUrl}/create_many`,
137
+ {
138
+ method: 'POST',
139
+ mode: 'no-cors',
140
+ headers: { 'Content-Type': 'application/json' },
141
+ body: JSON.stringify({ property_ids: propertyIds, domain, event_type: eventType }),
142
+ });
143
+ };
144
+
118
145
  export const loadNext = () => (dispatch, getState) => {
119
146
  dispatch(setLoading({ properties: true }));
120
147
  // set page on search to page + 1
@@ -126,6 +153,13 @@ export const loadNext = () => (dispatch, getState) => {
126
153
  .then((response) => response.json())
127
154
  .then((json) => {
128
155
  if (json.properties) {
156
+ // post new property ids
157
+ dispatch(
158
+ postBulkPropertyExposureCreation({
159
+ eventType: 'SearchResult',
160
+ propertyIds: json.properties.map((property) => property.property_id),
161
+ }),
162
+ );
129
163
  // add the page number to each new property for dividing properties into per-page divs
130
164
  const addedProperties = json.properties.map((property) => (
131
165
  { ...property, resultPage: newSearch.page }
@@ -12,7 +12,12 @@ import bookingCalendar from '../booking-calendar/booking-calendar';
12
12
  import { setThemePreferences, setThemeSettings, setAuthenticityToken } from '../actions/app.actions';
13
13
  import { fetchUser } from '../actions/user.actions';
14
14
  import {
15
- setProperties, setPagination, setProperty, setPropertyLinksAsync,
15
+ setProperties,
16
+ setPagination,
17
+ setProperty,
18
+ setPropertyLinksAsync,
19
+ postPropertyView,
20
+ postBulkPropertyExposureCreation,
16
21
  } from '../actions/properties.actions';
17
22
  import {
18
23
  setSearch, setInitialSearch, setSearchField, setPlace,
@@ -98,9 +103,21 @@ const hfInitialize = () => {
98
103
 
99
104
  const pageRoute = Homeflow.get('page_route');
100
105
 
101
- // if we're on the property show page, set next and previous links
106
+ // if we're on the property show page: 1. set next and previous links, 2. post property view
102
107
  if (pageRoute === 'properties#show') {
108
+ const propertyId = Homeflow.get('property')?.property_id;
103
109
  store.dispatch(setPropertyLinksAsync());
110
+ store.dispatch(postPropertyView(propertyId));
111
+ }
112
+
113
+ if (pageRoute === 'properties#index') {
114
+ const propertyIds = Homeflow.get('properties')?.map((property) => property.property_id);
115
+ store.dispatch(
116
+ postBulkPropertyExposureCreation({
117
+ eventType: 'SearchResult',
118
+ propertyIds,
119
+ }),
120
+ );
104
121
  }
105
122
 
106
123
  // setting articles, pagination and topics on articles index page
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.13.62",
3
+ "version": "0.13.64",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import React, { useEffect, useRef, useMemo } from 'react';
2
2
  import { connect, useSelector } from 'react-redux';
3
3
  import PropTypes from 'prop-types';
4
4
 
@@ -73,10 +73,24 @@ const PropertiesDisplay = ({
73
73
  const insertsAvailable = Array.isArray(inserts) && inserts.length > 0;
74
74
  const insertsFrequency =
75
75
  insertsAvailable && inserts[0]?.frequency > 0 ? inserts[0].frequency : null;
76
- const insertsIndexMap =
77
- insertsAvailable && inserts.some((insert) => insert?.index >= 0)
78
- ? inserts.reduce((acc, { index }) => [...acc, index], [])
76
+
77
+ const { propertiesInsertsMap, insertablePropertiesIDList } = useMemo(() => {
78
+ const propertiesLength = properties.length;
79
+ const validInserts = insertsAvailable
80
+ ? inserts.filter(({ index }) => index >= 0 && index < propertiesLength)
79
81
  : null;
82
+ if (validInserts) {
83
+ const propertiesInsertsMap = new Map();
84
+ for (const insert of validInserts) {
85
+ const property = properties[insert.index];
86
+ propertiesInsertsMap.set(property.property_id, insert);
87
+ };
88
+ const insertablePropertiesIDList = Array.from(propertiesInsertsMap.keys());
89
+
90
+ return { propertiesInsertsMap, insertablePropertiesIDList };
91
+ }
92
+ return {};
93
+ }, [properties]);
80
94
 
81
95
  const items = propertiesByPage(properties, propertiesPagination).map((page, i) => (
82
96
  <ConditionalWrapper
@@ -96,15 +110,18 @@ const PropertiesDisplay = ({
96
110
  * TODO: Allow for multiple inserts
97
111
  * This code only allows one insert from the inserts array to be show at a time
98
112
  */
99
- if (insertsFrequency && (index % insertsFrequency) === 0 && index !== 0) {
113
+ if (insertsFrequency && index % insertsFrequency === 0 && index !== 0) {
100
114
  return (
101
115
  <React.Fragment key={property.property_id}>
102
116
  {inserts[0].component}
103
117
  <Item property={property} {...other} />
104
118
  </React.Fragment>
105
119
  );
106
- } else if (insertsIndexMap && insertsIndexMap.includes(index)) {
107
- const findResult = inserts.find(insert => insert?.index === index);
120
+ } else if (
121
+ insertablePropertiesIDList?.length &&
122
+ insertablePropertiesIDList.includes(property.property_id)
123
+ ) {
124
+ const findResult = propertiesInsertsMap.get(property.property_id);
108
125
  if (findResult) {
109
126
  return (
110
127
  <React.Fragment key={property.property_id}>
@@ -113,7 +130,7 @@ const PropertiesDisplay = ({
113
130
  </React.Fragment>
114
131
  );
115
132
  }
116
- }
133
+ }
117
134
 
118
135
  return (
119
136
  <Item