Skip to content

Commit

Permalink
feat: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Oct 5, 2024
1 parent 8718ffc commit cf350fe
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 44 deletions.
19 changes: 7 additions & 12 deletions dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,13 @@ <h6 class="fw-bold m-0 p-0" id="count-like">
</div>

<div class="p-3 bg-theme-light mb-4 rounded-4 shadow">
<div class="row align-items-center justify-content-between">
<div class="col-auto">
<small>
Build with<i class="fa-solid fa-heart mx-1 text-danger"></i>Dewanakl
</small>
</div>
<div class="col-auto">
<small>
<i class="fa-brands fa-github me-1"></i><a target="_blank" href="https://github.com/dewanakl/undangan">dewanakl</a>
</small>
</div>
</div>
<p class="mx-0 mt-0 mb-1 p-0 fw-bold"><i class="fa-solid fa-heart me-1"></i>Project</p>
<p class="mx-0 mt-0 mb-1 p-0">
This project is built with <i class="fa-solid fa-heart text-danger"></i> by <a target="_blank" href="https://github.com/dewanakl/undangan">dewanakl</a>
</p>
<p class="m-0 p-0">
If you want to support me, consider <a target="_blank" href="https://saweria.co/dewanakl">buying me a coffee</a><i class="fa-solid fa-mug-hot ms-1"></i>
</p>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ <h2 class="font-esthetic mt-0 mb-3" style="font-size: 2rem">Allah Subhanahu Wa T
<div class="container">
<div class="text-center">

<h2 class="font-esthetic py-3" style="font-size: 2rem;">Waktu Menuju Acara</h2>
<h2 class="font-esthetic py-3" style="font-size: 2.5rem;">Moment Bahagia</h2>

<div class="border rounded-pill shadow py-2 px-4 mx-2 mb-4">
<!-- Ganti waktunya pada data-waktu (sesuai format tersebut) -->
Expand Down Expand Up @@ -417,7 +417,7 @@ <h2 class="font-esthetic mt-0 mb-3" style="font-size: 2.5rem;">Love Gift</h2>
<div class="d-flex justify-content-between align-items-center mt-2">
<p class="m-0 p-0" style="font-size: 0.95rem;">1234 5678 9101 112</p>
<!-- Ubah juga data-copy sesuai dengan no rekening -->
<button class="btn btn-outline-dark btn-sm rounded-4" data-copy="123456789101112" onclick="util.copy(this, 'Tersalin')"><i class="fa-solid fa-copy me-1"></i>Salin</button>
<button class="btn btn-outline-dark btn-sm rounded-4" style="font-size: 0.8rem;" data-copy="123456789101112" onclick="util.copy(this, 'Tersalin')"><i class="fa-solid fa-copy me-1"></i>Salin</button>
</div>

<p class="mt-2 mb-0 p-0" style="font-size: 0.95rem;">Nama Wahyu Siapa</p>
Expand All @@ -429,7 +429,7 @@ <h2 class="font-esthetic mt-0 mb-3" style="font-size: 2.5rem;">Love Gift</h2>
<div class="d-flex justify-content-between align-items-center mt-2">
<p class="m-0 p-0" style="font-size: 0.95rem;">1234 5678 9101 112</p>
<!-- Ubah juga data-copy sesuai dengan no rekening -->
<button class="btn btn-outline-dark btn-sm rounded-4" data-copy="123456789101112" onclick="util.copy(this, 'Tersalin')"><i class="fa-solid fa-copy me-1"></i>Salin</button>
<button class="btn btn-outline-dark btn-sm rounded-4" style="font-size: 0.8rem;" data-copy="123456789101112" onclick="util.copy(this, 'Tersalin')"><i class="fa-solid fa-copy me-1"></i>Salin</button>
</div>

<p class="mt-2 mb-0 p-0" style="font-size: 0.95rem;">Nama Riski Siapa</p>
Expand Down
2 changes: 1 addition & 1 deletion js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const audio = (() => {
await audio.play();
isPlay = true;
} catch (err) {
alert(err);
isPlay = false;
alert(err);
}
music.disabled = false;
};
Expand Down
4 changes: 2 additions & 2 deletions js/dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -72,7 +72,7 @@ export const dto = (() => {
return {
uuid,
show,
}
};
});

const postCommentRequest = ((id, name, presence, comment) => {
Expand Down
15 changes: 11 additions & 4 deletions js/guest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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');
Expand All @@ -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();
Expand Down
18 changes: 8 additions & 10 deletions js/progress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { util } from './util.js';
import { guest } from './guest.js';

export const progress = (() => {
Expand All @@ -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) => {
Expand All @@ -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';
Expand Down
18 changes: 13 additions & 5 deletions js/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const request = (method, path) => {
})
};

if (url.slice(-1) == '/') {
if (url.slice(-1) === '/') {
url = url.slice(0, -1);
}

Expand All @@ -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);
}
Expand Down
10 changes: 7 additions & 3 deletions js/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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');
});
};

Expand Down
8 changes: 4 additions & 4 deletions js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

Expand Down

0 comments on commit cf350fe

Please sign in to comment.