Skip to content

Commit

Permalink
refactor: guest function
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Jan 20, 2025
1 parent f3dfec0 commit b3508d2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ <h5 class="fw-bold mt-1 mb-0 ms-0 p-0" style="color: var(--bs-gray-900); font-si

<div class="p-3 bg-theme-light mb-4 rounded-4 shadow">
<p class="mx-0 mt-0 mb-1 p-0 fw-bold"><i class="fa-solid fa-heart me-2"></i>Love Project</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>
<p class="m-0 p-0">If you want to support me, consider <a target="_blank" rel="noopener noreferrer" href="https://saweria.co/dewanakl">buying me a coffee</a><i class="fa-solid fa-mug-hot ms-1"></i></p>
</div>
</section>
</div>
Expand Down
14 changes: 8 additions & 6 deletions js/app/guest/guest.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export const guest = (() => {
*/
const open = (button) => {
button.disabled = true;
document.body.scrollIntoView({ behavior: 'instant' });

if (!theme.isAutoMode()) {
document.getElementById('button-theme').style.display = 'none';
Expand Down Expand Up @@ -164,12 +163,14 @@ export const guest = (() => {
offline.init();
progress.init();

countDownDate();
normalizeArabicFont();
information = storage('information');

document.addEventListener('progressDone', showGuestName);
document.addEventListener('progressDone', window.AOS.init);
document.addEventListener('progressDone', () => {
countDownDate();
showGuestName();
window.AOS.init();
normalizeArabicFont();
document.body.scrollIntoView({ behavior: 'instant' });
});

if (session.isAdmin()) {
storage('user').clear();
Expand Down Expand Up @@ -198,6 +199,7 @@ export const guest = (() => {

if (token.length > 0) {
// add 2 progress for config and comment.
// before load image.
progress.add();
progress.add();

Expand Down
25 changes: 17 additions & 8 deletions js/app/guest/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const image = (() => {
/**
* @type {Map<string, string>}
*/
let uniqueUrl = null;
let uniqUrl = null;

/**
* @type {NodeListOf<HTMLImageElement>}
Expand All @@ -14,10 +14,10 @@ export const image = (() => {

let hasSrc = true;

// 6 hour TTL
const ttl = 1000 * 60 * 60 * 6;
// default 6 hour TTL
let ttl = 1000 * 60 * 60 * 6;

const cacheName = 'image_cache';
const cacheName = 'images';

/**
* @param {HTMLImageElement} el
Expand All @@ -27,8 +27,8 @@ export const image = (() => {
const url = el.getAttribute('data-src');
const exp = 'x-expiration-time';

if (uniqueUrl.has(url)) {
el.src = uniqueUrl.get(url);
if (uniqUrl.has(url)) {
el.src = uniqUrl.get(url);
progress.complete('image');
return;
}
Expand Down Expand Up @@ -59,7 +59,7 @@ export const image = (() => {
return c.delete(url).then((s) => s ? fetchPut(c) : res.blob());
}).then((b) => {
el.src = URL.createObjectURL(b);
uniqueUrl.set(url, el.src);
uniqUrl.set(url, el.src);
progress.complete('image');
})
}).catch(() => progress.invalid('image'));
Expand All @@ -85,6 +85,14 @@ export const image = (() => {
*/
const hasDataSrc = () => hasSrc;

/**
* @param {number} v
* @returns {void}
*/
const setTtl = (v) => {
ttl = Number(v)
};

/**
* @returns {void}
*/
Expand All @@ -104,14 +112,15 @@ export const image = (() => {
* @returns {object}
*/
const init = () => {
uniqueUrl = new Map();
uniqUrl = new Map();
images = document.querySelectorAll('img');

images.forEach(progress.add);
hasSrc = Array.from(images).some((i) => i.hasAttribute('data-src'));

return {
load,
setTtl,
hasDataSrc,
};
};
Expand Down

0 comments on commit b3508d2

Please sign in to comment.