Update website

- faster site loading
- added more channels
This commit is contained in:
Aleksandr Statciuk 2022-01-25 20:51:23 +03:00
parent 7fb8250025
commit 3f5ff5b671
2 changed files with 208 additions and 193 deletions

View file

@ -1,54 +1,158 @@
document.addEventListener('alpine:init', () => {
Alpine.data('list', () => ({
isLoading: true,
query: '',
_query: '',
items: [],
const ChannelItem = {
props: ['channel'],
template: `
<tr>
<td class="is-vcentered" style="min-width: 150px; text-align: center">
<img
loading="lazy"
v-show="channel.logo"
:src="channel.logo"
style="max-width: 100px; max-height: 50px; vertical-align: middle"
/>
</td>
<td class="is-vcentered" nowrap>
<p v-text="channel.name"></p>
</td>
<td class="is-vcentered" nowrap>
<code v-text="channel.id"></code>
</td>
<td class="is-vcentered">
<p v-for="guide in channel.guides"><code style="white-space: nowrap" v-text="guide"></code></p>
</td>
</tr>
`
}
search() {
this._query = this.query.toLowerCase()
},
async init() {
const countries = await fetch('api/countries.json')
.then(response => response.json())
.catch(console.log)
const channels = await fetch('api/channels.json')
.then(response => response.json())
.catch(console.log)
let items = {}
for (let channel of channels) {
if (!items[channel.country]) {
if (!countries[channel.country]) {
console.log('Warning: Wrong country code', channel)
continue
}
const country = countries[channel.country]
items[channel.country] = {
flag: country.flag,
name: country.name,
expanded: false,
channels: []
}
}
channel.hash = `${channel.id}_${channel.name}`.toLowerCase()
items[channel.country].channels.push(channel)
}
items = Object.values(items).sort((a, b) => {
if (a.name > b.name) return 1
if (a.name < b.name) return -1
return 0
})
this.items = items
this.isLoading = false
const CountryItem = {
components: {
ChannelItem
},
props: ['item', 'query'],
data() {
return {
count: 0
}
}))
})
},
computed: {
countryChannels() {
if (!this.query) return this.item.channels
return (
this.item.channels.filter(c => {
return c.key.includes(this.query)
}) || []
)
}
},
watch: {
countryChannels: function (value) {
this.count = value.length
}
},
template: `
<div
class="card mb-3 is-shadowless"
style="border: 1px solid #dbdbdb"
v-show="countryChannels && countryChannels.length > 0"
>
<div
class="card-header is-shadowless is-clickable"
@click="item.expanded = !item.expanded"
>
<span class="card-header-title">{{item.flag}}&nbsp;{{item.name}}</span>
<button class="card-header-icon" aria-label="more options">
<span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">
<path
v-show="!item.expanded"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="48"
d="M112 184l144 144 144-144"
/>
<path
v-show="item.expanded"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="48"
d="M112 328l144-144 144 144"
/>
</svg>
</span>
</button>
</div>
<div class="card-content" v-show="item.expanded || (count > 0 && query.length)">
<div class="table-container">
<table class="table" style="min-width: 100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>TVG-ID</th>
<th>EPG</th>
</tr>
</thead>
<tbody>
<channel-item v-for="channel in countryChannels" :channel="channel"></channel-item>
</tbody>
</table>
</div>
</div>
</div>
`
}
const App = {
components: {
CountryItem
},
data() {
return {
isLoading: true,
query: '',
normQuery: '',
items: []
}
},
methods: {
search() {
this.normQuery = this.query.replace(/\s/g, '').toLowerCase()
}
},
async mounted() {
const guides = await fetch('https://iptv-org.github.io/epg/api/channels.json')
.then(response => response.json())
.catch(console.log)
const channels = await fetch('https://iptv-org.github.io/api/channels.json')
.then(response => response.json())
.then(arr =>
arr.map(c => {
const found = guides.find(g => g.id === c.id)
c.key = `${c.id}_${c.name}`.replace(/\s/g, '').toLowerCase()
c.guides = found ? found.guides : []
return c
})
)
.then(arr => groupBy(arr, 'country'))
.catch(console.log)
const countries = await fetch('https://iptv-org.github.io/api/countries.json')
.then(response => response.json())
.catch(console.log)
this.items = countries.map(i => {
i.expanded = false
i.channels = channels[i.code] || []
return i
})
this.isLoading = false
}
}
Vue.createApp(App).mount('#app')