Skip to content

Commit

Permalink
close #154
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZhang73 committed Mar 15, 2022
1 parent 6f28370 commit e23b7fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/hooks/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const useAnnotation = () => {
annotation: annotationStore.exportAnnotation(),
config: configurationStore.exportConfig()
}
console.log('Submitting to: ' + mainStore.submitURL)
console.debug('Submitting to: ' + mainStore.submitURL)
fetch(mainStore.submitURL, {
method: 'post',
headers: {
Expand All @@ -85,30 +85,26 @@ export const useAnnotation = () => {
}).then(res => {
submitLoading.value = false
if (res.ok) {
console.log('Success', res)
console.debug('Success', res)
res.json().then(data => {
const { message, clipboard, type } = data
if (message) {
utils.notify('Server: ' + message, type || 'positive')
}
if (clipboard) {
copyToClipboard(clipboard).then(() => {
console.log('Copied to clipboard: ' + clipboard)
utils.notify('Copied to clipboard: ' + clipboard, 'positive', 0, 'center')
}).catch((err) => {
console.error('Failed to copy to clipboard', err)
}).catch(() => {
utils.notify('Failed to copy to clipboard, please do it manually: ' + clipboard, 'negative', 10000)
}
)
}
})
} else {
console.error('Failed', res)
utils.notify(`Failed to submit: ${res.statusText} (${res.status})`, 'warning')
}
}).catch(err => {
submitLoading.value = false
console.error('Failed', err)
utils.notify('Failed to submit: ' + err, 'negative')
})
},
Expand Down
17 changes: 17 additions & 0 deletions src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ export default {
* @returns
*/
notify (message, color = 'positive', timeout = 5000, position = 'bottom-right') {
switch (color) {
case 'positive':
console.debug(message)
break
case 'info':
console.info(message)
break
case 'negative':
console.error(message)
break
case 'warning':
console.warn(message)
break
default:
console.log(message)
break
}
return Notify.create({
message: message,
color: color,
Expand Down
1 change: 0 additions & 1 deletion src/pages/configuration/Configuration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const handleLoad = () => {
configurationStore.importConfig(JSON.parse(file))
utils.notify('Load successfully!', 'positive')
} catch (e) {
console.error(e)
utils.notify(`Could not load config: ${e}`, 'negative')
}
})
Expand Down

0 comments on commit e23b7fb

Please sign in to comment.