Update index.svelte

This commit is contained in:
Arhey 2022-09-13 22:05:00 +03:00
parent ca7b882fc7
commit e4e5c772fb

View file

@ -1,6 +1,15 @@
<script> <script>
import InfiniteLoading from 'svelte-infinite-loading' import InfiniteLoading from 'svelte-infinite-loading'
import { fetchChannels, hasQuery, countries, filteredChannels, query, search, setSearchParam, setPageTitle } from '../store.js' import {
fetchChannels,
hasQuery,
countries,
filteredChannels,
query,
search,
setSearchParam,
setPageTitle
} from '../store.js'
import { onMount, onDestroy } from 'svelte' import { onMount, onDestroy } from 'svelte'
import CountryItem from '../components/CountryItem.svelte' import CountryItem from '../components/CountryItem.svelte'
import SearchField from '../components/SearchField.svelte' import SearchField from '../components/SearchField.svelte'
@ -17,7 +26,7 @@
$: visible = _countries.slice(0, limit) $: visible = _countries.slice(0, limit)
$: grouped = _.groupBy($filteredChannels, 'country.code') $: grouped = _.groupBy($filteredChannels, 'country')
function loadMore({ detail }) { function loadMore({ detail }) {
let { loaded, complete } = detail let { loaded, complete } = detail
@ -51,7 +60,7 @@
search($query) search($query)
} }
window.onpopstate = (event) => { window.onpopstate = event => {
const q = event.state.q const q = event.state.q
if (q) { if (q) {
setPageTitle(q) setPageTitle(q)
@ -79,7 +88,8 @@
> >
loading... loading...
</div> </div>
{/if} {#each visible as country} {#if grouped[country.code] && grouped[country.code].length > 0} {/if} {#each visible as country (country.code)} {#if grouped[country.code] &&
grouped[country.code].length > 0}
<CountryItem <CountryItem
bind:country="{country}" bind:country="{country}"
bind:channels="{grouped[country.code]}" bind:channels="{grouped[country.code]}"