aboutsummaryrefslogtreecommitdiff
path: root/src/routes/reader/+page.svelte
blob: b6cce06608507b385e68b5c9f0f93ab81101b4fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<script>
import Notice from "$lib/Error/Notice.svelte";
import Message from "$lib/Loading/Message.svelte";
import MangaDexChapters from "$lib/Reader/Chapters/MangaDex.svelte";
import RawkumaChapters from "$lib/Reader/Chapters/Rawkuma.svelte";
import {
	decodeResource,
	fetchResource,
	identify,
	Resource,
} from "$lib/Reader/resource";
import InputTemplate from "$lib/Tools/InputTemplate.svelte";

let submission = "";

$: resourceIdentity = identify(submission);
</script>

<InputTemplate field="Manga URL" bind:submission submitText="Read" preserveCase>
  {#if resourceIdentity}
    {#await fetchResource(submission)}
      <Message message="Loading chapters ..." />
    {:then response}
      {#if response.ok}
        {#await decodeResource(response, submission) then data}
          {#if resourceIdentity === Resource.MangaDex}
            <MangaDexChapters {data} />
          {:else if resourceIdentity === Resource.Rawkuma}
            <RawkumaChapters {data} />
          {/if}
        {:catch error}
          <Notice>{error}</Notice>
        {/await}
      {:else}
        <Notice>Failed to fetch data</Notice>
      {/if}
    {:catch}
      <Notice>An unknown error has occurred.</Notice>
    {/await}
  {:else}
    <Notice>Invalid URL</Notice>
  {/if}
</InputTemplate>