virtual sample : add dynamic comments count attribute on track buttons

This commit is contained in:
isUnknown 2025-02-11 17:49:34 +01:00
parent 7153da14eb
commit db7b6171f7

View file

@ -9,6 +9,7 @@
:aria-controls="track.slug" :aria-controls="track.slug"
:style="`--btn-image: url(${getFrontViewUrl(track)});`" :style="`--btn-image: url(${getFrontViewUrl(track)});`"
@click="selectTrack(track)" @click="selectTrack(track)"
:data-comments="getCommentsCount(track)"
> >
<span>{{ track.title }}</span> <span>{{ track.title }}</span>
</button> </button>
@ -136,6 +137,14 @@ function removeTrack(track) {
(activeTrack) => activeTrack.title !== track.title (activeTrack) => activeTrack.title !== track.title
); );
} }
function getCommentsCount(track) {
let count = 0;
for (const file of track.files) {
count += file?.comments?.length || 0;
}
return count > 0 ? count : undefined;
}
</script> </script>
<style> <style>