Browse Source

refactor(nc-gui): only enable swipe controls for mobile layout

pull/3669/head
braks 2 years ago committed by Raju Udava
parent
commit
6652c39bf5
  1. 47
      packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue
  2. 3
      packages/nc-gui/pages/index/index/index.vue

47
packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk' import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk'
import { SwipeDirection } from '@vueuse/core' import { SwipeDirection, breakpointsTailwind } from '@vueuse/core'
import { import {
DropZoneRef, DropZoneRef,
computed, computed,
@ -9,7 +9,7 @@ import {
onMounted, onMounted,
provide, provide,
ref, ref,
useEventListener, useBreakpoints,
usePointerSwipe, usePointerSwipe,
useSharedFormStoreOrThrow, useSharedFormStoreOrThrow,
useStepper, useStepper,
@ -20,6 +20,8 @@ enum TransitionDirection {
Right = 'right', Right = 'right',
} }
const { md } = useBreakpoints(breakpointsTailwind)
const { v$, formState, formColumns, submitForm, submitted, secondsRemain, sharedFormView } = useSharedFormStoreOrThrow() const { v$, formState, formColumns, submitForm, submitted, secondsRemain, sharedFormView } = useSharedFormStoreOrThrow()
const isTransitioning = ref(false) const isTransitioning = ref(false)
@ -28,18 +30,6 @@ const transitionName = ref<TransitionDirection>(TransitionDirection.Left)
const el = ref<HTMLDivElement>() const el = ref<HTMLDivElement>()
const { direction } = usePointerSwipe(el, {
onSwipe: () => {
if (isTransitioning.value) return
if (direction.value === SwipeDirection.LEFT) {
goNext()
} else if (direction.value === SwipeDirection.RIGHT) {
goPrevious()
}
},
})
provide(DropZoneRef, el) provide(DropZoneRef, el)
const steps = computed(() => { const steps = computed(() => {
@ -129,25 +119,26 @@ function focusInput() {
} }
} }
useEventListener('wheel', (event) => { onKeyStroke(['ArrowLeft', 'ArrowDown'], goPrevious)
if (Math.abs(event.deltaX) < Math.abs(event.deltaY)) { onKeyStroke(['ArrowRight', 'ArrowUp', 'Enter', 'Space'], goNext)
// Scrolling more vertically than horizontally
return onMounted(() => {
} focusInput()
if (!md.value) {
const { direction } = usePointerSwipe(el, {
onSwipe: () => {
if (isTransitioning.value) return if (isTransitioning.value) return
if (event.deltaX < -15) { if (direction.value === SwipeDirection.LEFT) {
goPrevious()
} else if (event.deltaX > 15) {
goNext() goNext()
} else if (direction.value === SwipeDirection.RIGHT) {
goPrevious()
}
},
})
} }
}) })
onKeyStroke(['ArrowLeft', 'ArrowDown'], goPrevious)
onKeyStroke(['ArrowRight', 'ArrowUp', 'Enter', 'Space'], goNext)
onMounted(focusInput)
</script> </script>
<template> <template>
@ -248,7 +239,7 @@ onMounted(focusInput)
</a-tooltip> </a-tooltip>
<!-- todo: i18n --> <!-- todo: i18n -->
<div class="text-sm text-gray-500 flex items-center gap-1"> <div class="hidden md:flex text-sm text-gray-500 items-center gap-1">
Press Enter <MaterialSymbolsKeyboardReturn class="mt-1" /> Press Enter <MaterialSymbolsKeyboardReturn class="mt-1" />
</div> </div>
</div> </div>

3
packages/nc-gui/pages/index/index/index.vue

@ -204,7 +204,8 @@ onBeforeMount(loadProjects)
<a-skeleton /> <a-skeleton />
</div> </div>
<a-table v-else <a-table
v-else
:custom-row="customRow" :custom-row="customRow"
:data-source="filteredProjects" :data-source="filteredProjects"
:pagination="{ position: ['bottomCenter'] }" :pagination="{ position: ['bottomCenter'] }"

Loading…
Cancel
Save