From f377009397ca6ec918335c7855901685c21ef804 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Tue, 10 Oct 2023 08:17:49 +0300 Subject: [PATCH] Fixes navigation --- src/components/ChannelItem.svelte | 12 ++--- src/components/ChannelPopup.svelte | 3 +- src/components/CountryItem.svelte | 74 +++++++++++++++--------------- src/components/HTMLPreview.svelte | 25 ++++------ src/pages/+page.svelte | 50 ++++++++------------ 5 files changed, 71 insertions(+), 93 deletions(-) diff --git a/src/components/ChannelItem.svelte b/src/components/ChannelItem.svelte index a4644dd9e..69d3485b8 100644 --- a/src/components/ChannelItem.svelte +++ b/src/components/ChannelItem.svelte @@ -4,7 +4,7 @@ import GuidesPopup from './GuidesPopup.svelte' import ChannelPopup from './ChannelPopup.svelte' import Checkbox from './Checkbox.svelte' - import { downloadMode, selected } from '~/store' + import { downloadMode, selected, query } from '~/store' import { fade } from 'svelte/transition' export let channel @@ -13,14 +13,14 @@ const [name, country] = channel.id.split('.') - let currLocation const { open } = getContext('simple-modal') + let prevUrl = '/' const onOpened = () => { - currLocation = window.location.href + prevUrl = window.location.href window.history.pushState({}, `${channel.name} • iptv-org`, `/channels/${country}/${name}`) } - const onClosed = () => { - window.history.pushState({}, `iptv-org`, currLocation || '/') + const onClose = () => { + window.history.pushState({}, `iptv-org`, prevUrl) } const showGuides = () => open( @@ -39,7 +39,7 @@ ChannelPopup, { channel }, { transitionBgProps: { duration: 0 }, transitionWindowProps: { duration: 0 } }, - { onOpened, onClosed } + { onOpened, onClose } ) } diff --git a/src/components/ChannelPopup.svelte b/src/components/ChannelPopup.svelte index 74c1cf4b1..efe76b19a 100644 --- a/src/components/ChannelPopup.svelte +++ b/src/components/ChannelPopup.svelte @@ -4,10 +4,11 @@ import Divider from '~/components/Divider.svelte' import SquareButton from '~/components/SquareButton.svelte' import { getContext } from 'svelte' - const { close } = getContext('simple-modal') export let channel + const { close } = getContext('simple-modal') + const closePopup = () => { close() } diff --git a/src/components/CountryItem.svelte b/src/components/CountryItem.svelte index cdb6a9d14..2ea0c0e25 100644 --- a/src/components/CountryItem.svelte +++ b/src/components/CountryItem.svelte @@ -33,59 +33,59 @@ } -
+

{#if $downloadMode} -
- -
+
+ +
{/if}

{#if expanded} -
- +
+ +
-
{/if}
diff --git a/src/components/HTMLPreview.svelte b/src/components/HTMLPreview.svelte index c28c826e4..84667c409 100644 --- a/src/components/HTMLPreview.svelte +++ b/src/components/HTMLPreview.svelte @@ -82,17 +82,6 @@ function norm(value) { return value.includes(' ') ? `"${value}"` : value } - - function searchBy(q) { - if ($query !== q) { - query.set(q) - hasQuery.set(true) - setTimeout(() => { - goto('/') - }, 0) - } - close() - } @@ -115,22 +104,24 @@ class="border rounded-sm overflow-hidden border-gray-200 bg-[#e6e6e6]" /> {:else if field.type === 'link'} - + {:else if field.type === 'link[]'} {#each field.value as value, i} {#if i > 0} {/if} - + {/each} {:else if field.type === 'external_link'} { - const params = new URLSearchParams(window.location.search) - const q = params.get('q') - if (q) { - setPageTitle(q) - query.set(q) - hasQuery.set(true) - } - if (!$channels.length) { await fetchChannels() } _countries = Object.values($countries) isLoading = false - - if ($hasQuery) { - search($query) - } - - window.onpopstate = event => { - const q = event.state.q - if (q) { - setPageTitle(q) - query.set(q) - hasQuery.set(true) - search($query) - } else { - setPageTitle(null) - hasQuery.set(false) - } - } + search($query) }) afterNavigate(() => { - setSearchParam('q', $query) + const q = $page.url.searchParams.get('q') + if (q) { + setPageTitle(q) + query.set(q) + hasQuery.set(true) + } else { + setPageTitle(null) + hasQuery.set(false) + } search($query) }) @@ -121,9 +104,12 @@ loading... {/if} - {#each visible as country (country.code)} - {#if grouped[country.code] && grouped[country.code].length > 0} - 0} + {/if} {/each}