wip: toggling visibility of newly added download

This commit is contained in:
2025-06-04 22:12:06 -05:00
parent b6bc1645b4
commit 5ca0cd651d
5 changed files with 55 additions and 14 deletions

View File

@@ -7,7 +7,13 @@ import { getComponent } from '@symfony/ux-live-component';
/* stimulusFetch: 'lazy' */
export default class extends Controller {
static targets = ['download']
static targets = ['download', 'downloadRow', 'viewAllBtn']
static values = {
isWidget: Boolean,
perPage: Number,
}
component = null;
async initialize() {
this.component = await getComponent(this.element);
@@ -22,9 +28,38 @@ export default class extends Controller {
// this.fooTarget.addEventListener('click', this._fooBar)
}
downloadRowTargetConnected(target) {
if (Boolean(target.getAttribute('isBroadcasted')) === true) {
this.viewAllBtnTarget.parentElement.append(this.viewAllBtnTarget);
if (this.downloadRowTargets.length > this.perPageValue) {
target.classList.add('hidden');
this.viewAllBtnTarget.classList.remove('hidden');
} else {
this.viewAllBtnTarget.classList.add('hidden');
}
}
}
downloadRowTargetDisconnected(target) {
this.viewAllBtnTarget.parentElement.append(this.viewAllBtnTarget);
let i = 1;
this.downloadRowTargets.forEach((downloadRow) => {
console.log(downloadRow)
if (i <= this.perPageValue) {
downloadRow.classList.remove('hidden');
} else {
downloadRow.classList.add('hidden');
}
})
if (this.downloadRowTargets.length > this.perPage) {
this.viewAllBtnTarget.classList.remove('hidden');
}
}
downloadTargetConnected(target) {
let downloads = this.element.querySelectorAll('tbody tr');
if (downloads.length > 5) {
if (downloads.length > this.perPageValue) {
target.classList.add('hidden');
}
}