Skip to content

Commit

Permalink
fix: hide main title if all sub items unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
Pipazoul committed Dec 15, 2023
1 parent 95c06a9 commit b77e23f
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@
displayedCategories = spliced;
}
async function checkUncheckAll(index: number) {
async function checkUncheckAll(index: number, value: boolean) {
const spliced = displayedCategories.filter((cat, catIndex) => {
if (catIndex === index) {
cat.sub_categorie_items.forEach((subCat) => {
if(subCat){
subCat.checked = !subCat.checked;
subCat.checked = value;
}
});
Expand All @@ -90,6 +90,23 @@
displayedCategories = spliced
}
function checkIfAllUnchecked(categories: Category) {
let checked = false;
console.log(categories);
categories.sub_categorie_items.forEach((subCat) => {
if (subCat) {
console.log('subCat');
console.log(subCat);
if (subCat.checked) {
console.log('checked');
checked = true;
}
}
});
return checked;
}
onMount(() => {
parse();
});
Expand Down Expand Up @@ -150,7 +167,7 @@
<input
type="checkbox"
checked
on:click={async () => {await checkUncheckAll(categoriesIndex)}}
on:click={async (e) => {await checkUncheckAll(categoriesIndex, e.target.checked)}}
class="mr-2"
/>
Sélectionner/Déselectionner tout
Expand Down Expand Up @@ -180,7 +197,10 @@
{#each displayedCategories as categories, categoriesIndex}
{#if categories.checked}
<div class="print:h-screen print:flex print:justify-center print:items-center print:break-after-page print:break-before-page ">
<h1 class="text-4xl">{categories?.category_label}</h1>

{#if checkIfAllUnchecked(categories)}
<h1 class="text-4xl">{categories?.category_label}</h1>
{/if}
</div>
{#each categories.sub_categorie_items as category, categoryIndex}
{#if category?.checked}
Expand Down

0 comments on commit b77e23f

Please sign in to comment.