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 12, 2024
1 parent 86529c6 commit e77acf6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 49 deletions.
12 changes: 4 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ <h1 class="font-arabic py-4 px-2" style="font-size: 2rem">بِسْمِ اللّ
<h1 class="font-esthetic py-4 px-2" style="font-size: 2rem">Assalamualaikum Warahmatullahi Wabarakatuh</h1>

<p class="pb-3 px-3">
Tanpa mengurangi rasa hormat. Kami mengundang Bapak/Ibu/Saudara/i serta kerabat
sekalian untuk menghadiri acara pernikahan kami:
Tanpa mengurangi rasa hormat, kami mengundang Bapak/Ibu/Saudara/i serta kerabat sekalian untuk menghadiri acara pernikahan kami:
</p>

<!-- Love animation -->
Expand Down Expand Up @@ -293,8 +292,7 @@ <h2 class="d-inline m-0 p-0" id="second">0</h2><small class="ms-1 me-0 my-0 p-0
</div>

<p style="font-size: 0.9rem;" class="mt-4 py-2">
Dengan memohon rahmat dan ridho Allah Subhanahu Wa Ta'ala, insyaAllah kami akan menyelenggarakan
acara :
Dengan memohon rahmat dan ridho Allah Subhanahu Wa Ta'ala, insyaAllah kami akan menyelenggarakan acara:
</p>

<!-- Love animation -->
Expand Down Expand Up @@ -424,8 +422,7 @@ <h1 class="font-esthetic text-center py-3" data-aos="fade-down" data-aos-duratio
<h1 class="font-esthetic mt-0 mb-3" style="font-size: 3rem;">Love Gift</h1>

<p class="mb-3" style="font-size: 0.9rem;">
Tanpa mengurangi rasa hormat, bagi anda yang ingin memberikan tanda kasih untuk kami,
dapat melalui :
Tanpa mengurangi rasa hormat, bagi Anda yang ingin memberikan tanda kasih untuk kami, dapat melalui:
</p>

<div class="overflow-x-hidden">
Expand Down Expand Up @@ -530,8 +527,7 @@ <h1 class="font-esthetic text-center mb-3" style="font-size: 3rem;">Ucapan &amp;
<div class="text-center">

<p style="font-size: 0.9rem;" class="pt-2 pb-1 px-2">
Merupakan suatu kehormatan dan kebahagiaan bagi kami apabila, Bapak / Ibu / Saudara / i.
berkenan untuk memberikan do'a restunya kami ucapkan terimakasih.
Merupakan suatu kehormatan dan kebahagiaan bagi kami apabila Bapak/Ibu/Saudara/i berkenan untuk memberikan do'a restunya. Kami ucapkan terima kasih.
</p>

<h1 class="font-esthetic">Wassalamualaikum Warahmatullahi Wabarakatuh</h1>
Expand Down
2 changes: 1 addition & 1 deletion js/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const card = (() => {
const renderContent = (comment, is_parent) => {
return `
<div ${renderHeader(comment, is_parent)} id="${comment.uuid}">
<div id="body-content-${comment.uuid}" data-tapTime="0" data-liked="false">
<div id="body-content-${comment.uuid}" data-tapTime="0" data-liked="false" ontouchend="like.tapTap(this)">
${renderBody(comment, is_parent)}
</div>
${renderTracker(comment)}
Expand Down
29 changes: 8 additions & 21 deletions js/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,32 +229,24 @@ export const comment = (() => {

const comment = async () => {
card.renderLoading();
const comments = document.getElementById('comments');
const onNullComment = `<div class="h6 text-center fw-bold p-4 my-3 bg-theme-${theme.isDarkMode('dark', 'light')} rounded-4 shadow">Yuk bagikan undangan ini biar banyak komentarnya</div>`;

await request(HTTP_GET, `/api/comment?per=${pagination.getPer()}&next=${pagination.getNext()}`)
.token(session.get('token'))
.then((res) => {
if (res.code !== 200) {
return;
}

const comments = document.getElementById('comments');
pagination.setResultData(res.data.length);

if (res.data.length === 0) {
comments.innerHTML = onNullComment;
return;
}

const uuids = util.extractUUIDs(res.data);
showHide.set('hidden', (() => {
let arrHidden = showHide.get('hidden');
uuids.forEach((c) => {
util.extractUUIDs(res.data).forEach((c) => {
if (!arrHidden.find((item) => item.uuid === c)) {
arrHidden.push({
uuid: c,
show: false,
});
arrHidden.push({ uuid: c, show: false });
}
});

Expand All @@ -263,13 +255,7 @@ export const comment = (() => {

comments.setAttribute('data-loading', 'false');
comments.innerHTML = res.data.map((comment) => card.renderContent(comment)).join('');

uuids.forEach((c) => {
like.setTapTap(c);
});
res.data.forEach((c) => {
card.fetchTracker(c);
});
res.data.forEach(card.fetchTracker);
});
};

Expand All @@ -280,20 +266,21 @@ export const comment = (() => {

if (show) {
button.setAttribute('data-show', 'false');
button.innerText = 'Show replies' + ' (' + ids.length + ')';
button.innerText = 'Show replies';
button.innerText += ' (' + ids.length + ')';

showHide.set('show', showHide.get('show').filter((item) => item !== uuid));
} else {
button.setAttribute('data-show', 'true');
button.innerText = 'Hide replies';

showHide.set('show', [...showHide.get('show'), uuid]);
showHide.set('show', showHide.get('show').concat([uuid]));
}

for (const id of ids) {
showHide.set('hidden', showHide.get('hidden').map((item) => {
if (item.uuid === id) {
return { uuid: id, show: !show };
item.show = !show;
}

return item;
Expand Down
32 changes: 13 additions & 19 deletions js/like.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const like = (() => {
if (!confetti) {
return;
}

const end = Date.now() + 25;
const colors = ['#ff69b4', '#ff1493'];

Expand Down Expand Up @@ -96,29 +96,23 @@ export const like = (() => {
}());
};

const setTapTap = (uuid) => {
const id = document.getElementById(`body-content-${uuid}`);

const action = async () => {
const currentTime = (new Date()).getTime();
const tapLength = currentTime - parseInt(id.getAttribute('data-tapTime'));
const tapTap = async (id) => {
const currentTime = (new Date()).getTime();
const tapLength = currentTime - parseInt(id.getAttribute('data-tapTime'));
const uuid = id.id.replace('body-content-', '');

if (tapLength < 300 && tapLength > 0 && !likes.has(uuid) && id.getAttribute('data-liked') !== 'true') {
animation(id);
id.setAttribute('data-liked', 'true');
await like(document.querySelector(`[onclick="like.like(this)"][data-uuid="${uuid}"]`));
id.setAttribute('data-liked', 'false');
}

id.setAttribute('data-tapTime', currentTime);
};
if (tapLength < 300 && tapLength > 0 && !likes.has(uuid) && id.getAttribute('data-liked') !== 'true') {
animation(id);
id.setAttribute('data-liked', 'true');
await like(document.querySelector(`[onclick="like.like(this)"][data-uuid="${uuid}"]`));
id.setAttribute('data-liked', 'false');
}

id.removeEventListener('touchend', action);
id.addEventListener('touchend', action);
id.setAttribute('data-tapTime', currentTime);
};

return {
like,
setTapTap,
tapTap,
};
})();

0 comments on commit e77acf6

Please sign in to comment.