chore: show loader when deleting community question or comment (#102)

* fix: move org slot media query to postcss

* fix: remove slot css

* fix: remove unused vars

* chore: show loader when deleting a question or comment
This commit is contained in:
Rotimi Best
2023-12-13 16:31:27 +03:00
committed by GitHub
parent aa2f7c58c8
commit e68c36d7fb
3 changed files with 30 additions and 4 deletions
@@ -7,6 +7,7 @@
export let onCancel = () => {}; export let onCancel = () => {};
export let open = false; export let open = false;
export let isQuestion = false; export let isQuestion = false;
export let isDeleting = false;
</script> </script>
<Modal <Modal
@@ -32,6 +33,7 @@
variant={VARIANTS.CONTAINED} variant={VARIANTS.CONTAINED}
label="Yes, delete" label="Yes, delete"
onClick={onDelete} onClick={onDelete}
isLoading={isDeleting}
/> />
</div> </div>
</div> </div>
@@ -67,11 +67,13 @@
let isEditMode = false; let isEditMode = false;
let deleteComment = { let deleteComment = {
shouldDelete: false, shouldDelete: false,
commentId: '' commentId: '',
isDeleting: false
}; };
let deleteQuestion = { let deleteQuestion = {
shouldDelete: false, shouldDelete: false,
questionId: '' questionId: '',
isDeleting: false
}; };
let editContent = { let editContent = {
title: '', title: '',
@@ -267,11 +269,15 @@
async function handleDelete(isQuestion: boolean) { async function handleDelete(isQuestion: boolean) {
if (!isQuestion) { if (!isQuestion) {
deleteComment.isDeleting = true;
const { error } = await supabase const { error } = await supabase
.from('community_answer') .from('community_answer')
.delete() .delete()
.match({ id: deleteComment.commentId }); .match({ id: deleteComment.commentId });
deleteComment.isDeleting = false;
if (error) { if (error) {
snackbar.error('Error deleting comments'); snackbar.error('Error deleting comments');
console.log('Error deleting comments', error); console.log('Error deleting comments', error);
@@ -286,6 +292,7 @@
// Handle only delete comment // Handle only delete comment
return; return;
} }
deleteQuestion.isDeleting = true;
const { error: commentDeleteError } = await supabase const { error: commentDeleteError } = await supabase
.from('community_answer') .from('community_answer')
@@ -295,6 +302,8 @@
if (commentDeleteError) { if (commentDeleteError) {
snackbar.error('Error deleting comments'); snackbar.error('Error deleting comments');
console.log('Error deleting comments', commentDeleteError); console.log('Error deleting comments', commentDeleteError);
deleteQuestion.isDeleting = false;
return; return;
} }
@@ -311,6 +320,7 @@
snackbar.success('Deleted successfully'); snackbar.success('Deleted successfully');
goto(`/lms/community`); goto(`/lms/community`);
deleteQuestion.isDeleting = false;
} }
$: browser && fetchCommunityQuestion(slug); $: browser && fetchCommunityQuestion(slug);
@@ -322,6 +332,7 @@
<DeleteModal <DeleteModal
bind:open={deleteQuestion.shouldDelete} bind:open={deleteQuestion.shouldDelete}
bind:isDeleting={deleteQuestion.isDeleting}
onCancel={() => { onCancel={() => {
deleteQuestion.shouldDelete = false; deleteQuestion.shouldDelete = false;
deleteQuestion.questionId = ''; deleteQuestion.questionId = '';
@@ -332,6 +343,7 @@
<DeleteModal <DeleteModal
bind:open={deleteComment.shouldDelete} bind:open={deleteComment.shouldDelete}
isDeleting={deleteComment.isDeleting}
onCancel={() => { onCancel={() => {
deleteComment.shouldDelete = false; deleteComment.shouldDelete = false;
deleteComment.commentId = ''; deleteComment.commentId = '';
@@ -67,11 +67,13 @@
let isEditMode = false; let isEditMode = false;
let deleteComment = { let deleteComment = {
shouldDelete: false, shouldDelete: false,
commentId: '' commentId: '',
isDeleting: false
}; };
let deleteQuestion = { let deleteQuestion = {
shouldDelete: false, shouldDelete: false,
questionId: '' questionId: '',
isDeleting: false
}; };
let editContent = { let editContent = {
title: '', title: '',
@@ -267,11 +269,15 @@
async function handleDelete(isQuestion: boolean) { async function handleDelete(isQuestion: boolean) {
if (!isQuestion) { if (!isQuestion) {
deleteComment.isDeleting = true;
const { error } = await supabase const { error } = await supabase
.from('community_answer') .from('community_answer')
.delete() .delete()
.match({ id: deleteComment.commentId }); .match({ id: deleteComment.commentId });
deleteComment.isDeleting = false;
if (error) { if (error) {
snackbar.error('Error deleting comments'); snackbar.error('Error deleting comments');
console.log('Error deleting comments', error); console.log('Error deleting comments', error);
@@ -286,6 +292,7 @@
// Handle only delete comment // Handle only delete comment
return; return;
} }
deleteQuestion.isDeleting = true;
const { error: commentDeleteError } = await supabase const { error: commentDeleteError } = await supabase
.from('community_answer') .from('community_answer')
@@ -295,6 +302,8 @@
if (commentDeleteError) { if (commentDeleteError) {
snackbar.error('Error deleting comments'); snackbar.error('Error deleting comments');
console.log('Error deleting comments', commentDeleteError); console.log('Error deleting comments', commentDeleteError);
deleteQuestion.isDeleting = false;
return; return;
} }
@@ -311,6 +320,7 @@
snackbar.success('Deleted successfully'); snackbar.success('Deleted successfully');
goto(`${$currentOrgPath}/community`); goto(`${$currentOrgPath}/community`);
deleteQuestion.isDeleting = false;
} }
$: browser && fetchCommunityQuestion(slug); $: browser && fetchCommunityQuestion(slug);
@@ -322,6 +332,7 @@
<DeleteModal <DeleteModal
bind:open={deleteQuestion.shouldDelete} bind:open={deleteQuestion.shouldDelete}
bind:isDeleting={deleteQuestion.isDeleting}
onCancel={() => { onCancel={() => {
deleteQuestion.shouldDelete = false; deleteQuestion.shouldDelete = false;
deleteQuestion.questionId = ''; deleteQuestion.questionId = '';
@@ -332,6 +343,7 @@
<DeleteModal <DeleteModal
bind:open={deleteComment.shouldDelete} bind:open={deleteComment.shouldDelete}
isDeleting={deleteComment.isDeleting}
onCancel={() => { onCancel={() => {
deleteComment.shouldDelete = false; deleteComment.shouldDelete = false;
deleteComment.commentId = ''; deleteComment.commentId = '';