Skip to content

Commit

Permalink
Use success and failure notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dideler committed May 20, 2020
1 parent 7a53c24 commit 6114b9b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getGitHubApi, GET_SINGLE_GIST } from '../utilities/githubApi'
import Notifier from '../utilities/notifier'
import { notifyFailure } from '../utilities/notifier'
import { remote } from 'electron'
const logger = remote.getGlobal('logger')

Expand Down Expand Up @@ -232,7 +232,7 @@ export function fetchSingleGist (oldGist, id) {
})
.catch((err) => {
logger.error('The request has failed: ' + err)
Notifier('Sync failed', 'Please check your network condition. 01')
notifyFailure('Sync failed', 'Please check your network condition. 01')
})
}
}
16 changes: 8 additions & 8 deletions app/containers/snippet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Autolinker from 'autolinker'
import CodeArea from '../codeArea'
import HumanReadableTime from 'human-readable-time'
import Moment from 'moment'
import Notifier from '../../utilities/notifier'
import { notifySuccess, notifyFailure } from '../../utilities/notifier'
import React, { Component } from 'react'
import {
addLangPrefix as Prefixed,
Expand Down Expand Up @@ -78,11 +78,11 @@ class Snippet extends Component {
.catch(err => {
logger.error('Failed to delete the gist ' + activeGist)
logger.error(JSON.stringify(err))
Notifier('Deletion failed', 'Please check your network condition. 02')
notifyFailure('Deletion failed', 'Please check your network condition. 02')
})
.then(data => {
logger.info('The gist ' + activeGist + ' has been deleted.')
Notifier('The gist has been deleted')
notifySuccess('The gist has been deleted')

// For performance purpose, we should perform an internal update, like what
// we're doing for creating/edit gists. However, since delete is an infrequent
Expand Down Expand Up @@ -156,7 +156,7 @@ class Snippet extends Component {
description,
processedFiles)
.catch((err) => {
Notifier('Gist update failed')
notifyFailure('Gist update failed')
logger.error(JSON.stringify(err))
})
.then((response) => {
Expand Down Expand Up @@ -277,7 +277,7 @@ class Snippet extends Component {
filename: filenameRecords
})

Notifier('Gist updated', HumanReadableTime(new Date()))
notifySuccess('Gist updated', HumanReadableTime(new Date()))
}

renderGistEditorModalBody (description, fileArray, isPrivate) {
Expand Down Expand Up @@ -328,12 +328,12 @@ class Snippet extends Component {
handleCopyGistLinkClicked (snippet, file) {
const link = snippet.details.html_url + '#file-' + file.filename.replace(/\./g, '-').toLowerCase()
clipboard.writeText(link)
Notifier('Copied', 'The link has been copied to the clipboard.')
notifySuccess('Copied', 'The link has been copied to the clipboard.')
}

handleCopyGistFileClicked (gist) {
clipboard.writeText(gist.content)
Notifier('Copied', 'The content has been copied to the clipboard.')
notifySuccess('Copied', 'The content has been copied to the clipboard.')
}

showRawModalModal (gist) {
Expand Down Expand Up @@ -375,7 +375,7 @@ class Snippet extends Component {

handleCopyRawLinkClicked (url) {
clipboard.writeText(url)
Notifier('Copied', 'The raw file link has been copied to the clipboard.')
notifySuccess('Copied', 'The raw file link has been copied to the clipboard.')
}

renderPanelHeader (activeSnippet) {
Expand Down
6 changes: 3 additions & 3 deletions app/containers/userPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { default as GistEditorForm, NEW_GIST } from '../gistEditorForm'
import { Image, Modal, Button, ProgressBar } from 'react-bootstrap'
import { remote, ipcRenderer } from 'electron'
import HumanReadableTime from 'human-readable-time'
import Notifier from '../../utilities/notifier'
import { notifySuccess, notifyFailure } from '../../utilities/notifier'
import React, { Component } from 'react'
import {
addLangPrefix as Prefixed,
Expand Down Expand Up @@ -78,7 +78,7 @@ class UserPanel extends Component {

return getGitHubApi(CREATE_SINGLE_GIST)(this.props.accessToken, description, processedFiles, isPublic)
.catch((err) => {
Notifier('Gist creation failed')
notifyFailure('Gist creation failed')
logger.error(JSON.stringify(err))
})
.then((response) => {
Expand Down Expand Up @@ -162,7 +162,7 @@ class UserPanel extends Component {
filename: filenameRecords
})

Notifier('Gist created', HumanReadableTime(new Date()))
notifySuccess('Gist created', HumanReadableTime(new Date()))
}

renderGistEditorModalBody () {
Expand Down
10 changes: 5 additions & 5 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
updatePinnedTags
} from './actions/index'

import Notifier from './utilities/notifier'
import { notifySuccess, notifyFailure } from './utilities/notifier'

const logger = remote.getGlobal('logger')

Expand Down Expand Up @@ -128,7 +128,7 @@ function launchAuthWindow (token) {
})
.catch((err) => {
logger.error('Failed: ' + JSON.stringify(err.error))
Notifier('Sync failed', 'Please check your network condition. 03')
notifyFailure('Sync failed', 'Please check your network condition. 03')
})
} else if (error) {
logger.error('Oops! Something went wrong and we couldn\'t' +
Expand Down Expand Up @@ -355,12 +355,12 @@ function updateUserGists (userLoginId, token) {
// clean up the snapshot for the previous state
clearSyncSnapshot()

Notifier('Sync succeeds', humanReadableSyncTime)
notifySuccess('Sync succeeds', humanReadableSyncTime)

reduxStore.dispatch(updateGistSyncStatus('DONE'))
})
.catch(err => {
Notifier('Sync failed', 'Please check your network condition. 04')
notifyFailure('Sync failed', 'Please check your network condition. 04')
logger.error('The request has failed: ' + err)
reduxStore.dispatch(updateGistSyncStatus('DONE'))
throw err
Expand Down Expand Up @@ -411,7 +411,7 @@ function initUserSession (token) {
logger.info('[Dispatch] updateUserSession INACTIVE')
reduxStore.dispatch(updateUserSession({ activeStatus: 'INACTIVE' }))
}
Notifier('Sync failed', 'Please check your network condition. 00')
notifyFailure('Sync failed', 'Please check your network condition. 00')
})
}
/** End: User session management **/
Expand Down
4 changes: 2 additions & 2 deletions app/utilities/githubApi/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Promise } from 'bluebird'
import { remote } from 'electron'
import Notifier from '../notifier'
import { notifyFailure } from '../notifier'
import ProxyAgent from 'proxy-agent'
import ReqPromise from 'request-promise'
import Request from 'request'
Expand Down Expand Up @@ -137,7 +137,7 @@ function getAllGistsV1 (token, userId) {
.catch(err => {
if (err !== EMPTY_PAGE_ERROR_MESSAGE) {
logger.error(err)
Notifier('Sync failed', 'Please check your network condition. 05')
notifyFailure('Sync failed', 'Please check your network condition. 05')
}
})
.finally(() => {
Expand Down

0 comments on commit 6114b9b

Please sign in to comment.