diff --git a/dashboard.html b/dashboard.html index 687aebf..ae872f1 100644 --- a/dashboard.html +++ b/dashboard.html @@ -341,18 +341,13 @@
Project
++ This project is built with by dewanakl +
++ If you want to support me, consider buying me a coffee +
1234 5678 9101 112
- +Nama Wahyu Siapa
@@ -429,7 +429,7 @@1234 5678 9101 112
- +Nama Riski Siapa
diff --git a/js/audio.js b/js/audio.js index 2386be2..2851f43 100644 --- a/js/audio.js +++ b/js/audio.js @@ -23,8 +23,8 @@ export const audio = (() => { await audio.play(); isPlay = true; } catch (err) { - alert(err); isPlay = false; + alert(err); } music.disabled = false; }; diff --git a/js/dto.js b/js/dto.js index f0096b7..c48f5ca 100644 --- a/js/dto.js +++ b/js/dto.js @@ -23,7 +23,7 @@ export const dto = (() => { }); const postCommentResponse = (({ uuid, own, name, presence, comment, created_at }) => { - let is_admin; + let is_admin = false; let comments = []; let like = likeCommentResponse(); @@ -72,7 +72,7 @@ export const dto = (() => { return { uuid, show, - } + }; }); const postCommentRequest = ((id, name, presence, comment) => { diff --git a/js/guest.js b/js/guest.js index ae81b2f..69187d6 100644 --- a/js/guest.js +++ b/js/guest.js @@ -8,7 +8,11 @@ import { confetti } from './confetti.js'; export const guest = (() => { const countDownDate = () => { - const until = document.getElementById('count-down').getAttribute('data-time').replace(' ', 'T'); + const until = document.getElementById('count-down')?.getAttribute('data-time')?.replace(' ', 'T'); + if (!until) { + return; + } + const count = (new Date(until)).getTime(); setInterval(() => { @@ -67,7 +71,7 @@ export const guest = (() => { const guest = document.getElementById('guest-name'); if (!name || !guest) { - guest.remove(); + guest?.remove(); } else { const div = document.createElement('div'); div.classList.add('m-2'); @@ -79,17 +83,20 @@ export const guest = (() => { if (form) { form.value = storage('information').get('name') ?? name; } + + util.opacity('loading', 0.025); }; const open = (button) => { button.disabled = true; + document.body.style.overflowY = 'scroll'; + document.body.scrollIntoView({ behavior: 'instant' }); + confetti({ origin: { y: 1 }, zIndex: 1057 }); - document.body.style.overflowY = 'scroll'; - document.body.scrollIntoView({ behavior: 'instant' }); util.opacity('welcome', 0.025); audio.play(); diff --git a/js/progress.js b/js/progress.js index d592158..5c190eb 100644 --- a/js/progress.js +++ b/js/progress.js @@ -1,4 +1,3 @@ -import { util } from './util.js'; import { guest } from './guest.js'; export const progress = (() => { @@ -13,7 +12,14 @@ export const progress = (() => { const onComplete = () => { guest.name(); - util.opacity('loading', 0.025); + }; + + const add = () => { + if (!push) { + return; + } + + total += 1; }; const complete = (type) => { @@ -30,14 +36,6 @@ export const progress = (() => { } }; - const add = () => { - if (!push) { - return; - } - - total += 1; - }; - const invalid = (type) => { info.innerText = `Error loading ${type} (${loaded}/${total}) [${parseInt((loaded / total) * 100).toFixed(0)}%]`; bar.style.backgroundColor = 'red'; diff --git a/js/request.js b/js/request.js index 1241d03..cbd6829 100644 --- a/js/request.js +++ b/js/request.js @@ -18,7 +18,7 @@ export const request = (method, path) => { }) }; - if (url.slice(-1) == '/') { + if (url.slice(-1) === '/') { url = url.slice(0, -1); } @@ -30,12 +30,20 @@ export const request = (method, path) => { */ send(transform = null) { return fetch(url + path, req) - .then((res) => res.json()) .then((res) => { - if (res.error) { - throw res.error[0]; - } + return res.json().then((json) => { + if (res.status >= 500 && (json.message || json[0])) { + throw json.message || json[0]; + } + + if (json.error) { + throw json.error[0]; + } + return json; + }); + }) + .then((res) => { if (transform) { res.data = transform(res.data); } diff --git a/js/session.js b/js/session.js index 9b8f623..fbfe6de 100644 --- a/js/session.js +++ b/js/session.js @@ -35,10 +35,10 @@ export const session = (() => { .then((res) => res.code === 200, () => false); if (res) { - bootstrap.Modal.getOrCreateInstance('#loginModal').hide(); admin.getUserDetail(); admin.getStatUser(); comment.comment(); + bootstrap.Modal.getOrCreateInstance('#loginModal').hide(); formEmail.value = null; formPassword.value = null; } @@ -67,18 +67,22 @@ export const session = (() => { .token(document.body.getAttribute('data-key')) .send() .then(async (res) => { - session.set('token', document.body.getAttribute('data-key')); + if (res.code !== 200) { + progress.invalid('request'); + return; + } const config = storage('config'); for (let [key, value] of Object.entries(res.data)) { config.set(key, value); } + session.set('token', document.body.getAttribute('data-key')); await comment.comment(); progress.complete('request'); }).catch(() => { - progress.invalid('request') + progress.invalid('request'); }); }; diff --git a/js/storage.js b/js/storage.js index a34d9dd..078f6c5 100644 --- a/js/storage.js +++ b/js/storage.js @@ -8,16 +8,16 @@ export const storage = (table) => { const set = (key, value) => { let storage = get(); storage[String(key)] = value; - - localStorage.removeItem(table); localStorage.setItem(table, JSON.stringify(storage)); }; const unset = (key) => { + if (!has(key)) { + return; + } + let storage = get(); delete storage[String(key)]; - - localStorage.removeItem(table); localStorage.setItem(table, JSON.stringify(storage)); };