2024-01-09 01:26:32 +00:00
|
|
|
<template>
|
|
|
|
<div class="filter channels-container">
|
|
|
|
<div class="filters-sort">
|
|
|
|
<input
|
|
|
|
v-model="search"
|
|
|
|
type="search"
|
2024-01-25 02:07:26 +00:00
|
|
|
:placeholder="`Filter ${channels.length} channels`"
|
2024-01-09 01:26:32 +00:00
|
|
|
class="input input-inline filters-search"
|
|
|
|
>
|
|
|
|
|
|
|
|
<div
|
|
|
|
v-show="order === 'name'"
|
|
|
|
class="filter-sort order noselect"
|
|
|
|
@click="order = 'count'"
|
|
|
|
>
|
2024-01-10 01:00:38 +00:00
|
|
|
<Icon icon="sort-alpha-asc" />
|
2024-01-09 01:26:32 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div
|
|
|
|
v-show="order === 'count'"
|
|
|
|
class="filter-sort order noselect"
|
2024-01-10 01:00:38 +00:00
|
|
|
@click="order = 'name'"
|
2024-01-09 01:26:32 +00:00
|
|
|
>
|
2024-01-10 01:00:38 +00:00
|
|
|
<Icon icon="sort-numeric-desc" />
|
2024-01-09 01:26:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ul
|
|
|
|
class="filter-items nolist"
|
|
|
|
>
|
2024-01-10 01:00:38 +00:00
|
|
|
<li
|
|
|
|
v-for="entity in entities"
|
|
|
|
:key="`filter-channel-${entity.id}`"
|
|
|
|
class="filter-item"
|
|
|
|
:class="{ channel: !entity.isIndependent && entity.type !== 'network', selected: filters.entity?.id === entity.id }"
|
|
|
|
@click="emit('update', 'entity', entity)"
|
|
|
|
>
|
|
|
|
<span class="filter-name">
|
|
|
|
<span
|
|
|
|
class="filter-text"
|
|
|
|
:title="entity.name"
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
v-if="entity.isIndependent || entity.type === 'network'"
|
|
|
|
:src="`/logos/${entity.slug}/favicon_dark.png`"
|
|
|
|
class="favicon"
|
2024-01-09 01:26:32 +00:00
|
|
|
>
|
2024-01-10 01:00:38 +00:00
|
|
|
|
|
|
|
<Icon
|
|
|
|
v-else
|
|
|
|
icon="arrow-up4"
|
|
|
|
/>
|
|
|
|
|
|
|
|
{{ entity.name }}
|
2024-01-09 01:26:32 +00:00
|
|
|
</span>
|
2024-01-10 01:00:38 +00:00
|
|
|
|
|
|
|
<span class="filter-details">
|
|
|
|
<span
|
|
|
|
v-if="entity.count"
|
|
|
|
class="filter-count"
|
|
|
|
>{{ entity.count }}</span>
|
|
|
|
|
|
|
|
<Icon
|
|
|
|
v-if="filters.entity?.id === entity.id"
|
|
|
|
icon="cross2"
|
|
|
|
class="filter-remove"
|
|
|
|
@click.native.stop="emit('update', 'entity', null)"
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</li>
|
2024-01-09 01:26:32 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
import { ref, computed, inject } from 'vue';
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
filters: {
|
|
|
|
type: Object,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
channels: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits(['update']);
|
|
|
|
|
|
|
|
const search = ref('');
|
|
|
|
const searchRegexp = computed(() => new RegExp(search.value, 'i'));
|
|
|
|
const order = ref('name');
|
|
|
|
|
|
|
|
const { pageProps } = inject('pageContext');
|
|
|
|
const { channel: pageChannel } = pageProps;
|
|
|
|
|
2024-01-10 01:00:38 +00:00
|
|
|
function sort(channelA, channelB) {
|
|
|
|
if (order.value === 'count') {
|
|
|
|
return channelB.count - channelA.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return channelA.name.localeCompare(channelB.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
const entities = computed(() => {
|
2024-01-09 01:26:32 +00:00
|
|
|
const filteredChannels = props.channels.filter((channel) => channel.id !== pageChannel?.id
|
|
|
|
&& (searchRegexp.value.test(channel.name)
|
|
|
|
|| searchRegexp.value.test(channel.slug)
|
|
|
|
|| (channel.parent && searchRegexp.value.test(channel.parent.name))
|
|
|
|
|| (channel.parent && searchRegexp.value.test(channel.parent.slug))));
|
|
|
|
|
|
|
|
return Object.values(filteredChannels.reduce((acc, channel) => {
|
|
|
|
if (!channel.parent || channel.isIndependent) {
|
2024-01-25 02:07:26 +00:00
|
|
|
acc[channel.id] = {
|
|
|
|
...channel,
|
|
|
|
children: [],
|
|
|
|
};
|
2024-01-09 01:26:32 +00:00
|
|
|
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!acc[channel.parent.id]) {
|
|
|
|
acc[channel.parent.id] = {
|
|
|
|
...channel.parent,
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
acc[channel.parent.id].children.push(channel);
|
|
|
|
|
|
|
|
return acc;
|
2024-01-10 01:00:38 +00:00
|
|
|
}, {}))
|
|
|
|
.map((network) => ({
|
|
|
|
...network,
|
|
|
|
children: network.children?.sort(sort),
|
|
|
|
count: network.count || network.children?.reduce((acc, channel) => acc + channel.count, 0),
|
|
|
|
}))
|
|
|
|
.sort(sort)
|
|
|
|
.flatMap((network) => [network, ...(network.children || [])]);
|
2024-01-09 01:26:32 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.filter-items {
|
2024-01-26 00:31:15 +00:00
|
|
|
max-height: 15rem;
|
2024-01-09 01:26:32 +00:00
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.filter {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.filter-item.channel {
|
2024-01-10 01:00:38 +00:00
|
|
|
.filter-text .icon {
|
2024-01-25 02:07:26 +00:00
|
|
|
width: 2.25rem;
|
2024-01-09 01:26:32 +00:00
|
|
|
height: 1rem;
|
|
|
|
transform: rotate(-135deg);
|
|
|
|
fill: var(--shadow-weak-30);
|
2024-01-10 01:00:38 +00:00
|
|
|
overflow: hidden; /* prevent parent jumping on load */
|
2024-01-09 01:26:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.favicon {
|
2024-01-25 02:07:26 +00:00
|
|
|
width: 1.75rem;
|
2024-01-09 01:26:32 +00:00
|
|
|
height: 1rem;
|
|
|
|
margin-right: .5rem;
|
|
|
|
object-fit: contain;
|
|
|
|
}
|
|
|
|
</style>
|