Skip to content
This repository was archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #123 from tahnik/bugfixes
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
tahnik authored Jul 30, 2017
2 parents 9e4675e + aef9c8a commit 3000620
Show file tree
Hide file tree
Showing 30 changed files with 299 additions and 209 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"import/no-dynamic-require": 0,
"import/no-extraneous-dependencies": "off",
"linebreak-style": ["error", "unix"],
"react/forbid-prop-types": 0
"react/forbid-prop-types": 0,
"react/require-default-props": 0
},
"settings": {
"import/resolver": {
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const electron = require('electron');

const { app, BrowserWindow, Menu, Tray, ipcMain } = electron;
const { app, BrowserWindow, Menu, Tray, ipcMain, shell } = electron;

const https = require('https');
const os = require('os');
Expand Down Expand Up @@ -50,6 +50,13 @@ function quitApp() {
mainWindow.webContents.send('quitApp');
}

const handleRedirect = (e, link) => {
if (url !== mainWindow.webContents.getURL()) {
e.preventDefault();
shell.openExternal(link);
}
};

/** This function will create the tray icon */
function initTray() {
// No idea why using let or var or const with tray causes the tray not to display anything
Expand Down Expand Up @@ -163,6 +170,16 @@ function createWindow() {
}
});

mainWindow.webContents.on('new-window', handleRedirect);

mainWindow.webContents.on('will-navigate', (e, link) => {
if (link.indexOf('devrant.io') !== -1) {
const user = link.substr(link.lastIndexOf('/') + 1, link.length);
mainWindow.webContents.send('open-profile', { user });
e.preventDefault();
}
});

initTray();
}

Expand Down
17 changes: 14 additions & 3 deletions app/src/main/js/actions/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import rantscript from '../consts/rantscript';
import { FEED, STATE, COLUMN, COLUMNS, ITEM } from '../consts/types';
import DEFAULT_STATES from '../consts/default_states';
import showToast from './toast';
import { getUID } from '../consts/DOMFunctions';
import { getUID } from '../consts/utils';

const AMOUNT = 20;

Expand Down Expand Up @@ -127,6 +127,14 @@ const resetColumn = () => (dispatch) => {
});
};

const updateColumnScrollHeight = (id, value) => (dispatch) => {
dispatch({
type: COLUMN.UPDATE_SCROLL,
id,
value,
});
};

/**
* fetches a feed.
*
Expand Down Expand Up @@ -239,7 +247,7 @@ const fetch =
switch (type) {
case FEED.RANTS.NAME:
rantscript
.rants(sort, AMOUNT, AMOUNT * page, prevSet, authToken)
.rants(sort, AMOUNT, AMOUNT * page, prevSet, authToken, range)
.then((res) => {
/**
* If the pages is 0, that means we do not need to current items in the
Expand Down Expand Up @@ -306,4 +314,7 @@ const fetch =
};


export { fetch as default, addColumn, resetColumn, removeColumn };
export { fetch as default,
addColumn, resetColumn, removeColumn,
updateColumnScrollHeight,
};
1 change: 1 addition & 0 deletions app/src/main/js/actions/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ const openModal = (type, id = 0) => (dispatch) => {
});
};


export { openModal, closeModal };
9 changes: 7 additions & 2 deletions app/src/main/js/actions/notifs.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ const showNotifs = notif => (dispatch, getState) => {
}
if (notifSettings[notif.content.type].value === true) {
// Show quick reply notif instead
if (notif.content.type === 'comment_content' || notif.content.type === 'comment_mention') {
if (
(notif.content.type === 'comment_content'
|| notif.content.type === 'comment_mention')
&& notifSettings.quick_reply_enabled.value
) {
ipcRenderer.send('showQRNotif', notif);
return;
}
Expand All @@ -77,6 +81,7 @@ const showNotifs = notif => (dispatch, getState) => {
body: notif.body,
data: notif.id,
icon: 'http://i.imgur.com/iikd00P.png',
silent: !notifSettings.notif_sound_enabled.value,
});

myNotification.onclick = (e) => {
Expand All @@ -87,4 +92,4 @@ const showNotifs = notif => (dispatch, getState) => {
}
};

export { fetchNotifs, clearNotifs, showNotifs }; //eslint-disable-line
export { fetchNotifs, clearNotifs, showNotifs };
58 changes: 34 additions & 24 deletions app/src/main/js/components/columns/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import PropTypes from 'prop-types';
import ItemCard from '../item/item_card';
import Loading from '../utilities/loading';
import ColumnTopBar from './column_topbar';
import { getRandomInt } from '../../consts/DOMFunctions';
import { ITEM } from '../../consts/types';
import CommentCard from '../comments/comment_card';
import { getRandomInt } from '../../consts/utils';

class Column extends Component {
constructor() {
Expand All @@ -18,6 +16,12 @@ class Column extends Component {
const divID = `column_${this.props.column.type}_${getRandomInt()}`;
this.setState({ divID });
}
componentDidMount() {
const scrollHeight = this.props.column.scrollHeight;
if (typeof scrollHeight !== 'undefined') {
this.itemsContainer.scrollTop = scrollHeight;
}
}
shouldComponentUpdate(nextProps) {
const currentColumn = this.props.column;
const nextColumn = nextProps.column;
Expand All @@ -32,6 +36,12 @@ class Column extends Component {
}
return true;
}
componentWillUnmount() {
const { updateScrollHeight } = this.props;
if (typeof updateScrollHeight !== 'undefined') {
updateScrollHeight(this.props.column.id, this.itemsContainer.scrollTop);
}
}
render() {
const {
column, theme, vote, fetch, open, filters, itemType, removeColumn, auth } = this.props;
Expand All @@ -50,32 +60,31 @@ class Column extends Component {
type={column.type}
state={column.state}
removeColumn={removeColumn}
sort={column.sort}
range={column.range}
/>
<div className="items_container" id={divID}>
<div
className="items_container"
id={divID}
ref={(node) => { this.itemsContainer = node; }}
>
{
column.items.length === 0 ?
<Loading
backgroundColor={theme.backgroundColor}
/> :
column.items.map((item) => {
if (column.itemType === ITEM.COMMENT.NAME) {
return (
<CommentCard {...this.props} item={item} key={item.id} />
);
}
return (
<ItemCard
fetch={fetch}
item={item}
open={(type, id) => open(type, id)}
key={item.id}
theme={theme}
vote={vote}
itemType={itemType}
auth={auth}
/>
);
})
column.items.map(item => (
<ItemCard
fetch={fetch}
item={item}
open={(type, id) => open(type, id)}
key={item.id}
theme={theme}
vote={vote}
itemType={itemType}
auth={auth}
/>
))
}
</div>
</div>
Expand All @@ -89,10 +98,11 @@ Column.propTypes = {
theme: PropTypes.object.isRequired,
vote: PropTypes.func.isRequired,
open: PropTypes.func.isRequired,
removeColumn: PropTypes.func, // eslint-disable-line
removeColumn: PropTypes.func,
filters: PropTypes.object.isRequired,
itemType: PropTypes.string.isRequired,
auth: PropTypes.object.isRequired,
updateScrollHeight: PropTypes.func,
};

export default Column;
53 changes: 44 additions & 9 deletions app/src/main/js/components/columns/column_topbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ class ColumnTopBar extends Component {
componentWillMount() {
const { filters, fetchAfterMount } = this.props;

const primaryFilters = filters[filters.PRIMARY];
const firstPriIndex = Object.keys(primaryFilters)[0];
const firstPri = primaryFilters[firstPriIndex];
const firstPri = this.getFilter(filters.PRIMARY);
this.setState({ primary: firstPri });

let firstSec = null;
if (filters.SECONDARY) {
const secondaryFilters = filters[filters.SECONDARY];
const firstSecIndex = Object.keys(secondaryFilters)[0];
firstSec = secondaryFilters[firstSecIndex];
const firstSec = this.getFilter(filters.SECONDARY);
if (firstSec) {
this.setState({ secondary: firstSec });
}
if (fetchAfterMount) {
Expand All @@ -44,6 +39,44 @@ class ColumnTopBar extends Component {
element.removeEventListener('scroll', () => this.handleScroll());
}
}
getFilter(type) {
const { filters, sort, range } = this.props;
// Get the options from the given filter type i.e. algo, top and recent
const options = filters[type];
if (options) {
/**
* sort and range is previously selected options.
* if they are undefined, it means that the column is being mounted for the first time
*/
if (typeof sort !== 'undefined' && sort) {
if (options[sort.toUpperCase()]) {
/**
* This means that we've found out previously selected 'sort' in the given filter type.
* let's return it
*/
return sort;
}
}
if (typeof range !== 'undefined' && range) {
if (options[range.toUpperCase()]) {
/**
* This means that we've found out previously selected 'range' in the given filter type.
* let's return it
*/
return range;
}
}

/**
* If we have come this far, this means that the column is being mounted for the first time
* Let's return the first option from the options
* For example, if it's algo, recent and top, we are going to return algo
*/

return options[Object.keys(options)[0]];
}
return null;
}
fetch(firstPri, firstSec, refresh = false) {
const { id, type, filters } = this.props;
if (filters.PRIMARY === FILTERS.SORT) {
Expand Down Expand Up @@ -154,8 +187,10 @@ class ColumnTopBar extends Component {
ColumnTopBar.propTypes = {
filters: PropTypes.object.isRequired,
fetch: PropTypes.func.isRequired,
removeColumn: PropTypes.func, // eslint-disable-line
removeColumn: PropTypes.func,
divID: PropTypes.string.isRequired,
sort: PropTypes.string,
range: PropTypes.string,
id: PropTypes.string.isRequired,
fetchAfterMount: PropTypes.bool.isRequired,
type: PropTypes.string.isRequired,
Expand Down
79 changes: 0 additions & 79 deletions app/src/main/js/components/comments/comment_card.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/js/components/comments/comments.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import CommentCard from './comment_card';
import ItemCard from '../item/item_card';

class Comments extends Component {
constructor() {
Expand All @@ -24,7 +24,7 @@ class Comments extends Component {
}
{
comments.map(comment => (
<CommentCard
<ItemCard
key={comment.id}
item={comment}
theme={theme}
Expand Down
Loading

0 comments on commit 3000620

Please sign in to comment.