From 2f718a144df5504549cec0cc14a534637a64ddc7 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 3 Feb 2022 23:56:48 +0300 Subject: [PATCH] Update app.js --- app.js | 73 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/app.js b/app.js index c10cd8e81..37d507aca 100644 --- a/app.js +++ b/app.js @@ -28,49 +28,23 @@ const CountryItem = { components: { ChannelItem }, - props: ['item', 'normQuery', 'regQuery'], - data() { - return { - count: 0 - } - }, - computed: { - countryChannels() { - if (!this.normQuery) return this.item.channels - - return ( - this.item.channels.filter(c => { - const normResult = c.key.includes(this.normQuery) - const regResult = this.regQuery - ? this.regQuery.test(c.name) || this.regQuery.test(c.id) - : false - - return normResult || regResult - }) || [] - ) - } - }, - watch: { - countryChannels: function (value) { - this.count = value.length - } - }, + props: ['channels', 'normQuery', 'regQuery', 'country'], template: `
- {{item.flag}} {{item.name}} + {{country.flag}} {{country.name}}
-
+
@@ -103,7 +77,7 @@ const CountryItem = { - +
@@ -122,7 +96,25 @@ const App = { query: '', normQuery: '', regQuery: null, - items: [] + countries: [], + channels: [] + } + }, + computed: { + filtered() { + if (!this.normQuery) return this.channels + + return this.channels.filter(c => { + const normResult = c.key.includes(this.normQuery) + const regResult = this.regQuery + ? this.regQuery.test(c.name) || this.regQuery.test(c.id) + : false + + return normResult || regResult + }) + }, + grouped() { + return _.groupBy(this.filtered, 'country') } }, methods: { @@ -138,7 +130,7 @@ const App = { guides = guides.length ? guides : [] guides = _.groupBy(guides, 'channel') - const channels = await fetch('https://iptv-org.github.io/api/channels.json') + this.channels = await fetch('https://iptv-org.github.io/api/channels.json') .then(response => response.json()) .then(arr => arr.map(c => { @@ -147,16 +139,17 @@ const App = { return c }) ) - .then(arr => _.groupBy(arr, 'country')) - .catch(console.log) + .catch(err => { + console.log(err) + return [] + }) const countries = await fetch('https://iptv-org.github.io/api/countries.json') .then(response => response.json()) .catch(console.log) - this.items = countries.map(i => { + this.countries = countries.map(i => { i.expanded = false - i.channels = channels[i.code] || [] return i })