|
1 | 1 | <script lang="ts"> |
2 | 2 | import { page } from '$app/state'; |
3 | 3 | import { comments } from '$lib/dummyData'; |
4 | | - import { BottomNav, Header, Comment, MessageInput, SideBar, Modal } from '$lib/fragments'; |
5 | | - import InputFile from '$lib/fragments/InputFile/InputFile.svelte'; |
| 4 | + import { BottomNav, Header, Comment, MessageInput, SideBar } from '$lib/fragments'; |
| 5 | + import AddPostModal from '$lib/fragments/AddPostModal/AddPostModal.svelte'; |
6 | 6 | import UserRequest from '$lib/fragments/UserRequest/UserRequest.svelte'; |
7 | 7 | import { showComments } from '$lib/store/store.svelte'; |
8 | 8 | import type { CommentType } from '$lib/types'; |
9 | | - import { Button, Label, Textarea } from '$lib/ui'; |
10 | | - import InputRadio from '$lib/ui/InputRadio/InputRadio.svelte'; |
11 | 9 | import { ArrowLeft02Icon } from '@hugeicons/core-free-icons'; |
12 | 10 | import { HugeiconsIcon } from '@hugeicons/svelte'; |
13 | 11 | import type { CupertinoPane } from 'cupertino-pane'; |
|
21 | 19 | let activeReplyToId: string | null = $state(null); |
22 | 20 | let paneModal: CupertinoPane | undefined = $state(); |
23 | 21 | let files: FileList | undefined = $state(); |
24 | | - let imagePreviews: string[] = $state([]); |
25 | | - let isAddCaption: boolean = $state(false); |
26 | 22 | let caption: string = $state(''); |
27 | 23 | let idFromParams = $state(); |
28 | 24 | let postVisibility = $state(''); |
29 | 25 |
|
30 | | - let postVisibilityOptions = ['Only followers', 'Close friends', 'Anyone']; |
31 | | -
|
32 | 26 | const handleSend = async () => { |
33 | 27 | const newComment = { |
34 | 28 | userImgSrc: 'https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250', |
|
82 | 76 | heading = 'Profile'; |
83 | 77 | } |
84 | 78 | }); |
85 | | -
|
86 | | - $effect(() => { |
87 | | - if (files) { |
88 | | - const readers = Array.from(files).map((file) => { |
89 | | - return new Promise<string>((resolve) => { |
90 | | - const reader = new FileReader(); |
91 | | - reader.onload = (e) => resolve(e.target?.result as string); |
92 | | - reader.readAsDataURL(file); |
93 | | - }); |
94 | | - }); |
95 | | -
|
96 | | - Promise.all(readers).then((previews) => { |
97 | | - imagePreviews = previews; |
98 | | - }); |
99 | | - } else { |
100 | | - imagePreviews = []; |
101 | | - } |
102 | | - }); |
103 | 79 | </script> |
104 | 80 |
|
105 | 81 | <main |
|
189 | 165 | {/if} |
190 | 166 | </main> |
191 | 167 |
|
192 | | -<Modal |
193 | | - bind:paneModal |
194 | | - initialBreak="middle" |
195 | | - handleDismiss={() => { |
196 | | - (files = undefined), (isAddCaption = false); |
197 | | - }} |
198 | | -> |
199 | | - <h1 class="mb-6 font-semibold text-black">Upload a Photo</h1> |
200 | | - {#if !isAddCaption} |
201 | | - {#if !files} |
202 | | - <InputFile class="mb-4 h-[40vh]" bind:files accept="images/*" multiple={true} /> |
203 | | - {:else} |
204 | | - <div class="mb-4 grid grid-cols-3 gap-2"> |
205 | | - {#each imagePreviews as src} |
206 | | - <div class="aspect-[4/5] overflow-hidden rounded-lg border"> |
207 | | - <!-- svelte-ignore a11y_img_redundant_alt --> |
208 | | - <img {src} alt="Selected image" class="h-full w-full object-cover" /> |
209 | | - </div> |
210 | | - {/each} |
211 | | - </div> |
212 | | - {/if} |
213 | | - {:else if isAddCaption} |
214 | | - <Label>Add a Caption</Label> |
215 | | - <Textarea class="mb-4" bind:value={caption} placeholder="enter caption" /> |
216 | | - <div class="mb-4 flex items-center gap-2"> |
217 | | - {#each imagePreviews as src} |
218 | | - <div class="h-[100px] w-[80px] overflow-hidden rounded-lg border"> |
219 | | - <!-- svelte-ignore a11y_img_redundant_alt --> |
220 | | - <img {src} alt="Selected image" class="h-[100px] w-[80px] object-cover" /> |
221 | | - </div> |
222 | | - {/each} |
223 | | - </div> |
224 | | - <h3 class="text-black-800 mt-20 mb-2">Who can see the post?</h3> |
225 | | - {#each postVisibilityOptions as option, i} |
226 | | - <div class="mb-2 flex w-[50%] items-center justify-between"> |
227 | | - <Label for={option + i}>{option}</Label> |
228 | | - <InputRadio |
229 | | - name="post-visibility" |
230 | | - id={option + i} |
231 | | - value={option} |
232 | | - bind:selected={postVisibility} |
233 | | - /> |
234 | | - </div> |
235 | | - {/each} |
236 | | - {/if} |
237 | | - {#if files} |
238 | | - <div class="grid grid-cols-2 gap-2"> |
239 | | - <Button |
240 | | - variant="secondary" |
241 | | - size="sm" |
242 | | - callback={async () => { |
243 | | - files = undefined; |
244 | | - isAddCaption = false; |
245 | | - paneModal?.destroy({ animate: true }); |
246 | | - }}>Cancel</Button |
247 | | - > |
248 | | - <Button |
249 | | - variant="secondary" |
250 | | - size="sm" |
251 | | - callback={async () => { |
252 | | - isAddCaption = true; |
253 | | - }}>Next</Button |
254 | | - > |
255 | | - </div> |
256 | | - {/if} |
257 | | -</Modal> |
| 168 | +<AddPostModal bind:files bind:postVisibility bind:caption bind:paneModal /> |
0 commit comments