connecting to remote mysql db, saving market alerts

This commit is contained in:
egradanin
2019-01-19 16:53:27 +01:00
parent 3cebd722fd
commit 18032c6ca6
12 changed files with 487 additions and 24 deletions

View File

@@ -1,7 +1,11 @@
import React from "react";
import Select from "react-select";
import { connect } from "react-redux";
import { CATEGORY_SELECT, ITEMS_CHANGED } from "constants/actionTypes";
import {
CATEGORY_SELECT,
ITEMS_CHANGED,
USER_DATA_CHANGED
} from "constants/actionTypes";
import { hoc, areObjectEqual } from "utils/helpers";
import { createOlxLink } from "utils/createOlxLink";
import axios from "axios";
@@ -23,13 +27,15 @@ const mapStateToProps = state => {
category: state.category,
options: state.options,
subcategory: state.subcategory,
items: state.items
items: state.items,
userdata: state.userdata
};
};
const mapDispatchToProps = dispatch => ({
onCategoryChanged: option => dispatch({ type: CATEGORY_SELECT, option }),
onItemsChanged: items => dispatch({ type: ITEMS_CHANGED, items })
onItemsChanged: items => dispatch({ type: ITEMS_CHANGED, items }),
onUserDataChange: change => dispatch({ type: USER_DATA_CHANGED, ...change })
});
let lastUpdateTime = null;
@@ -38,13 +44,26 @@ class App extends React.Component {
componentDidMount() {
interval = setInterval(() => {
if (lastUpdateTime && Date.now() - lastUpdateTime > 2000) {
const { category, options, subcategory, onItemsChanged } = this.props;
const {
category,
options,
subcategory,
onItemsChanged,
onUserDataChange
} = this.props;
let url = createOlxLink(category, subcategory, options);
url = encodeURI(url);
onUserDataChange({ info: "olx_url", value: url });
if (url) {
axios
.get(`/api/${url}`)
.then(response => onItemsChanged(response.data))
.then(response => {
onItemsChanged(response.data.items);
onUserDataChange({
info: "last_date",
value: response.data.last_date
});
})
.catch(error => console.log(error));
}
lastUpdateTime = null;
@@ -84,7 +103,6 @@ class App extends React.Component {
Nekretnine: <DeepCategoryWrapper {...Nekretnine.properties} />
})}
<ItemsContainer />
<NotificationModal />
{items.length ? <NotificationModal /> : null}
</div>
);