enh: swipe to reply

This commit is contained in:
Timothy Jaeryang Baek committed 2026-03-29 19:09:13 -05:00
1 parent 6c2b2f2c3e
commit 012ce95f27
2 files changed
+135 -6

No files matched your search

@@ -65,6 +65,67 @@
let editedContent = null; let editedContent = null;
let showDeleteConfirmDialog = false; let showDeleteConfirmDialog = false;
// Swipe-to-reply state
let swipeStartX = 0;
let swipeStartY = 0;
let swipeOffsetX = 0;
let isSwiping = false;
let swipeLocked = false; // locked to horizontal once determined
let swipeMessageEl: HTMLElement | null = null;
const SWIPE_THRESHOLD = 60;
const SWIPE_MAX = 100;
const SWIPE_DEAD_ZONE = 10;
const handleTouchStart = (e: TouchEvent) => {
if (disabled || edit || !onReply) return;
const touch = e.touches[0];
swipeStartX = touch.clientX;
swipeStartY = touch.clientY;
swipeOffsetX = 0;
isSwiping = false;
swipeLocked = false;
};
const handleTouchMove = (e: TouchEvent) => {
if (disabled || edit || !onReply) return;
const touch = e.touches[0];
const deltaX = touch.clientX - swipeStartX;
const deltaY = touch.clientY - swipeStartY;
// Determine swipe direction from dead zone
if (!swipeLocked && (Math.abs(deltaX) > SWIPE_DEAD_ZONE || Math.abs(deltaY) > SWIPE_DEAD_ZONE)) {
if (Math.abs(deltaY) > Math.abs(deltaX)) {
// Vertical scroll — abort swipe tracking
isSwiping = false;
swipeLocked = true;
return;
}
// Horizontal swipe — lock in
swipeLocked = true;
isSwiping = true;
}
if (!isSwiping) return;
// Only allow right swipe
const clampedX = Math.max(0, deltaX);
// Dampen the motion beyond threshold for a rubber-band feel
swipeOffsetX = clampedX <= SWIPE_THRESHOLD
? clampedX
: SWIPE_THRESHOLD + (clampedX - SWIPE_THRESHOLD) * 0.3;
swipeOffsetX = Math.min(swipeOffsetX, SWIPE_MAX);
};
const handleTouchEnd = () => {
if (isSwiping && swipeOffsetX >= SWIPE_THRESHOLD && onReply) {
onReply(message);
}
swipeOffsetX = 0;
isSwiping = false;
swipeLocked = false;
};
const loadMessageData = async () => { const loadMessageData = async () => {
if (message && message?.data === true) { if (message && message?.data === true) {
const res = await getMessageData(localStorage.token, channel?.id, message.id); const res = await getMessageData(localStorage.token, channel?.id, message.id);
@@ -91,9 +152,27 @@
/> />
{#if message} {#if message}
<div
class="swipe-reply-wrapper relative"
on:touchstart={handleTouchStart}
on:touchmove={handleTouchMove}
on:touchend={handleTouchEnd}
>
<!-- Swipe reply indicator -->
{#if swipeOffsetX > 0}
<div
class="swipe-reply-indicator"
style="opacity: {Math.min(swipeOffsetX / SWIPE_THRESHOLD, 1)}; transform: scale({0.5 + Math.min(swipeOffsetX / SWIPE_THRESHOLD, 1) * 0.5});"
>
<div class="swipe-reply-icon" class:swipe-reply-icon--active={swipeOffsetX >= SWIPE_THRESHOLD}>
<ArrowUpLeftAlt className="size-5" />
</div>
</div>
{/if}
<div <div
id="message-{message.id}" id="message-{message.id}"
class="flex flex-col justify-between w-full max-w-full mx-auto group hover:bg-gray-300/5 dark:hover:bg-gray-700/5 transition relative {className class="flex flex-col justify-between w-full max-w-full mx-auto group hover:bg-gray-300/5 dark:hover:bg-gray-700/5 relative {className
? className ? className
: `px-5 ${ : `px-5 ${
replyToMessage ? 'border-l-4 border-blue-500 bg-blue-100/10 dark:bg-blue-100/5 pl-4' : '' replyToMessage ? 'border-l-4 border-blue-500 bg-blue-100/10 dark:bg-blue-100/5 pl-4' : ''
@@ -105,6 +184,7 @@
} ${message?.is_pinned ? 'bg-yellow-100/20 dark:bg-yellow-100/5' : ''}`} {showUserProfile } ${message?.is_pinned ? 'bg-yellow-100/20 dark:bg-yellow-100/5' : ''}`} {showUserProfile
? 'pt-1.5 pb-0.5' ? 'pt-1.5 pb-0.5'
: ''}" : ''}"
style="transform: translateX({swipeOffsetX}px); {swipeOffsetX > 0 ? '' : 'transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);'}"
> >
{#if !edit && !disabled} {#if !edit && !disabled}
<div <div
@@ -546,6 +626,7 @@
</div> </div>
</div> </div>
</div> </div>
</div>
{/if} {/if}
<style> <style>
@@ -561,4 +642,48 @@
background-color: transparent; background-color: transparent;
} }
} }
/* Swipe-to-reply styles */
.swipe-reply-wrapper {
touch-action: pan-y;
}
.swipe-reply-indicator {
position: absolute;
left: 8px;
top: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
z-index: 5;
pointer-events: none;
}
.swipe-reply-icon {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: 50%;
background-color: rgba(128, 128, 128, 0.15);
color: rgba(128, 128, 128, 0.8);
transition: background-color 0.15s, color 0.15s;
}
.swipe-reply-icon--active {
background-color: rgba(59, 130, 246, 0.2);
color: rgb(59, 130, 246);
}
:global(.dark) .swipe-reply-icon {
background-color: rgba(200, 200, 200, 0.1);
color: rgba(200, 200, 200, 0.6);
}
:global(.dark) .swipe-reply-icon--active {
background-color: rgba(96, 165, 250, 0.2);
color: rgb(96, 165, 250);
}
</style> </style>
+9 -5
View File
@@ -153,7 +153,9 @@
{/if} {/if}
</div> </div>
<div class="self-start flex flex-none items-center text-gray-600 dark:text-gray-400 gap-1"> <div
class="self-start flex flex-none items-center text-gray-600 dark:text-gray-400 gap-1 shrink-0"
>
{#if channel} {#if channel}
<Tooltip content={$i18n.t('Pinned Messages')}> <Tooltip content={$i18n.t('Pinned Messages')}>
<button <button
@@ -164,7 +166,7 @@
showChannelPinnedMessagesModal = true; showChannelPinnedMessagesModal = true;
}} }}
> >
<div class=" flex items-center gap-0.5 m-auto self-center"> <div class=" flex items-center gap-0.5 m-auto self-center shrink-0">
<Pin className=" size-4" strokeWidth="1.5" /> <Pin className=" size-4" strokeWidth="1.5" />
</div> </div>
</button> </button>
@@ -173,17 +175,17 @@
{#if channel?.user_count !== undefined} {#if channel?.user_count !== undefined}
<Tooltip content={$i18n.t('Users')}> <Tooltip content={$i18n.t('Users')}>
<button <button
class=" flex cursor-pointer py-1 px-1.5 border dark:border-gray-850 border-gray-50 rounded-xl text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-850 transition" class=" flex cursor-pointer shrink-0 py-1 px-1.5 border dark:border-gray-850 border-gray-50 rounded-xl text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-850 transition"
aria-label="User Count" aria-label="User Count"
type="button" type="button"
on:click={() => { on:click={() => {
showChannelInfoModal = true; showChannelInfoModal = true;
}} }}
> >
<div class=" flex items-center gap-0.5 m-auto self-center"> <div class=" flex items-center gap-0.5 m-auto self-center shrink-0">
<UserAlt className=" size-4" strokeWidth="1.5" /> <UserAlt className=" size-4" strokeWidth="1.5" />
<div class="text-sm"> <div class="text-sm shrink-0">
{channel.user_count} {channel.user_count}
</div> </div>
</div> </div>
@@ -193,6 +195,7 @@
{/if} {/if}
{#if $user !== undefined} {#if $user !== undefined}
<div>
<UserMenu <UserMenu
className="w-[240px]" className="w-[240px]"
role={$user?.role} role={$user?.role}
@@ -217,6 +220,7 @@
</div> </div>
</button> </button>
</UserMenu> </UserMenu>
</div>
{/if} {/if}
</div> </div>
</div> </div>