|
65 | 65 | let editedContent = null; |
66 | 66 | let showDeleteConfirmDialog = false; |
67 | 67 |
|
| 68 | + // Swipe-to-reply state |
| 69 | + let swipeStartX = 0; |
| 70 | + let swipeStartY = 0; |
| 71 | + let swipeOffsetX = 0; |
| 72 | + let isSwiping = false; |
| 73 | + let swipeLocked = false; // locked to horizontal once determined |
| 74 | + let swipeMessageEl: HTMLElement | null = null; |
| 75 | +
|
| 76 | + const SWIPE_THRESHOLD = 60; |
| 77 | + const SWIPE_MAX = 100; |
| 78 | + const SWIPE_DEAD_ZONE = 10; |
| 79 | +
|
| 80 | + const handleTouchStart = (e: TouchEvent) => { |
| 81 | + if (disabled || edit || !onReply) return; |
| 82 | + const touch = e.touches[0]; |
| 83 | + swipeStartX = touch.clientX; |
| 84 | + swipeStartY = touch.clientY; |
| 85 | + swipeOffsetX = 0; |
| 86 | + isSwiping = false; |
| 87 | + swipeLocked = false; |
| 88 | + }; |
| 89 | +
|
| 90 | + const handleTouchMove = (e: TouchEvent) => { |
| 91 | + if (disabled || edit || !onReply) return; |
| 92 | + const touch = e.touches[0]; |
| 93 | + const deltaX = touch.clientX - swipeStartX; |
| 94 | + const deltaY = touch.clientY - swipeStartY; |
| 95 | +
|
| 96 | + // Determine swipe direction from dead zone |
| 97 | + if (!swipeLocked && (Math.abs(deltaX) > SWIPE_DEAD_ZONE || Math.abs(deltaY) > SWIPE_DEAD_ZONE)) { |
| 98 | + if (Math.abs(deltaY) > Math.abs(deltaX)) { |
| 99 | + // Vertical scroll — abort swipe tracking |
| 100 | + isSwiping = false; |
| 101 | + swipeLocked = true; |
| 102 | + return; |
| 103 | + } |
| 104 | + // Horizontal swipe — lock in |
| 105 | + swipeLocked = true; |
| 106 | + isSwiping = true; |
| 107 | + } |
| 108 | +
|
| 109 | + if (!isSwiping) return; |
| 110 | +
|
| 111 | + // Only allow right swipe |
| 112 | + const clampedX = Math.max(0, deltaX); |
| 113 | + // Dampen the motion beyond threshold for a rubber-band feel |
| 114 | + swipeOffsetX = clampedX <= SWIPE_THRESHOLD |
| 115 | + ? clampedX |
| 116 | + : SWIPE_THRESHOLD + (clampedX - SWIPE_THRESHOLD) * 0.3; |
| 117 | + swipeOffsetX = Math.min(swipeOffsetX, SWIPE_MAX); |
| 118 | + }; |
| 119 | +
|
| 120 | + const handleTouchEnd = () => { |
| 121 | + if (isSwiping && swipeOffsetX >= SWIPE_THRESHOLD && onReply) { |
| 122 | + onReply(message); |
| 123 | + } |
| 124 | + swipeOffsetX = 0; |
| 125 | + isSwiping = false; |
| 126 | + swipeLocked = false; |
| 127 | + }; |
| 128 | +
|
68 | 129 | const loadMessageData = async () => { |
69 | 130 | if (message && message?.data === true) { |
70 | 131 | const res = await getMessageData(localStorage.token, channel?.id, message.id); |
|
92 | 153 |
|
93 | 154 | {#if message} |
94 | 155 | <div |
95 | | - id="message-{message.id}" |
96 | | - 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 |
97 | | - ? className |
98 | | - : `px-5 ${ |
99 | | - replyToMessage ? 'border-l-4 border-blue-500 bg-blue-100/10 dark:bg-blue-100/5 pl-4' : '' |
100 | | - } ${ |
101 | | - (message?.reply_to_message?.meta?.model_id ?? message?.reply_to_message?.user_id) === |
102 | | - $user?.id |
103 | | - ? 'border-l-4 border-orange-500 bg-orange-100/10 dark:bg-orange-100/5 pl-4' |
104 | | - : '' |
105 | | - } ${message?.is_pinned ? 'bg-yellow-100/20 dark:bg-yellow-100/5' : ''}`} {showUserProfile |
106 | | - ? 'pt-1.5 pb-0.5' |
107 | | - : ''}" |
| 156 | + class="swipe-reply-wrapper relative" |
| 157 | + on:touchstart={handleTouchStart} |
| 158 | + on:touchmove={handleTouchMove} |
| 159 | + on:touchend={handleTouchEnd} |
108 | 160 | > |
| 161 | + <!-- Swipe reply indicator --> |
| 162 | + {#if swipeOffsetX > 0} |
| 163 | + <div |
| 164 | + class="swipe-reply-indicator" |
| 165 | + style="opacity: {Math.min(swipeOffsetX / SWIPE_THRESHOLD, 1)}; transform: scale({0.5 + Math.min(swipeOffsetX / SWIPE_THRESHOLD, 1) * 0.5});" |
| 166 | + > |
| 167 | + <div class="swipe-reply-icon" class:swipe-reply-icon--active={swipeOffsetX >= SWIPE_THRESHOLD}> |
| 168 | + <ArrowUpLeftAlt className="size-5" /> |
| 169 | + </div> |
| 170 | + </div> |
| 171 | + {/if} |
| 172 | + |
| 173 | + <div |
| 174 | + id="message-{message.id}" |
| 175 | + 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 |
| 176 | + ? className |
| 177 | + : `px-5 ${ |
| 178 | + replyToMessage ? 'border-l-4 border-blue-500 bg-blue-100/10 dark:bg-blue-100/5 pl-4' : '' |
| 179 | + } ${ |
| 180 | + (message?.reply_to_message?.meta?.model_id ?? message?.reply_to_message?.user_id) === |
| 181 | + $user?.id |
| 182 | + ? 'border-l-4 border-orange-500 bg-orange-100/10 dark:bg-orange-100/5 pl-4' |
| 183 | + : '' |
| 184 | + } ${message?.is_pinned ? 'bg-yellow-100/20 dark:bg-yellow-100/5' : ''}`} {showUserProfile |
| 185 | + ? 'pt-1.5 pb-0.5' |
| 186 | + : ''}" |
| 187 | + style="transform: translateX({swipeOffsetX}px); {swipeOffsetX > 0 ? '' : 'transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);'}" |
| 188 | + > |
109 | 189 | {#if !edit && !disabled} |
110 | 190 | <div |
111 | 191 | class=" absolute {showButtons ? '' : 'invisible group-hover:visible'} right-1 -top-2 z-10" |
|
545 | 625 | {/if} |
546 | 626 | </div> |
547 | 627 | </div> |
| 628 | + </div> |
548 | 629 | </div> |
549 | 630 | {/if} |
550 | 631 |
|
|
561 | 642 | background-color: transparent; |
562 | 643 | } |
563 | 644 | } |
| 645 | +
|
| 646 | + /* Swipe-to-reply styles */ |
| 647 | + .swipe-reply-wrapper { |
| 648 | + touch-action: pan-y; |
| 649 | + } |
| 650 | +
|
| 651 | + .swipe-reply-indicator { |
| 652 | + position: absolute; |
| 653 | + left: 8px; |
| 654 | + top: 0; |
| 655 | + bottom: 0; |
| 656 | + display: flex; |
| 657 | + align-items: center; |
| 658 | + justify-content: center; |
| 659 | + z-index: 5; |
| 660 | + pointer-events: none; |
| 661 | + } |
| 662 | +
|
| 663 | + .swipe-reply-icon { |
| 664 | + display: flex; |
| 665 | + align-items: center; |
| 666 | + justify-content: center; |
| 667 | + width: 32px; |
| 668 | + height: 32px; |
| 669 | + border-radius: 50%; |
| 670 | + background-color: rgba(128, 128, 128, 0.15); |
| 671 | + color: rgba(128, 128, 128, 0.8); |
| 672 | + transition: background-color 0.15s, color 0.15s; |
| 673 | + } |
| 674 | +
|
| 675 | + .swipe-reply-icon--active { |
| 676 | + background-color: rgba(59, 130, 246, 0.2); |
| 677 | + color: rgb(59, 130, 246); |
| 678 | + } |
| 679 | +
|
| 680 | + :global(.dark) .swipe-reply-icon { |
| 681 | + background-color: rgba(200, 200, 200, 0.1); |
| 682 | + color: rgba(200, 200, 200, 0.6); |
| 683 | + } |
| 684 | +
|
| 685 | + :global(.dark) .swipe-reply-icon--active { |
| 686 | + background-color: rgba(96, 165, 250, 0.2); |
| 687 | + color: rgb(96, 165, 250); |
| 688 | + } |
564 | 689 | </style> |
0 commit comments