Skip to content

Commit

Permalink
feat: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Aug 13, 2024
1 parent 07ba464 commit c688aa8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
30 changes: 22 additions & 8 deletions js/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ export const comment = (() => {

const btn = util.disableButton(button);

await request(HTTP_DELETE, '/api/comment/' + owns.get(id))
const status = await request(HTTP_DELETE, '/api/comment/' + owns.get(id))
.token(session.get('token'))
.then((res) => {
if (res.data.status) {
owns.unset(id);
document.getElementById(id).remove();
}
});
.then((res) => res.data.status);

btn.restore();
if (!status) {
btn.restore();
return;
}

owns.unset(id);
document.getElementById(id).remove();

document.querySelectorAll('[data-uuids]').forEach((n) => {
if (n.getAttribute('data-uuids').split(',').find((i) => i === id)) {
const uuids = n.getAttribute('data-uuids').split(',').filter((i) => i !== id).join(',');
n.setAttribute('data-uuids', uuids);

if (uuids.length === 0) {
n.remove();
}
}
});
};

const changeButton = (id, disabled) => {
Expand Down Expand Up @@ -152,6 +164,8 @@ export const comment = (() => {
}

if (id) {
showHide.set('hidden', showHide.get('hidden').concat([{ uuid: response.data.uuid, show: true }]));
showHide.set('show', showHide.get('show').concat([id]));
await comment();
}
}
Expand Down
16 changes: 8 additions & 8 deletions js/like.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ export const like = (() => {
}());
};

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

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

id.setAttribute('data-tapTime', currentTime);
div.setAttribute('data-tapTime', currentTime);
};

return {
Expand Down

0 comments on commit c688aa8

Please sign in to comment.