Skip to content

Commit 66fe564

Browse files
committed
fix: message input in comment drawer on mobile
1 parent f757c6c commit 66fe564

File tree

3 files changed

+69
-47
lines changed

3 files changed

+69
-47
lines changed

platforms/pictique/src/lib/fragments/Drawer/Drawer.svelte

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,26 @@
99
interface IDrawerProps extends HTMLAttributes<HTMLDivElement> {
1010
drawer?: CupertinoPane;
1111
children?: Snippet;
12+
onClose?: () => void;
1213
}
1314
14-
let { drawer = $bindable(), children = undefined, ...restProps }: IDrawerProps = $props();
15+
let {
16+
drawer = $bindable(),
17+
children = undefined,
18+
onClose,
19+
...restProps
20+
}: IDrawerProps = $props();
1521
1622
let drawerElement: HTMLElement;
1723
1824
function dismiss() {
1925
if (drawer) drawer.destroy({ animate: true });
26+
onClose?.();
2027
}
2128
2229
function downSwipeHandler() {
2330
drawer?.destroy({ animate: true });
31+
onClose?.();
2432
}
2533
2634
const swipeActions = useSwipe(
@@ -46,29 +54,33 @@
4654
bottomClose: true,
4755
buttonDestroy: false,
4856
cssClass: '',
49-
initialBreak: 'middle',
57+
initialBreak: 'top',
58+
breaks: {
59+
top: { enabled: true, height: window.innerHeight * 0.9 },
60+
middle: { enabled: true, height: window.innerHeight * 0.5 }
61+
},
5062
events: {
51-
onBackdropTap: () => dismiss()
63+
onBackdropTap: () => dismiss(),
64+
onWillDismiss: () => onClose?.()
5265
}
5366
});
5467
});
5568
</script>
5669

5770
<div bind:this={drawerElement} {...restProps} {...swipeActions} class={cn(restProps.class)}>
58-
<div class="h-[100%] overflow-y-scroll">
59-
{@render children?.()}
60-
</div>
71+
{@render children?.()}
6172
</div>
6273

6374
<style>
6475
:global(.pane) {
6576
border-top-left-radius: 32px !important;
6677
border-top-right-radius: 32px !important;
6778
padding: 20px !important;
79+
overflow-y: scroll !important;
6880
scrollbar-width: none !important;
6981
-ms-overflow-style: none !important;
70-
::-webkit-scrollbar {
71-
display: none !important;
72-
}
82+
}
83+
:global(.pane)::-webkit-scrollbar {
84+
display: none !important;
7385
}
7486
</style>

platforms/pictique/src/routes/(protected)/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
/>
5050
{@render children()}
5151

52-
{#if route !== `/messages/${page.params.id}`}
52+
{#if !route.match(/^\/messages\/[^/]+$/)}
5353
<BottomNav class="btm-nav" profileSrc={profile?.avatarUrl ?? ''} />
5454
{/if}
5555
</main>

platforms/pictique/src/routes/(protected)/home/+page.svelte

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
let commentInput: HTMLInputElement | undefined = $state();
2929
let isCommentsLoading = $state(false);
3030
let commentsError = $state<string | null>(null);
31+
let isDrawerOpen = $state(false);
3132
3233
const sentinel = (node: HTMLElement) => {
3334
const observer = new IntersectionObserver(
@@ -203,6 +204,7 @@
203204
activePostId.set(post.id);
204205
if (window.matchMedia('(max-width: 768px)').matches) {
205206
showComments.value = true;
207+
isDrawerOpen = true;
206208
drawer?.present({ animate: true });
207209
} else {
208210
showComments.value = true;
@@ -215,12 +217,7 @@
215217
</li>
216218
{/each}
217219
{#if $isLoadingMore}
218-
<li class="my-4 flex flex-col items-center justify-center gap-2">
219-
<span class="text-center">Loading more posts...</span>
220-
<div
221-
class="h-6 w-6 animate-spin rounded-full border-2 border-gray-400 border-t-transparent"
222-
></div>
223-
</li>
220+
<li class="my-4 text-center">Loading more posts...</li>
224221
{/if}
225222
{#if !$hasMore && $posts.length > 0 && !$isLoadingMore}
226223
<li class="my-4 text-center text-gray-500">No more posts to load</li>
@@ -237,15 +234,15 @@
237234
<p class="text-center">Select a post to view comments</p>
238235
</div>
239236
{:else}
240-
<ul class="pb-4">
241-
<h3 class="text-black-600 mb-6 text-center">
242-
{$comments.length} Comments
243-
</h3>
244-
{#if isCommentsLoading}
245-
<li class="text-center text-gray-500">Loading comments...</li>
246-
{:else if commentsError}
247-
<li class="text-center text-red-500">{commentsError}</li>
248-
{:else}
237+
<h3 class="text-black-600 mb-6 text-center">
238+
{$comments.length} Comments
239+
</h3>
240+
{#if isCommentsLoading}
241+
<p class="text-center text-gray-500">Loading comments...</p>
242+
{:else if commentsError}
243+
<p class="text-center text-red-500">{commentsError}</p>
244+
{:else}
245+
<ul>
249246
{#each $comments as comment (comment.id)}
250247
<li class="mb-4">
251248
<Comment
@@ -266,28 +263,34 @@
266263
/>
267264
</li>
268265
{/each}
269-
{/if}
270-
<MessageInput
271-
class="sticky start-0 bottom-4 mt-4 w-full px-2"
272-
variant="comment"
273-
src={profile?.avatarUrl ?? '/images/user.png'}
274-
bind:value={commentValue}
275-
{handleSend}
276-
bind:input={commentInput}
277-
/>
278-
</ul>
266+
</ul>
267+
{/if}
268+
<MessageInput
269+
class="sticky start-0 bottom-4 mt-4 w-full px-2"
270+
variant="comment"
271+
src={profile?.avatarUrl ?? '/images/user.png'}
272+
bind:value={commentValue}
273+
{handleSend}
274+
bind:input={commentInput}
275+
/>
279276
{/if}
280277
{/snippet}
281278

282279
<!-- Mobile Comments Drawer -->
283-
<Drawer bind:drawer>
284-
<ul class="pb-4">
285-
<h3 class="text-black-600 mb-6 text-center">{$comments.length} Comments</h3>
286-
{#if isCommentsLoading}
287-
<li class="text-center text-gray-500">Loading comments...</li>
288-
{:else if commentsError}
289-
<li class="text-center text-red-500">{commentsError}</li>
290-
{:else}
280+
<Drawer
281+
bind:drawer
282+
onClose={() => {
283+
isDrawerOpen = false;
284+
showComments.value = false;
285+
}}
286+
>
287+
<h3 class="text-black-600 mb-6 text-center">{$comments.length} Comments</h3>
288+
{#if isCommentsLoading}
289+
<p class="text-center text-gray-500">Loading comments...</p>
290+
{:else if commentsError}
291+
<p class="text-center text-red-500">{commentsError}</p>
292+
{:else}
293+
<ul class="pb-32">
291294
{#each $comments as comment (comment.id)}
292295
<li class="mb-4">
293296
<Comment
@@ -308,15 +311,22 @@
308311
/>
309312
</li>
310313
{/each}
311-
{/if}
314+
</ul>
315+
{/if}
316+
</Drawer>
317+
318+
{#if showComments.value && isDrawerOpen}
319+
<div
320+
class="fixed right-0 bottom-0 left-0 z-50 border-t border-gray-200 bg-white px-5 py-4 md:hidden"
321+
>
312322
<MessageInput
313-
class="fixed start-0 bottom-4 mt-4 w-full px-5"
323+
class="w-full"
314324
variant="comment"
315325
src={profile?.avatarUrl ?? '/images/user.png'}
316326
bind:value={commentValue}
317327
{handleSend}
318328
bind:input={commentInput}
319329
/>
320-
</ul>
321-
</Drawer>
330+
</div>
331+
{/if}
322332
</MainPanel>

0 commit comments

Comments
 (0)