Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Drag-to-dismiss for the bottom-sheet upload modal — pulling the sheet down past 120 px (or 25 % of viewport, whichever is smaller) closes it; releasing before the threshold snaps back via a 200 ms cubic-bezier transition; only the modal-header area carries the touch handlers (touchstart / touchmove / touchend / touchcancel) so dragging inside the scrollable modal-body still scrolls content normally without fighting the gesture; offset is exposed as a bottomSheetDragStyle computed bound to the panel's :style — translateY follows the finger 1:1 with transition: none during the drag, then transitions are re-enabled on release so the snap-back animates smoothly; on dismissal, the sheet animates fully off-screen (innerHeight px) before calling closeUploadView so the close reads as the natural continuation of the gesture rather than a hard jump; only engages on mobile (window.innerWidth ≤ 640) mirroring the bottom-sheet CSS variant's media query gate, so desktop has zero touch-handler overhead; .passive event modifiers used throughout so the handlers never block scroll-jank checks; on touchcancel (user dragged into a system gesture or switched apps) the offset is reset cleanly via the same end handler

Murtaza Nasir21d837387312
diff --git a/static/js/modules/composables/ui.js b/static/js/modules/composables/ui.js
index 1523dab0..df05bd01 100644
--- a/static/js/modules/composables/ui.js
+++ b/static/js/modules/composables/ui.js
@@ -198,6 +198,73 @@ export function useUI(state, utils, processedTranscription) {
showUploadModal.value = false;
};
+ // Drag-to-dismiss for the .modal-panel--bottom-sheet variant on
+ // mobile. Attached to the modal-header area only so dragging
+ // inside the scrollable modal-body doesn't fight the gesture.
+ // Pulling the sheet down past the threshold (120 px or 25 % of
+ // viewport, whichever is smaller) closes the modal; releasing
+ // before the threshold snaps back via the CSS transition. The
+ // offset is exposed as bottomSheetDragStyle which the template
+ // binds to the modal-panel's :style.
+ const bottomSheetDragOffset = ref(0);
+ const bottomSheetDragStartY = ref(null);
+ const bottomSheetDragStyle = computed(() => {
+ if (bottomSheetDragOffset.value <= 0) {
+ return { transition: 'transform 200ms cubic-bezier(0.16, 1, 0.3, 1)' };
+ }
+ // No transition while the finger is actively dragging so it
+ // tracks 1:1; transition is restored on release.
+ return {
+ transform: `translateY(${bottomSheetDragOffset.value}px)`,
+ transition: 'none'
+ };
+ });
+
+ const onSheetDragStart = (e) => {
+ // Only engage on mobile (the bottom-sheet variant is
+ // viewport-gated to ≤ 640 px in primitives.css; mirroring
+ // the gate here avoids touch handler overhead on desktop).
+ if (window.innerWidth > 640) return;
+ const t = e.touches && e.touches[0];
+ if (!t) return;
+ bottomSheetDragStartY.value = t.clientY;
+ bottomSheetDragOffset.value = 0;
+ };
+
+ const onSheetDragMove = (e) => {
+ if (bottomSheetDragStartY.value == null) return;
+ const t = e.touches && e.touches[0];
+ if (!t) return;
+ const delta = t.clientY - bottomSheetDragStartY.value;
+ // Only follow downward drags; upward gestures fall through
+ // so the user can scroll content in the body normally if
+ // they drift onto the header by accident.
+ if (delta > 0) {
+ bottomSheetDragOffset.value = delta;
+ } else {
+ bottomSheetDragOffset.value = 0;
+ }
+ };
+
+ const onSheetDragEnd = () => {
+ if (bottomSheetDragStartY.value == null) return;
+ const threshold = Math.min(120, window.innerHeight * 0.25);
+ if (bottomSheetDragOffset.value > threshold) {
+ // Snap fully off-screen before dismissing so the close
+ // reads as the natural continuation of the gesture
+ // rather than a hard jump.
+ bottomSheetDragOffset.value = window.innerHeight;
+ setTimeout(() => {
+ closeUploadView();
+ bottomSheetDragOffset.value = 0;
+ bottomSheetDragStartY.value = null;
+ }, 180);
+ return;
+ }
+ bottomSheetDragOffset.value = 0;
+ bottomSheetDragStartY.value = null;
+ };
+
// Switch to recording view
const switchToRecordingView = () => {
currentView.value = 'recording';
@@ -2054,6 +2121,10 @@ export function useUI(state, utils, processedTranscription) {
switchToUploadView,
switchToDetailView,
closeUploadView,
+ bottomSheetDragStyle,
+ onSheetDragStart,
+ onSheetDragMove,
+ onSheetDragEnd,
switchToRecordingView,
setGlobalError,
formatFileSize,
diff --git a/templates/components/upload-view.html b/templates/components/upload-view.html
index 5b830faa..470b8059 100644
--- a/templates/components/upload-view.html
+++ b/templates/components/upload-view.html
@@ -9,8 +9,18 @@
@keydown.esc="closeUploadView"
tabindex="-1"
class="modal-overlay">
- <div class="modal-panel modal-panel--lg modal-panel--bottom-sheet" style="max-height: 92vh;">
- <div class="modal-header">
+ <div class="modal-panel modal-panel--lg modal-panel--bottom-sheet"
+ :style="[{ maxHeight: '92vh' }, bottomSheetDragStyle]">
+ <!-- Drag-to-dismiss handlers attached on the header area only
+ (and on the panel's ::before drag handle, which lives inside
+ this header's expanded top padding) — keeps the scrollable
+ modal-body free for normal touch-scrolling without
+ swallowing the gesture. -->
+ <div class="modal-header"
+ @touchstart.passive="onSheetDragStart"
+ @touchmove.passive="onSheetDragMove"
+ @touchend.passive="onSheetDragEnd"
+ @touchcancel.passive="onSheetDragEnd">
<i class="fas fa-microphone text-[var(--text-accent)]"></i>
<h3 class="modal-title" v-text="t('upload.title')"></h3>
<button @click="closeUploadView" class="modal-close" :title="t('buttons.close')">