Update app.js

This commit is contained in:
Aleksandr Statciuk 2022-01-15 03:05:54 +03:00
parent 2563aab667
commit 6ed6e6c887
3 changed files with 1147 additions and 13 deletions

1102
.gh-pages/api/countries.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -10,10 +10,39 @@ document.addEventListener('alpine:init', () => {
}, },
async init() { async init() {
this.items = await fetch('items.json') const countries = await fetch('api/countries.json')
.then(response => response.json()) .then(response => response.json())
.catch(console.log) .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]) {
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 this.isLoading = false
} }
})) }))

View file

@ -60,18 +60,19 @@
<div class="level-item">Loading...</div> <div class="level-item">Loading...</div>
</div> </div>
<template x-for="country in items"> <template x-for="item in items">
<div <div
class="card mb-3 is-shadowless" class="card mb-3 is-shadowless"
style="border: 1px solid #dbdbdb" style="border: 1px solid #dbdbdb"
x-data="{ x-data="{
count: 0, count: 0,
get countryChannels() { get countryChannels() {
if (!_query) return country.channels if (!_query) return item.channels
const normQuery = _query.toLowerCase()
return country.channels.filter(c => { return item.channels.filter(c => {
return c.hash.includes(_query) return c.hash.includes(normQuery)
}) }) || []
} }
}" }"
x-show="countryChannels.length > 0" x-show="countryChannels.length > 0"
@ -81,14 +82,14 @@
> >
<div <div
class="card-header is-shadowless is-clickable" class="card-header is-shadowless is-clickable"
@click="country.expanded = !country.expanded" @click="item.expanded = !item.expanded"
> >
<span class="card-header-title" x-text="`${country.flag} ${country.name}`"></span> <span class="card-header-title" x-text="`${item.flag} ${item.name}`"></span>
<button class="card-header-icon" aria-label="more options"> <button class="card-header-icon" aria-label="more options">
<span class="icon"> <span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"> <svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">
<path <path
x-show="!country.expanded" x-show="!item.expanded"
fill="none" fill="none"
stroke="currentColor" stroke="currentColor"
stroke-linecap="round" stroke-linecap="round"
@ -97,7 +98,7 @@
d="M112 184l144 144 144-144" d="M112 184l144 144 144-144"
/> />
<path <path
x-show="country.expanded" x-show="item.expanded"
fill="none" fill="none"
stroke="currentColor" stroke="currentColor"
stroke-linecap="round" stroke-linecap="round"
@ -109,7 +110,7 @@
</span> </span>
</button> </button>
</div> </div>
<div class="card-content" x-show="country.expanded || (count > 0 && _query.length)"> <div class="card-content" x-show="item.expanded || (count > 0 && _query.length)">
<div class="table-container"> <div class="table-container">
<table class="table" style="min-width: 100%"> <table class="table" style="min-width: 100%">
<thead> <thead>
@ -132,10 +133,12 @@
/> />
</td> </td>
<td class="is-vcentered" nowrap> <td class="is-vcentered" nowrap>
<div x-text="channel.display_name"></div> <template x-for="name in channel.name">
<p x-text="name"></p>
</template>
</td> </td>
<td class="is-vcentered" nowrap> <td class="is-vcentered" nowrap>
<code x-text="channel.tvg_id"></code> <code x-text="channel.id"></code>
</td> </td>
<td class="is-vcentered"> <td class="is-vcentered">
<template x-for="guide in channel.guides"> <template x-for="guide in channel.guides">