Skip to content

Commit

Permalink
Fix wrong scroll element Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kadiryazici committed Mar 17, 2024
1 parent 516e807 commit a974f13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/components/AppScroller.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue'
import { computed, onMounted, provide, ref, watch } from 'vue'
import { type OverlayScrollbarsComponentRef, OverlayScrollbarsComponent as ScrollView } from 'overlayscrollbars-vue'
import type { PartialOptions as OverlayScrollbarsOptions } from 'overlayscrollbars'
import { computedEager } from '@vueuse/core'
Expand All @@ -10,6 +10,7 @@ import { batchFn } from '../utils/batch'
import { ColorPreference } from '../constants'
import { useTheme } from '../composables/useTheme'
import { useRoute } from '../composables/useRoute'
import { scrollElementInjectionKey } from '../composables/useScrollElement'
const route = useRoute()
const scrollView = ref<Option<OverlayScrollbarsComponentRef>>(null)
Expand All @@ -18,6 +19,8 @@ const focus = batchFn(() => {
scrollView.value?.getElement()?.focus()
})
provide(scrollElementInjectionKey, computed(() => scrollView.value?.osInstance()?.elements()?.viewport as HTMLElement))
useTauriEvent('window:hidden', focus)
onMounted(focus)
watch(route.currentPage, () => {
Expand Down
8 changes: 8 additions & 0 deletions src/composables/useScrollElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { inject } from 'vue'
import type { ComputedRef, InjectionKey } from 'vue'

export const scrollElementInjectionKey: InjectionKey<ComputedRef<HTMLElement>> = Symbol('scrollElement')

export function useScrollElement() {
return inject(scrollElementInjectionKey)!
}
15 changes: 8 additions & 7 deletions src/pages/SettingsPage.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import { computed, ref, watch } from 'vue'
import { disable as disableAutostart, enable as enableAutostart } from 'tauri-plugin-autostart-api'
import { computedEager, watchDebounced } from '@vueuse/core'
import { computedEager, useEventListener, watchDebounced } from '@vueuse/core'
import { invoke } from '@tauri-apps/api/tauri'
import { requestPermission } from '@tauri-apps/api/notification'
Expand All @@ -22,6 +22,7 @@ import Switch from '../components/Switch.vue'
import SettingItem from '../components/SettingItem.vue'
import { useI18n } from '../composables/useI18n'
import { Page, useRoute } from '../composables/useRoute'
import { useScrollElement } from '../composables/useScrollElement'
const route = useRoute()
const { t, currentLanguage } = useI18n()
Expand Down Expand Up @@ -165,16 +166,16 @@ const selectLanguageItems = computed(() => [
])
const scrollTop = ref(0)
function handleScroll(e: Event) {
const scrollElement = useScrollElement()
useEventListener(scrollElement, 'scroll', (e) => {
console.log(e)
scrollTop.value = (e.target as HTMLElement).scrollTop
}
})
</script>

<template>
<div
class="settings"
@scroll="handleScroll"
>
<div class="settings">
<div
class="settings-header"
:class="{ 'settings-header-with-border': scrollTop > 0 }"
Expand Down

0 comments on commit a974f13

Please sign in to comment.