Skip to content

Commit

Permalink
feat: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Sep 20, 2024
1 parent b446a53 commit b095dff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ <h2 class="font-esthetic mt-0 mb-3" style="font-size: 2.5rem;">Love Gift</h2>
<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>
</div>

<p class="mt-2 mb-0 p-0">Nama Wahyu Siapa</p>
<p class="mt-2 mb-0 p-0" style="font-size: 0.95rem;">Nama Wahyu Siapa</p>
</div>

<div class="col card-body border rounded-4 shadow p-4 mx-4 mt-2 mb-4 text-start" data-aos="fade-down" data-aos-duration="1500">
Expand All @@ -432,7 +432,7 @@ <h2 class="font-esthetic mt-0 mb-3" style="font-size: 2.5rem;">Love Gift</h2>
<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>
</div>

<p class="mt-2 mb-0 p-0">Nama Riski Siapa</p>
<p class="mt-2 mb-0 p-0" style="font-size: 0.95rem;">Nama Riski Siapa</p>
</div>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions js/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const comment = (() => {
document.getElementById('comments').lastElementChild.remove();
}

document.getElementById('comments').innerHTML = card.renderContent(response.data) + document.getElementById('comments').innerHTML;
document.getElementById('comments').insertAdjacentHTML('afterbegin', card.renderContent(response.data));
scroll();
}

Expand Down Expand Up @@ -365,9 +365,17 @@ export const comment = (() => {
return res;
}

const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' && session.isAdmin()) {
res.data.forEach(card.fetchTracker);
}
}
});

observer.observe(comments, { childList: true });
comments.setAttribute('data-loading', 'false');
comments.innerHTML = res.data.map((c) => card.renderContent(c)).join('');
res.data.forEach(card.fetchTracker);
return res;
});
};
Expand Down
2 changes: 1 addition & 1 deletion js/guest.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const guest = (() => {
} else {
const div = document.createElement('div');
div.classList.add('m-2');
div.innerHTML = `<p class="mt-0 mb-1 mx-0 p-0">${guest.getAttribute('data-message')}</p><h2>${util.escapeHtml(name)}</h2>`;
div.innerHTML = `<p class="mt-0 mb-1 mx-0 p-0" style="font-size: 0.95rem;">${guest.getAttribute('data-message')}</p><h2>${util.escapeHtml(name)}</h2>`;
guest.appendChild(div);
}

Expand Down
18 changes: 9 additions & 9 deletions js/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export const pagination = (() => {
};

const next = async () => {
pageNow += perPage;

button.innerHTML = 'Next' + button.innerHTML;
await process();
page.innerText = parseInt(page.innerText) + 1;
};

const prev = async () => {
pageNow -= perPage;

button.innerHTML = button.innerHTML + 'Prev';
await process();
page.innerText = parseInt(page.innerText) - 1;
Expand Down Expand Up @@ -76,6 +80,11 @@ export const pagination = (() => {

const setResultData = (len) => {
resultData = len;

if (pageNow > 0) {
enablePrevious();
}

if (resultData < perPage) {
disabledNext();
return;
Expand All @@ -91,14 +100,8 @@ export const pagination = (() => {
return;
}

pageNow -= perPage;

disabledNext();
await buttonAction(button).prev();

if (pageNow > 0) {
enablePrevious();
}
};

const next = async (button) => {
Expand All @@ -108,11 +111,8 @@ export const pagination = (() => {
return;
}

pageNow += perPage;

disabledPrevious();
await buttonAction(button).next();
enablePrevious();
};

const init = () => {
Expand Down

0 comments on commit b095dff

Please sign in to comment.