Skip to content

Commit

Permalink
refactor: clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Dec 29, 2024
1 parent fa61650 commit 4bfaefc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ <h6 class="fw-semibold m-1" style="color: var(--bs-gray-900);"><i class="fa-soli
<!-- Logout -->
<div class="d-md-none d-lg-none d-xl-none">
<div class="p-3 bg-theme-light mb-3 rounded-4 shadow">
<button type="button" class="btn btn-danger btn-sm w-100 text-center fw-semibold rounded-4 shadow-sm" onclick="admin.logout()" data-offline-disabled>
<button type="button" class="btn btn-danger btn-sm w-100 text-center fw-semibold rounded-4 shadow-sm" onclick="admin.logout()">
<i class="fa-solid fa-right-from-bracket me-2"></i>Logout
</button>
</div>
Expand Down
62 changes: 40 additions & 22 deletions js/guest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ import { bootstrap } from './bootstrap.js';

export const guest = (() => {

/**
* @type {ReturnType<typeof storage>|null}
*/
let information = null;

/**
* @returns {void}
*/
const countDownDate = () => {
const until = document.getElementById('count-down')?.getAttribute('data-time')?.replace(' ', 'T');
if (!until) {
return;
}

const count = (new Date(until)).getTime();

setInterval(() => {
const distance = Math.abs(count - Date.now());

document.getElementById('day').innerText = Math.floor(distance / (1000 * 60 * 60 * 24));
document.getElementById('hour').innerText = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
document.getElementById('minute').innerText = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
document.getElementById('second').innerText = Math.floor((distance % (1000 * 60)) / 1000);
}, 1000);
};

/**
* @param {string} id
* @param {number} speed
Expand All @@ -37,28 +63,8 @@ export const guest = (() => {
};

/**
* @type {ReturnType<typeof storage>|null}
* @returns {void}
*/
let information = null;

const countDownDate = () => {
const until = document.getElementById('count-down')?.getAttribute('data-time')?.replace(' ', 'T');
if (!until) {
return;
}

const count = (new Date(until)).getTime();

setInterval(() => {
const distance = Math.abs(count - Date.now());

document.getElementById('day').innerText = Math.floor(distance / (1000 * 60 * 60 * 24));
document.getElementById('hour').innerText = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
document.getElementById('minute').innerText = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
document.getElementById('second').innerText = Math.floor((distance % (1000 * 60)) / 1000);
}, 1000);
};

const animation = () => {
const duration = 15 * 1000;
const animationEnd = Date.now() + duration;
Expand Down Expand Up @@ -100,6 +106,9 @@ export const guest = (() => {
})();
};

/**
* @returns {void}
*/
const name = () => {
const raw = window.location.search.split('to=');
let name = null;
Expand Down Expand Up @@ -127,6 +136,10 @@ export const guest = (() => {
opacity('loading', 0.025);
};

/**
* @param {HTMLButtonElement} button
* @returns {void}
*/
const open = (button) => {
button.disabled = true;
document.body.scrollIntoView({ behavior: 'instant' });
Expand Down Expand Up @@ -162,11 +175,15 @@ export const guest = (() => {
*/
const closeInformation = () => information.set('info', true);

/**
* @returns {void}
*/
const init = () => {
audio.init();
theme.init();
session.init();
offline.init();

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

Expand Down Expand Up @@ -198,7 +215,6 @@ export const guest = (() => {

progress.add();
progress.add();
comment.init();
progress.init();

session.guest()
Expand All @@ -209,6 +225,8 @@ export const guest = (() => {
}

progress.complete('request');

comment.init();
comment.comment()
.then(() => progress.complete('comment'))
.catch(() => progress.invalid('comment'));
Expand Down
20 changes: 7 additions & 13 deletions js/like.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ export const like = (() => {
let likes = null;

/**
* Handles the like button functionality.
*
* @param {HTMLButtonElement} button - The button element that was clicked.
* @returns {Promise<void>} - A promise that resolves when the like action is complete.
* @param {HTMLButtonElement} button
* @returns {Promise<void>}
*/
const like = async (button) => {
const id = button.getAttribute('data-uuid');
Expand Down Expand Up @@ -65,9 +63,8 @@ export const like = (() => {
};

/**
* Triggers a confetti animation with heart shapes around a specified div element.
*
* @param {HTMLElement} div - The div element around which the confetti animation will occur.
* @param {HTMLElement} div
* @returns {void}
*/
const animation = (div) => {
if (!confetti) {
Expand Down Expand Up @@ -114,11 +111,8 @@ export const like = (() => {
};

/**
* Handles the tap event on a given div element. If the tap is detected within a certain time frame,
* it triggers a like action and an animation.
*
* @param {HTMLElement} div - The div element that was tapped.
* @returns {Promise<void>} - A promise that resolves when the like action is complete.
* @param {HTMLElement} div
* @returns {Promise<void>}
*/
const tapTap = async (div) => {
if (!navigator.onLine) {
Expand All @@ -143,7 +137,7 @@ export const like = (() => {
};

/**
* Initializes the likes variable by retrieving it from storage.
* @returns {void}
*/
const init = () => {
likes = storage('likes');
Expand Down

0 comments on commit 4bfaefc

Please sign in to comment.