Skip to content

Commit

Permalink
Add alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
oktapodia committed Jun 14, 2018
1 parent 6aca37e commit c741dcd
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 79 deletions.
3 changes: 0 additions & 3 deletions .eslintrc
Expand Up @@ -14,7 +14,6 @@
"compat/compat": "error",
"consistent-return": "off",
"comma-dangle": "off",
"flowtype-errors/show-errors": "error",
"generator-star-spacing": "off",
"import/no-unresolved": "error",
"import/no-extraneous-dependencies": "off",
Expand Down Expand Up @@ -45,8 +44,6 @@
"react/prefer-stateless-function": "off"
},
"plugins": [
"flowtype",
"flowtype-errors",
"import",
"promise",
"compat",
Expand Down
45 changes: 0 additions & 45 deletions app/.eslintrc
@@ -1,49 +1,4 @@
{
"rules": {
"flowtype/boolean-style": [
2,
"boolean"
],
"flowtype/define-flow-type": 1,
"flowtype/delimiter-dangle": [
2,
"never"
],
"flowtype/generic-spacing": [
2,
"never"
],
"flowtype/no-primitive-constructor-types": 2,
"flowtype/no-weak-types": 1,
"flowtype/object-type-delimiter": [
2,
"comma"
],
"flowtype/require-parameter-type": 0,
"flowtype/require-return-type": 0,
"flowtype/require-valid-file-annotation": 0,
"flowtype/semi": [
2,
"always"
],
"flowtype/space-after-type-colon": [
2,
"always"
],
"flowtype/space-before-generic-bracket": [
2,
"never"
],
"flowtype/space-before-type-colon": [
2,
"never"
],
"flowtype/union-intersection-spacing": [
2,
"always"
],
"flowtype/use-flow-type": 2,
"flowtype/valid-syntax": 2,
"flowtype-errors/show-errors": 2
}
}
5 changes: 0 additions & 5 deletions app/components/Navbar.js
Expand Up @@ -8,17 +8,12 @@ class Navbar extends Component {
ipcRenderer.send('check-update', true);
}

notif() {
ipcRenderer.send('notification', { type: 'alert' });
}

render() {
return (
<nav className="navbar navbar-default navbar-static-top">
<div className="top-container">
<div className="title">
<h1><Link to="/"><img src={image} width={50} alt="Coin Watch" /> Coin Watch</Link></h1>
<h1 onClick={this.notif}>NOTIFICATION</h1>
</div>
<div className="content" />
<div className="toolbar pull-right">
Expand Down
2 changes: 1 addition & 1 deletion app/main.dev.js
Expand Up @@ -9,7 +9,7 @@
*
* @flow
*/
import { app, Notification } from 'electron';
import { app } from 'electron';
import log from 'electron-log';
import path from 'path';
import electronDebug from 'electron-debug';
Expand Down
4 changes: 2 additions & 2 deletions app/modules/coins/actions.js
Expand Up @@ -98,7 +98,7 @@ export function saveAlert(alert) {

const alerts = settings.get('alerts');

console.log(alert)
console.log(alert);

alerts[alert.slug] = alert;

Expand All @@ -109,7 +109,7 @@ export function saveAlert(alert) {

alerts.push(alert);

console.log('updated', alerts)
console.log('updated', alerts);

settings.set('alerts', alerts);

Expand Down
4 changes: 2 additions & 2 deletions app/modules/coins/components/Coin.js
Expand Up @@ -7,7 +7,6 @@ import { getCoinPrice, removeCoin, toggleVisibility, toggleForceRefresh } from '
import formatPrice from '../../../helpers/formatPrice';
import trendToArrow from '../../../helpers/trendToArrow';
import ModalButton from '../../modal/containers/ModalButton';
import Modal from '../../modal/containers/Modal';
import AlertSettings from '../containers/AlertSettings';

export class Coin extends Component {
Expand Down Expand Up @@ -59,7 +58,7 @@ export class Coin extends Component {
{formatPrice(currentPriceDisplayed, to)}{trendToArrow(trend)}
</td>
<td className="actions toolbar">
{/*<ModalButton className="pull-right"><span className="glyphicon glyphicon-plus" /></ModalButton>*/}
{/* <ModalButton className="pull-right"><span className="glyphicon glyphicon-plus" /></ModalButton> */}

<ModalButton className="alert" component={AlertSettings} extras={{ slug }}><span className={`glyphicon glyphicon-bell toggle-button ${alert && 'active'}`} /></ModalButton>
<button onClick={() => this.onToggleVisibility(slug)} className="visibility"><span className={`glyphicon glyphicon-eye-open toggle-button ${visibility && 'active'}`} /></button>
Expand Down Expand Up @@ -90,6 +89,7 @@ Coin.propTypes = {

Coin.defaultProps = {
price: null,
alert: null,
};

const dispatchProps = {
Expand Down
11 changes: 4 additions & 7 deletions app/modules/coins/containers/AlertSettings.js
@@ -1,9 +1,9 @@
import React, { Component } from 'react';
import { Field, reduxForm, SubmissionError } from 'redux-form';
import { Field, reduxForm } from 'redux-form';
import { connect } from 'react-redux';
import { saveAlert } from '../actions';
import { find } from 'lodash';
import PropTypes from 'prop-types';
import { saveAlert } from '../actions';

class AlertSettings extends Component {
constructor() {
Expand All @@ -23,13 +23,12 @@ class AlertSettings extends Component {
const {
error,
submitting,
alert,
handleSubmit,
} = this.props;

console.log(this.props)
console.log(this.props);

/*
/*
const coinsOptions = values(map(coins.Data, (d) => ({ label: d.FullName, value: d })));
const exchangesOptions = values(map(exchanges, (d) => ({ label: d, value: d })));
Expand Down Expand Up @@ -87,15 +86,13 @@ AlertSettings.propTypes = {
saveAlert: PropTypes.func.isRequired,
closeModal: PropTypes.func.isRequired,
extras: PropTypes.object.isRequired,
alert: PropTypes.object,
};

AlertSettings.defaultProps = {
error: null,
};

function mapStateToProps({ settings }, { extras }) {

return {
alert: find(settings.alerts, (a) => a.slug === extras.slug)
};
Expand Down
4 changes: 2 additions & 2 deletions app/modules/coins/containers/CoinsPage.js
@@ -1,12 +1,12 @@
import React, { Component } from 'react';
import { map, find } from 'lodash';
import { map } from 'lodash';
import { connect } from 'react-redux';
import shallowCompare from 'react-addons-shallow-compare';
import PropTypes from 'prop-types';
import Coin from '../components/Coin';
import CoinSettings from './CoinsSettings';
import { toggleForceRefresh } from '../actions';
import ModalButton from '../../modal/containers/ModalButton';
import PropTypes from 'prop-types';

export class CoinsPage extends Component {
constructor(props) {
Expand Down
4 changes: 2 additions & 2 deletions app/modules/coins/containers/CoinsSettings.js
@@ -1,10 +1,10 @@
import React, { Component } from 'react';
import { Field, reduxForm, SubmissionError } from 'redux-form';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { isEmpty, map, mapValues, values } from 'lodash';
import SelectField from '../../form/SelectField/index';
import { getCoinPrice, getCoins, getExchangeList, getSymbolList, saveCoin } from '../actions';
import PropTypes from 'prop-types';

class CoinsSettings extends Component {
constructor() {
Expand All @@ -26,7 +26,7 @@ class CoinsSettings extends Component {
}

onSubmit(props) {
const propsMapped = mapValues(props, (p) => p.value ? p.value : p);
const propsMapped = mapValues(props, (p) => (p.value ? p.value : p));

return this.props.getCoinPrice(propsMapped)
.then(() => this.props.saveCoin(propsMapped))
Expand Down
1 change: 0 additions & 1 deletion app/modules/coins/reducers.js
Expand Up @@ -99,7 +99,6 @@ export default function coinsReducer(state = initialState, action) {
if (alertSetting.trend === 'down' && coin.price < alertSetting.price) {
ipcRenderer.send(NOTIFICATION, { type: 'alert', title: coin.slug, body: `Price is lower than ${coin.price}` });
isAlerted = true;

} else if (alertSetting.trend === 'up' && coin.price > alertSetting.price) {
ipcRenderer.send(NOTIFICATION, { type: 'alert', title: coin.slug, body: `Price is greater than ${coin.price}` });
isAlerted = true;
Expand Down
2 changes: 1 addition & 1 deletion app/modules/modal/containers/Modal.js
@@ -1,8 +1,8 @@
import React, { Component } from 'react';
import Modal from 'react-modal';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { closeModal } from '../actions';
import PropTypes from 'prop-types';

class ModalClass extends Component {
render() {
Expand Down
6 changes: 5 additions & 1 deletion app/modules/modal/containers/ModalButton.js
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { openModal } from '../actions';
import PropTypes from 'prop-types';
import { openModal } from '../actions';

class ModalButton extends Component {
constructor(props) {
Expand Down Expand Up @@ -31,4 +31,8 @@ ModalButton.propTypes = {
extras: PropTypes.object,
};

ModalButton.defaultProps = {
extras: {},
};

export default connect(null, { openModal })(ModalButton);
15 changes: 8 additions & 7 deletions app/modules/settings/Migrate.js
@@ -1,12 +1,9 @@
import { readdirSync } from 'fs';
import path from 'path';
import settings from 'electron-settings';
import { forEach } from 'lodash';

class Migrate {
basePath = path.resolve(__dirname, 'migrations');
constructor() {
const migrationFiles = this.constructor.getMigrations(this.basePath);
const migrationFiles = this.constructor.getMigrations();

this.settingsUpdated = settings.getAll();

Expand All @@ -19,7 +16,7 @@ class Migrate {
}

migrate(migrationFile) {
const ClassName = require(path.resolve(this.basePath, migrationFile));
const ClassName = migrationFile; // eslint-disable-line global-require,import/no-dynamic-require
const migration = new ClassName(this.settingsUpdated);
if (!migration.isVersion()) {
console.log(`settings are not version ${migrationFile}`);
Expand All @@ -30,8 +27,12 @@ class Migrate {
this.settingsUpdated = migration.up();
}

static getMigrations(basePath) {
return readdirSync(basePath);
static getMigrations() {
return [
require('./migrations/v0'), // eslint-disable-line global-require
require('./migrations/v1'), // eslint-disable-line global-require
require('./migrations/v2'), // eslint-disable-line global-require
];
}
}

Expand Down

0 comments on commit c741dcd

Please sign in to comment.