|
| 1 | +<script lang="ts"> |
| 2 | + import Badge from '@nick-mazuk/ui-svelte/src/elements/badge/badge.svelte' |
| 3 | + import type { ScriptData } from '$lib/types/script-data' |
| 4 | + import Button from '@nick-mazuk/ui-svelte/src/elements/button/button.svelte' |
| 5 | + import { download } from '$lib/lib/download-file' |
| 6 | + import { sentenceCase } from '@nick-mazuk/lib/text-styling' |
| 7 | + import { format } from 'date-fns' |
| 8 | +
|
| 9 | + export let data: ScriptData |
| 10 | + export let show: boolean |
| 11 | + export let first: boolean |
| 12 | + export let last: boolean |
| 13 | +
|
| 14 | + let isDownloading = false |
| 15 | + let showMore = false |
| 16 | +
|
| 17 | + const handleDownload = async () => { |
| 18 | + isDownloading = true |
| 19 | + const response = await fetch( |
| 20 | + `https://raw.githubusercontent.com/Nick-Mazuk/jw-lua-scripts/master/dist/${data.fileName}` |
| 21 | + ) |
| 22 | + const file = await response.text() |
| 23 | + download(data.fileName, file) |
| 24 | + isDownloading = false |
| 25 | + } |
| 26 | +
|
| 27 | + $: if (show) showMore = false |
| 28 | +</script> |
| 29 | + |
| 30 | +<article |
| 31 | + class:hidden="{!show}" |
| 32 | + class="border-b py-6" |
| 33 | + class:pt-0="{first}" |
| 34 | + class:pb-0="{last}" |
| 35 | + class:border-none="{last}" |
| 36 | +> |
| 37 | + <div class="flex space-x-6 items-center justify-between"> |
| 38 | + <div> |
| 39 | + <h3 class="h5">{sentenceCase(data.name)}</h3> |
| 40 | + <p>{data.shortDescription}</p> |
| 41 | + </div> |
| 42 | + <div class="flex-none hidden sm:block"> |
| 43 | + <Button size="small" on:click="{handleDownload}" loading="{isDownloading}"> |
| 44 | + Download |
| 45 | + </Button> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + <div class="flex mt-3 space-x-3 items-baseline sm:space-x-0 sm:mt-0"> |
| 49 | + <div class="sm:hidden"> |
| 50 | + <Button size="small" on:click="{handleDownload}" loading="{isDownloading}"> |
| 51 | + Download |
| 52 | + </Button> |
| 53 | + </div> |
| 54 | + <div> |
| 55 | + <Button |
| 56 | + variant="link" |
| 57 | + glue="{['left', 'bottom', 'right']}" |
| 58 | + on:click="{() => (showMore = !showMore)}" |
| 59 | + > |
| 60 | + {showMore ? 'Hide' : 'Show'} details |
| 61 | + </Button> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + {#if showMore} |
| 65 | + <div class="pt-3 text-gray-700"> |
| 66 | + {#if data.notes} |
| 67 | + <p class="my-3">{data.notes}</p> |
| 68 | + {/if} |
| 69 | + {#if data.author.name || data.author.website || data.author.email} |
| 70 | + <h4>Author</h4> |
| 71 | + {#if data.author.name} |
| 72 | + <p>{data.author.name}</p> |
| 73 | + {/if} |
| 74 | + {#if data.author.website} |
| 75 | + <p> |
| 76 | + Website: <a href="{data.author.website}" target="_blank" rel="noreferrer"> |
| 77 | + {data.author.website} |
| 78 | + </a> |
| 79 | + </p> |
| 80 | + {/if} |
| 81 | + {#if data.author.email} |
| 82 | + <p>Email: <a href="mailto:{data.author.email}">{data.author.email}</a></p> |
| 83 | + {/if} |
| 84 | + {/if} |
| 85 | + {#if data.categories.length > 0} |
| 86 | + <h4>Categories</h4> |
| 87 | + <div class="flex space-x-0.5 mt-1"> |
| 88 | + {#each data.categories as category} |
| 89 | + <Badge>{category}</Badge> |
| 90 | + {/each} |
| 91 | + </div> |
| 92 | + {/if} |
| 93 | + {#if data.version || data.date} |
| 94 | + <h4>Version</h4> |
| 95 | + <p>Version {data.version}</p> |
| 96 | + {#if data.date} |
| 97 | + <p>{format(new Date(data.date), 'MMMM d, YYY')}</p> |
| 98 | + {/if} |
| 99 | + {/if} |
| 100 | + <h4>Requirements</h4> |
| 101 | + {#if data.requireSelection} |
| 102 | + <p>Requires music selection to run</p> |
| 103 | + {/if} |
| 104 | + {#if data.requireScore} |
| 105 | + <p>Requires score view to run</p> |
| 106 | + {/if} |
| 107 | + {#if data.copyright} |
| 108 | + <h4>Licence</h4> |
| 109 | + <p>Copyright {data.copyright}</p> |
| 110 | + {/if} |
| 111 | + </div> |
| 112 | + {/if} |
| 113 | +</article> |
| 114 | + |
| 115 | +<style> |
| 116 | + h4 { |
| 117 | + @apply h6 text-foreground mt-3; |
| 118 | + } |
| 119 | +</style> |
0 commit comments