Skip to content

Commit

Permalink
feat: loader on deleting groups
Browse files Browse the repository at this point in the history
  • Loading branch information
VaibhavSingh8 committed Dec 2, 2024
1 parent f37f836 commit 3126f60
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
23 changes: 23 additions & 0 deletions groups/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ const removeLoadingCards = () => {
loadingCards.forEach((card) => mainContainer.removeChild(card));
};

const renderLoader = () => {
const loaderContainer = document.querySelector('.loader');

if (!loaderContainer) {
const loaderContainer = document.createElement('div');
loaderContainer.className = 'loader';
loaderContainer.innerHTML = `
<div class="loader-spin"></div>
`;

document.body.appendChild(loaderContainer);
}
};

const removeLoader = () => {
const loader = document.querySelector('.loader');
if (loader) {
document.body.removeChild(loader);
}
};

const renderGroupById = ({
group,
cardOnClick = () => {},
Expand Down Expand Up @@ -148,4 +169,6 @@ export {
renderNoGroupFound,
renderDeleteConfirmationModal,
removeDeleteConfirmationModal,
renderLoader,
removeLoader,
};
4 changes: 4 additions & 0 deletions groups/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
renderNotAuthenticatedPage,
renderDeleteConfirmationModal,
removeDeleteConfirmationModal,
renderLoader,
removeLoader,
} from './render.js';

import {
Expand Down Expand Up @@ -300,6 +302,7 @@ function showDeleteModal(groupId) {
removeDeleteConfirmationModal();
},
onConfirm: async () => {
renderLoader();
try {
await deleteDiscordGroupRole(groupId);
showToaster('Group deleted successfully');
Expand All @@ -316,6 +319,7 @@ function showDeleteModal(groupId) {
showToaster(error.message || 'Failed to delete group');
} finally {
removeDeleteConfirmationModal();
removeLoader();
}
},
});
Expand Down
36 changes: 36 additions & 0 deletions groups/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,39 @@ For Delete Confirmation Modal
.button--danger:hover {
background-color: #c82333;
}

/*
For Spin Loader
*/

.loader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.8);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1000;
}

.loader-spin {
border: 8px solid #f3f3f3;
border-top: 8px solid #345bdb;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

0 comments on commit 3126f60

Please sign in to comment.