Open source personal finance application
chore(UseTouch): refactor
Ilya Komichev79b0f6c01b45
diff --git a/assets/js/isTouchDevice.js b/assets/js/isTouchDevice.jsdeleted file mode 100644index 7f3f4ad7..00000000--- a/assets/js/isTouchDevice.js+++ /dev/null@@ -1,4 +0,0 @@-export default function isTouchDevice() {- // eslint-disable-next-line no-undef- return !!(('ontouchstart' in window) || (window.DocumentTouch && document instanceof DocumentTouch))-}diff --git a/assets/stylus/variables/media.styl b/assets/stylus/variables/media.stylindex fc54e69c..d48c6049 100644--- a/assets/stylus/variables/media.styl+++ b/assets/stylus/variables/media.styl@@ -63,7 +63,7 @@ media-laptop($less = false)// hover// ------------------------------------media-hover()- .isNotTouchDevice &:hover+ .mouse &:hover{block}&:activediff --git a/components/stat/cats/PeriodCatsChart.vue b/components/stat/cats/PeriodCatsChart.vueindex bf82435e..0b65c25e 100644--- a/components/stat/cats/PeriodCatsChart.vue+++ b/components/stat/cats/PeriodCatsChart.vue@@ -47,6 +47,6 @@ export default {overflow-x autodisplay flex- .isNotTouchDevice &+ .mouse &scrollbar()</style>diff --git a/layouts/default.vue b/layouts/default.vueindex 2c0caa1c..31c4781d 100644--- a/layouts/default.vue+++ b/layouts/default.vue@@ -1,6 +1,6 @@<script setup lang="ts">+import { usePointer } from '@vueuse/core'import debounce from '~/utils/debounce'-import detectTouch from '~/assets/js/isTouchDevice'import useUIView from '~/components/layout/useUIView'const { $store } = useNuxtApp()@@ -29,10 +29,19 @@ onMounted(async () => {}})-/**- * Detect touch device- */-const isTouchDevice = ref(false)+const { pointerType } = usePointer()+const classes = computed(() => [+ {+ mouse: pointerType.value === 'mouse' || !pointerType.value,+ touch: pointerType.value === 'touch',+ },+ `+ overflow-hidden relative+ h-full min-w-base+ font-roboto text-gray-500 dark_text-gray-400 leading-none antialiased+ bg-skin-layout-main+ `,+])/*** Page dimensions@@ -44,22 +53,14 @@ function getPageDimensions() {$store.dispatch('ui/setAppDimensions', { width, height })}-const touchClassNames = computed(() => ({- isNotTouchDevice: !isTouchDevice.value,- isTouchDevice: isTouchDevice.value,-}))-onMounted(() => {- isTouchDevice.value = detectTouch()getPageDimensions()window.addEventListener('resize', debounce(getPageDimensions, 300))})</script><template lang="pug">-.overflow-hidden.relative.h-full.min-w-base.font-roboto.text-slate-500.dark_text-gray-400.leading-none.antialiased.bg-skin-layout-main(- :class="touchClassNames"-)+div(:class="classes")LayoutModalsPortalTarget(diff --git a/layouts/login.vue b/layouts/login.vueindex a33c57bf..95c68254 100644--- a/layouts/login.vue+++ b/layouts/login.vue@@ -1,21 +1,27 @@<script setup lang="ts">-import detectTouch from '~/assets/js/isTouchDevice'+import { usePointer } from '@vueuse/core'+const { $store } = useNuxtApp()-// Detect touch device-const isTouchDevice = ref(false)-onMounted(() => { isTouchDevice.value = detectTouch() })-const touchClassNames = computed(() => ({- isNotTouchDevice: !isTouchDevice.value,- isTouchDevice: isTouchDevice.value,-}))+const { pointerType } = usePointer()+const classes = computed(() => [+ {+ mouse: pointerType.value === 'mouse' || !pointerType.value,+ touch: pointerType.value === 'touch',+ },+ `+ overflow-hidden+ flex+ h-full min-w-base+ font-roboto text-gray-600 dark_text-gray-400 antialiased leading-none+ bg-neutral-100 dark_bg-dark3+ `,+])</script><template lang="pug">-.overflow-hidden.flex.h-full.min-w-base.font-roboto.text-gray-600.dark_text-gray-400.antialiased.leading-none.bg-neutral-100.dark_bg-dark3(- :class="touchClassNames"-)- transition(name="fadeInSlow" appear)+div(:class="classes")+ Transition(name="fadeInSlow" appear)NuxtNotifications(diff --git a/layouts/welcome.vue b/layouts/welcome.vueindex 046124e2..8d1f5deb 100644--- a/layouts/welcome.vue+++ b/layouts/welcome.vue@@ -1,6 +1,6 @@<script setup lang="ts">+import { usePointer } from '@vueuse/core'import debounce from '~/utils/debounce'-import detectTouch from '~/assets/js/isTouchDevice'import useUIView from '~/components/layout/useUIView'const { $store } = useNuxtApp()@@ -25,10 +25,20 @@ onMounted(async () => {}})-/**- * Detect touch device- */-const isTouchDevice = ref(false)+const { pointerType } = usePointer()+const classes = computed(() => [+ {+ mouse: pointerType.value === 'mouse' || !pointerType.value,+ touch: pointerType.value === 'touch',+ },+ `+ overflow-hidden relative+ flex+ h-full min-w-base+ font-roboto text-gray-500 dark_text-gray-400 leading-none antialiased+ bg-skin-layout-main+ `,+])/*** Page dimensions@@ -40,22 +50,14 @@ function getPageDimensions() {$store.dispatch('ui/setAppDimensions', { width, height })}-const touchClassNames = computed(() => ({- isNotTouchDevice: !isTouchDevice.value,- isTouchDevice: isTouchDevice.value,-}))-onMounted(() => {- isTouchDevice.value = detectTouch()getPageDimensions()window.addEventListener('resize', debounce(getPageDimensions, 300))})</script><template lang="pug">-.font-roboto.text-gray-500.leading-none.antialiased.overflow-hidden.relative.h-full.min-w-base.flex.bg-skin-layout-main(- :class="[touchClassNames, 'dark_text-gray-400']"-)+div(:class="classes")LayoutModalsPortalTarget(diff --git a/tailwind.config.js b/tailwind.config.jsindex ec122bff..d15acd0c 100644--- a/tailwind.config.js+++ b/tailwind.config.js@@ -75,7 +75,7 @@ module.exports = {plugins: [plugin(({ addVariant }) => {- addVariant('hocus', ['.isNotTouchDevice &:not(._active):hover', '&:not(._active):active'])+ addVariant('hocus', ['.mouse &:not(._active):hover', '&:not(._active):active'])}),],}