Skip to content

Commit

Permalink
add a bit more feedback for users
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Sep 23, 2018
1 parent 1bc7b63 commit d949cea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion dist/bs-customizer.min.js

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/dialog-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import $ from 'jquery'
import 'bootstrap/js/dist/modal'
import 'boxicons/css/boxicons.css'

import { taskDebounce } from './util';

let $modal
let $loadingStatus
const dialogClass = 'dialog-loader'
Expand All @@ -29,26 +27,28 @@ const createModal = () => {
}

const showModal = (callback) => {
$loadingStatus.text('Building your custom Bootstrap...')
$loadingStatus.text('Downloading your assets...')
$modal
.one('shown.bs.modal', () => {
taskDebounce(() => {
callback()
})()
callback()
})
.modal('show')
}

const updateDialogStatus = (text) => {
$loadingStatus.text(text)
return $loadingStatus[0].offsetHeight
}
const hideModal = () => {
$modal
.one('hidden.bs.modal', () => {
$loadingStatus.text('')
})
.modal('hide')
$modal.one('hidden.bs.modal', () => {
updateDialogStatus('')
})
.modal('hide')
}

export {
createModal,
showModal,
hideModal,
updateDialogStatus,
}
18 changes: 13 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import $ from 'jquery'
import axios from 'axios'

import { createFileContent, downloadFile } from './file-util'
import { formatList } from './util'
import { createModal, showModal, hideModal } from './dialog-loader'
import { formatList, delay } from './util'
import { createModal, showModal, hideModal, updateDialogStatus } from './dialog-loader'

import 'bootstrap/dist/css/bootstrap.css'
import './main.css'
Expand Down Expand Up @@ -81,10 +81,18 @@ $(() => {

axios.all(listOfRequest)
.then((listOfFiles) => {
hideModal()
downloadFile(fileName, createFileContent(listOfFiles, minify))
updateDialogStatus('Building your assets...')

delay(10, () => {
const fileContent = createFileContent(listOfFiles, minify)

delay(10, () => {
downloadFile(fileName, fileContent)
hideModal()
})
})
})
.catch(() => {
.catch((err) => {
hideModal()
})
})
Expand Down
17 changes: 5 additions & 12 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@ const formatList = (list) => {
return listPlugin
}

const taskDebounce = (fn) => {
let scheduled = false;
return () => {
if (!scheduled) {
scheduled = true
setTimeout(() => {
scheduled = false
fn()
}, 0)
}
}
const delay = (time, fn) => {
setTimeout(() => {
fn()
}, time)
}

export {
formatList,
taskDebounce
delay,
}

0 comments on commit d949cea

Please sign in to comment.