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

View file

@ -10,10 +10,39 @@ document.addEventListener('alpine:init', () => {
},
async init() {
this.items = await fetch('items.json')
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]) {
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
}
}))