|
1 | 1 | <script lang="ts"> |
2 | 2 | import {formatFileSize} from "../util/filesize.ts"; |
3 | 3 | import { |
4 | | - CircleXIcon, DownloadIcon, |
| 4 | + ChevronDownIcon, ChevronUpIcon, CircleXIcon, DownloadIcon, |
5 | 5 | FileAudioIcon, |
6 | 6 | FileIcon, |
7 | 7 | FileVideoIcon, FrownIcon, HeartIcon, |
|
20 | 20 | import {truncateFileName} from "../util/truncate.ts"; |
21 | 21 |
|
22 | 22 | let manager: WebsocketManager; |
| 23 | + let showAllFiles = $state(false); |
| 24 | + const previewFileLimit = 8; |
23 | 25 |
|
24 | 26 | interface Props { |
25 | 27 | RoomId: undefined | string; |
|
47 | 49 |
|
48 | 50 | </script> |
49 | 51 |
|
50 | | -<div class="card h-full min-h-svh sm:min-h-0 bg-base-100 w-screen sm:w-full sm:h-auto max-w-lg gap-3 space-y-6"> |
51 | | - <div class="card-body flex-col justify-between h-full md:h-auto gap-16"> |
| 52 | +<div class="card relative h-[100dvh] bg-base-100 w-screen sm:w-full sm:max-h-[calc(100dvh-2rem)] max-w-lg {$currentFileOffer?.files.length > previewFileLimit ? 'sm:h-[min(100dvh-2rem,40rem)]' : 'sm:h-auto'}"> |
| 53 | + <div class="card-body flex h-full min-h-0 flex-col gap-6"> |
52 | 54 | <div class="flex items-center space-x-4"> |
53 | 55 | <div class="bg-gray-100 p-2 rounded-full"> |
54 | 56 | <ShareIcon class="h-6 w-6"/> |
|
57 | 59 | <p class="text-2xl sm:text-3xl font-bold modal-title">File transfer</p> |
58 | 60 | </div> |
59 | 61 | </div> |
60 | | - {#if $downloadFinished} |
61 | | - <div> |
| 62 | + <div class="min-h-0 flex-1 overflow-y-auto pb-28 pr-1"> |
| 63 | + {#if $downloadFinished} |
| 64 | + <div> |
62 | 65 | <p class="text-xl">Download finished!</p> |
63 | 66 | <p class="text-gray-500">Please consider donating! It helps the platform running ❤️</p> |
64 | 67 |
|
65 | 68 | </div> |
66 | | - {:else if $downloadCancelled} |
67 | | - <div> |
| 69 | + {:else if $downloadCancelled} |
| 70 | + <div> |
68 | 71 | <CircleXIcon class="w-32 h-32 mx-auto"/> |
69 | 72 | <p class="text-xl">Download cancelled</p> |
70 | 73 | <p class="text-gray-500">The download has been cancelled by the sender. <a class="link link-primary" |
71 | 74 | href="/">Return to |
72 | 75 | homepage</a></p> |
73 | 76 | </div> |
74 | | - {:else if $isConnected === false || $checkedRoomCode === false} |
75 | | - <div> |
| 77 | + {:else if $isConnected === false || $checkedRoomCode === false} |
| 78 | + <div> |
76 | 79 | <div class="flex flex-row gap-3"> |
77 | 80 | <Loader2Icon class="animate-spin"/> |
78 | 81 | <p class="text-base-content/70 text-lg">Setting up the connection</p> |
79 | 82 | </div> |
80 | 83 | </div> |
81 | | - {:else if $currentFileOffer} |
82 | | - <div> |
83 | | - <ul class="space-y-2"> |
84 | | - {#each $currentFileOffer.files as file} |
| 84 | + {:else if $currentFileOffer} |
| 85 | + <div> |
| 86 | + <ul id="offered-files" class="space-y-2"> |
| 87 | + {#each $currentFileOffer.files.slice(0, showAllFiles ? undefined : previewFileLimit) as file} |
85 | 88 | <li class="flex flex-col py-2"> |
86 | 89 | <div class="flex items-center justify-between"> |
87 | 90 | <div class="flex items-center space-x-3"> |
|
104 | 107 | </li> |
105 | 108 | {/each} |
106 | 109 | </ul> |
107 | | - <div class="mt-4"> |
108 | | - <span class="text-gray-500">Total size: {formatFileSize($currentFileOffer.files.reduce((acc, file) => acc + file.size, 0))}</span> |
109 | | - </div> |
110 | 110 | </div> |
111 | | - {:else if ($roomExists === false && $checkedRoomCode && $isConnected) || $room?.user_count === 1} |
112 | | - <div> |
| 111 | + {:else if ($roomExists === false && $checkedRoomCode && $isConnected) || $room?.user_count === 1} |
| 112 | + <div> |
113 | 113 | <FrownIcon class="w-32 h-32 mx-auto"/> |
114 | 114 | <p class="text-xl">Invalid link</p> |
115 | 115 | <p class="text-gray-500">The link you received is incorrect. Please try again. <a |
116 | 116 | class="link link-primary" href="/">Return to homepage</a></p> |
117 | 117 | </div> |
118 | | - {:else} |
119 | | - <div> |
| 118 | + {:else} |
| 119 | + <div> |
120 | 120 | <div class="flex flex-row gap-3"> |
121 | 121 | <Loader2Icon class="animate-spin"/> |
122 | 122 | <p class="text-base-content/70 text-lg">Waiting for file(s)...</p> |
123 | 123 | </div> |
124 | 124 | </div> |
| 125 | + {/if} |
| 126 | + </div> |
| 127 | + {#if $currentFileOffer && $currentFileOffer.files.length > previewFileLimit} |
| 128 | + <button class="btn btn-neutral btn-sm absolute bottom-40 left-1/2 z-10 -translate-x-1/2 shadow-lg" aria-controls="offered-files" aria-expanded={showAllFiles} onclick={() => showAllFiles = !showAllFiles}> |
| 129 | + {#if showAllFiles} |
| 130 | + <ChevronUpIcon class="h-4 w-4"/> |
| 131 | + Show less |
| 132 | + {:else} |
| 133 | + <ChevronDownIcon class="h-4 w-4"/> |
| 134 | + Show {$currentFileOffer.files.length - previewFileLimit} more file{$currentFileOffer.files.length - previewFileLimit === 1 ? "" : "s"} |
| 135 | + {/if} |
| 136 | + </button> |
| 137 | + {/if} |
| 138 | + {#if $currentFileOffer} |
| 139 | + <div class="flex shrink-0 items-center justify-between rounded-box bg-base-200 px-4 py-3 text-sm text-base-content/70"> |
| 140 | + <span>Total files: {$currentFileOffer.files.length}</span> |
| 141 | + <span>Total size: {formatFileSize($currentFileOffer.files.reduce((total, file) => total + file.size, 0))}</span> |
| 142 | + </div> |
125 | 143 | {/if} |
126 | | - <div class="flex flex-col gap-3"> |
| 144 | + <div class="flex shrink-0 flex-col gap-3"> |
127 | 145 | {#if $downloadFinished} |
128 | 146 | <a href="/donate" class="btn btn-primary w-full"> |
129 | 147 | <HeartIcon class="h-5 w-5"/> |
|
0 commit comments