Skip to content

Commit

Permalink
fiux
Browse files Browse the repository at this point in the history
  • Loading branch information
peniqliotuv committed May 13, 2018
1 parent b3f7f80 commit 06dc82e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
23 changes: 18 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ ipcMain.on('open-preferences', (event, symbol) => {
createPreferencesWindow();
});

ipcMain.on('chart', (event, symbol) => {
createStockWindow(symbol);
ipcMain.on('chart', (event, data) => {
const {
symbol,
tabIndex,
} = data;
console.log(data);
createStockWindow(symbol, tabIndex);
});

ipcMain.on('logout', async (event, arg) => {
Expand Down Expand Up @@ -376,10 +381,17 @@ const createLoginMenu = () => {
return Menu.buildFromTemplate(template);
};

const createStockWindow = async symbol => {
const createStockWindow = async (symbol, tabIndex) => {
let data;
const position = RobinHoodAPI._positions.filter((position) => position.symbol === symbol)[0];
const price = position.quote.last_trade_price;
let price;
if (tabIndex === 0) {
const position = RobinHoodAPI._positions.filter((quote) => quote.symbol === symbol)[0];
price = position.quote.last_trade_price;
} else if (tabIndex === 1) {
const watchlist = RobinHoodAPI._watchlist.filter((quote) => quote.symbol === symbol)[0];
price = watchlist.last_trade_price;
}

try {
data = await StockAPI.getSMA(symbol);
} catch (e) {
Expand Down Expand Up @@ -520,6 +532,7 @@ const initializeApp = () => {
height: 500,
tray,
resizable: false,
alwaysOnTop: true,
webPreferences: {
experimentalFeatures: true
}
Expand Down
1 change: 1 addition & 0 deletions src/styles/stock.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ span {
position: absolute;
height: 465px;
top: 132px;
visibility: hidden;
}

#vr>#time {
Expand Down
18 changes: 14 additions & 4 deletions src/views/menubar.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,33 @@
const newTop = oldTop - dragObj.offsetHeight - dragObj.container.scrollTop;
dragObj.style.top = `${newTop}px`;


/* Make it obvious that the stock elements are re-orderable */
positionsContainer.childNodes.forEach((el) => {
const currContainer = tabIndex === 0 ? positionsContainer : watchlistContainer;
currContainer.childNodes.forEach((el) => {
if (!el.classList.contains('placeholder')) {
el.childNodes[0].classList.add('movable');
}
});


})

obj.onmousedown = function (e) {
console.log('MOUSEDOWN');
longPressTimeoutExpired = false;
}

obj.onmouseup = function (e) {
/* Send a message to the main process to open the stock info window */
console.log('MOUSEUP', e.which, longPressTimeoutExpired);
if (e.which === 1 && !longPressTimeoutExpired) {
const symbol = obj.childNodes[0].childNodes[0].childNodes[0].innerHTML;
ipcRenderer.send('chart', symbol);
console.log(symbol);
ipcRenderer.send('chart', {
symbol,
tabIndex,
});
}
}
}
Expand Down Expand Up @@ -160,7 +170,7 @@
sortedPositions[index] = position;
});
positionsIndices = sortedPositions.map((position) => position.symbol);
console.log(positionsIndices);
// console.log(positionsIndices);
data._positions = sortedPositions;
} else if (tabIndex === 1) {
const sortedWatchlist = new Array(data._watchlist.length);
Expand All @@ -169,7 +179,7 @@
sortedWatchlist[index] = watchlist;
});
watchlistIndices = sortedWatchlist.map((watchlist) => watchlist.symbol);
console.log(watchlistIndices);
// console.log(watchlistIndices);
data._watchlist = sortedWatchlist;
}

Expand Down
9 changes: 8 additions & 1 deletion src/views/stock.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

let points;
let tooltip;
let currentPrice;

/* K: time (ex: 11:01AM) V: { price, boundingRect of node } */
const nodes = new Map();
Expand All @@ -49,14 +50,15 @@
symbol,
price,
} = message;
currentPrice = Number(price).toFixed(2);
const marketOpen = data[0].marketOpen;
const marketClose = data[0].marketClose;
const className = marketClose < marketOpen ? 'loss' : 'gain';
const color = marketClose < marketOpen ? '#e35f3e' : '#50a885';
points = data.map((item) => {
return {
x: item.label,
y: item.average,
y: Number(item.average).toFixed(2),
};
}).filter((point) => point.y >= 0);
console.log(points);
Expand Down Expand Up @@ -116,8 +118,13 @@
const BOTTOM_BOUNDARY = 50;
if (e.pageX < bounds.left + LEFT_BOUNDARY || e.pageX > bounds.right - RIGHT_BOUNDARY ||
e.pageY < bounds.top + TOP_BOUNDARY) {
tooltip.innerHTML = currentPrice;
vr.style.visibility = 'hidden';
time.style.visibility = 'hidden';
return;
}
vr.style.visibility = 'visible';
time.style.visibility = 'visible';
vr.style.left = `${e.pageX}px`;

let closestTime = null;
Expand Down

0 comments on commit 06dc82e

Please sign in to comment.