Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions app/background/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios'
/* global localStorage, chrome */
import moment from 'moment'
import request from '../components/AuthInterceptor'

JSON.isAJSONString = (object) => {
try {
Expand All @@ -12,8 +13,6 @@ JSON.isAJSONString = (object) => {

class RunrunTasks {
constructor () {
this._tasks

if (!localStorage.getItem('reminderEnabled')) { localStorage.setItem('reminderEnabled', true) }

if (!localStorage.getItem('reminderTimeInMinutes')) { localStorage.setItem('reminderTimeInMinutes', 30) }
Expand All @@ -26,29 +25,16 @@ class RunrunTasks {

this._is_working_on = (localStorage.getItem('is_working_on') && JSON.isAJSONString(localStorage.getItem('is_working_on'))) ? JSON.parse(localStorage.getItem('is_working_on')) : false
this._reminder = (localStorage.getItem('reminder')) ? moment(localStorage.getItem('reminder')) : moment()
parent = this

this.updateTasks = this.updateTasks.bind(this)
}

getHttpClient () {
const client = axios.create()
client.interceptors.request.use((config) => {
config.headers['App-Key'] = localStorage.getItem('appkey')
config.headers['User-Token'] = localStorage.getItem('usertoken')

return config
})
return client
}

getUser () {
return new Promise((resolve, reject) => {
try {
const user = (localStorage.getItem('user')) ? JSON.parse(localStorage.getItem('user')) : {}
resolve(user)
} catch (error) {
const request = this.getHttpClient()
request.get(`https://secure.runrun.it/api/v1.0/users/me`)
.then(response => {
localStorage.setItem('user', JSON.stringify(response.data))
Expand All @@ -62,7 +48,6 @@ class RunrunTasks {
}

updateTasks () {
const request = this.getHttpClient()
this.getUser()
.then(user => {
return request.get('https://secure.runrun.it/api/v1.0/tasks', {
Expand All @@ -82,7 +67,7 @@ class RunrunTasks {
const trackedTask = localStorage.getItem('trackedTask')
if (trackedTask) {
const trackedTaskOnTaskList = this._tasks.find((task) => {
return task.id == trackedTask
return task.id === trackedTask
})
if (trackedTaskOnTaskList === undefined || (workingTask !== undefined && workingTask.id !== trackedTaskOnTaskList.id)) { localStorage.setItem('trackedTask', '') }
}
Expand Down Expand Up @@ -119,7 +104,7 @@ class RunrunTasks {
chrome.browserAction.setIcon({path: 'images/icon_128.png'})
}

const reminderEnabled = !!((localStorage.getItem('reminderEnabled') && localStorage.getItem('reminderEnabled') == 'true'))
const reminderEnabled = !!((localStorage.getItem('reminderEnabled') && localStorage.getItem('reminderEnabled') === 'true'))
const reminderTime = (localStorage.getItem('reminderTimeInMinutes')) ? parseInt(localStorage.getItem('reminderTimeInMinutes')) : 30
if (reminderEnabled && this._reminder.isSameOrBefore(moment().subtract(reminderTime, 'm'))) {
this._reminder = moment()
Expand Down Expand Up @@ -164,15 +149,13 @@ class RunrunTasks {
}

pauseTask (id) {
const request = this.getHttpClient()
request.post(`https://secure.runrun.it/api/v1.0/tasks/${id}/pause`)
.then(response => {
this.updateTasks()
})
}

resumeTask (id) {
const request = this.getHttpClient()
request.post(`https://secure.runrun.it/api/v1.0/tasks/${id}/play`)
.then(response => {
this.updateTasks()
Expand Down
5 changes: 0 additions & 5 deletions app/components/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React from 'react'

import style from './App.css'

class App extends React.Component {
constructor (props) {
super(props)
}

render () {
return (
<div className='app'>
Expand Down
2 changes: 2 additions & 0 deletions app/components/AuthInterceptor/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* global localStorage */
import axios from 'axios'

const AuthInterceptor = axios.create()
AuthInterceptor.interceptors.request.use((config) => {
config.headers['App-Key'] = localStorage.getItem('appkey')
config.headers['User-Token'] = localStorage.getItem('usertoken')
config.headers['X-Platform'] = 'ChromeExtension'

return config
})
Expand Down
2 changes: 1 addition & 1 deletion app/components/ClosedTasksPage/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global localStorage */
import React from 'react'
import { Link } from 'react-router'
import moment from 'moment'
import 'moment-duration-format'

Expand Down
12 changes: 3 additions & 9 deletions app/components/OpenedTasksPage/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global localStorage, chrome, parent */
import React from 'react'
import { Link } from 'react-router'
import moment from 'moment'
import 'moment-duration-format'

Expand Down Expand Up @@ -89,7 +89,7 @@ class OpenedTasksPage extends React.Component {

handleTaskTracking (id) {
return () => {
if (localStorage.getItem('trackedTask') && localStorage.getItem('trackedTask') == id) { localStorage.setItem('trackedTask', '') } else { localStorage.setItem('trackedTask', id) }
if (localStorage.getItem('trackedTask') && localStorage.getItem('trackedTask') === id) { localStorage.setItem('trackedTask', '') } else { localStorage.setItem('trackedTask', id) }
this.setState({
trackedTask: localStorage.getItem('trackedTask')
})
Expand Down Expand Up @@ -134,7 +134,7 @@ class OpenedTasksPage extends React.Component {
{(this.state.autoPauseResume && task.is_working_on) ? (
<span title='When this option is active the extension will manage the task for you, pausing/resuming if you lock/unlock the machine.' onClick={this.handleTaskTracking(task.id)}>
{
(this.state.trackedTask == task.id)
(this.state.trackedTask === task.id)
? (<img src='/images/auto_pause_red.svg' />)
: (<img src='/images/auto_pause_gray.svg' />)
}
Expand Down Expand Up @@ -192,12 +192,6 @@ class OpenedTasksPage extends React.Component {
<PopupHeader title='Tasks (Open)' />
<PopupNav routeName='opened' />
</div>
{/* <ul className={`list-group ${style.OpenedTasksPage}`}>
{tasks}
</ul> */}
{/* <div className={style.TasksDiv}>
{tasks}
</div> */}
<div className={(localStorage.getItem('appkey')) ? `${style.TasksDiv}` : `${style.CoverDiv}`}>
{tasks}
</div>
Expand Down
6 changes: 1 addition & 5 deletions app/components/PopupHeader/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* global localStorage */
import React from 'react'
import style from './style.css'
import { Link } from 'react-router'
import PropTypes from 'prop-types'

class PopupHeader extends React.Component {
constructor (props) {
super(props)
}

render () {
if (!localStorage.getItem('appkey')) {
return (
Expand Down
1 change: 1 addition & 0 deletions app/components/PopupNav/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global localStorage */
import React from 'react'
import { Link } from 'react-router'
import PropTypes from 'prop-types'
Expand Down
2 changes: 1 addition & 1 deletion app/meta/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"short_name": "Runrun.it",
"description": "__MSG_extDescription__",
"default_locale": "en",
"version": "1.0.4",
"version": "1.0.5",
"browser_action": {
"default_icon": "images/icon_16_active.png",
"default_title": "Runrun.it",
Expand Down
3 changes: 1 addition & 2 deletions app/options.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react'
import { render } from 'react-dom'
import OptionsPage from './components/OptionsPage'
import routes from './routes'

const appContainer = document.getElementById('runrunTMApp')

import routes from './routes'

render(<OptionsPage />, appContainer)
3 changes: 1 addition & 2 deletions app/popup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react'
import { render } from 'react-dom'
import { Router, hashHistory } from 'react-router'
import routes from './routes'

const appContainer = document.getElementById('runrunTMApp')
const path = appContainer.getAttribute('path') || ''

import routes from './routes'

render(
<Router history={hashHistory} routes={routes(path)} />,
appContainer
Expand Down