Skip to content

Commit

Permalink
feat:show Modal if can't download videos for region
Browse files Browse the repository at this point in the history
  • Loading branch information
Nich87 committed Sep 26, 2023
1 parent c29830b commit 801e5f3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/lib/components/Modals/RegionError.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script lang="ts">
import { Modal, Button } from 'flowbite-svelte';
import { ExclamationCircleOutline } from 'flowbite-svelte-icons';
import { popupRegionErrorModal, togglepopupRegionErrorModal } from '$lib/store';
</script>

{#if popupRegionErrorModal}
<Modal
bind:open={$popupRegionErrorModal}
on:close={() => togglepopupRegionErrorModal()}
size="xs"
autoclose
outsideclose
>
<div class="text-center">
<ExclamationCircleOutline class="mx-auto mb-4 text-gray-400 w-12 h-12 dark:text-gray-200" />
<h3 class="mb-5 text-lg font-normal text-gray-500 dark:text-gray-400">
この動画はあなたの地域では利用出来ません。
</h3>
<Button color="red" class="mr-2">OK</Button>
</div>
</Modal>
{/if}
5 changes: 5 additions & 0 deletions src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { writable } from 'svelte/store';
export const isLoading = writable(false);
export const popupFetchErrorModal = writable(false);
export const popupUrlErrorModal = writable(false);
export const popupRegionErrorModal = writable(false);

export const toggleLoadingState = () => {
isLoading.update((value) => !value);
Expand All @@ -15,3 +16,7 @@ export const togglepopupFetchModal = () => {
export const togglepopupUrlErrorModal = () => {
popupUrlErrorModal.update((value) => !value);
};

export const togglepopupRegionErrorModal = () => {
popupRegionErrorModal.update((value) => !value);
}
5 changes: 3 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Card
} from 'flowbite-svelte';
import { VideoSolid, FileMusicSolid, SearchOutline } from 'flowbite-svelte-icons';
import { toggleLoadingState, togglepopupUrlErrorModal, togglepopupFetchModal } from '$lib/store';
import { toggleLoadingState, togglepopupUrlErrorModal, togglepopupFetchModal,togglepopupRegionErrorModal } from '$lib/store';
import { parseVideoUrl } from '$lib/parseURL';
import type { VideoInfo, PlaylistInfo, SearchInfo } from '$lib/types/index';
import Header from 'components/Header.svelte';
Expand Down Expand Up @@ -91,7 +91,8 @@
});
toggleLoadingState();
if (response.status !== 200) {
togglepopupFetchModal();
let json = await response.json();
json.errorobj.info.error_type === "UNPLAYABLE" ? togglepopupRegionErrorModal() : togglepopupFetchModal();
return console.error(response.status, response);
}
Expand Down

0 comments on commit 801e5f3

Please sign in to comment.