Skip to content

Commit

Permalink
feat: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Aug 19, 2024
1 parent 7bf1359 commit 92a8887
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions js/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const progress = (() => {
let total = 0;
let loaded = 0;
let valid = true;
let push = true;

const complete = (type) => {
if (!valid) {
Expand All @@ -26,7 +27,11 @@ export const progress = (() => {
};

const add = () => {
total = total + 1;
if (!push) {
return;
}

total += 1;
};

const invalid = (type) => {
Expand All @@ -35,15 +40,8 @@ export const progress = (() => {
valid = false;
};

const init = () => {
const assets = document.querySelectorAll('img');

info = document.getElementById('progress-info');
bar = document.getElementById('progress-bar');
info.style.display = 'block';

assets.forEach(add);
assets.forEach((asset) => {
const run = async () => {
document.querySelectorAll('img').forEach((asset) => {
asset.onerror = () => {
invalid('image');
};
Expand All @@ -59,6 +57,17 @@ export const progress = (() => {
});
};

const init = () => {
document.querySelectorAll('img').forEach(add);

info = document.getElementById('progress-info');
bar = document.getElementById('progress-bar');
info.style.display = 'block';

push = false;
run();
};

return {
init,
add,
Expand Down
2 changes: 1 addition & 1 deletion js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ export const util = (() => {
return;
}

session.set('token', token);
progress.add();
request(HTTP_GET, '/api/config')
.token(token)
.then((res) => {
session.set('token', token);
progress.complete('request');
const config = storage('config');

Expand Down

0 comments on commit 92a8887

Please sign in to comment.