This commit is contained in:
Timothy J. Baek 2024-07-05 21:27:59 -07:00
parent 8381346378
commit c3c15cbb7e

View File

@ -1,9 +1,10 @@
<script lang="ts"> <script lang="ts">
import { getContext, afterUpdate } from 'svelte'; import { getContext, tick } from 'svelte';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import { models, settings, user } from '$lib/stores'; import { models, settings, user } from '$lib/stores';
import { updateUserSettings } from '$lib/apis/users';
import { getModels as _getModels } from '$lib/apis'; import { getModels as _getModels } from '$lib/apis';
import { goto } from '$app/navigation';
import Modal from '../common/Modal.svelte'; import Modal from '../common/Modal.svelte';
import Account from './Settings/Account.svelte'; import Account from './Settings/Account.svelte';
@ -14,8 +15,6 @@
import Chats from './Settings/Chats.svelte'; import Chats from './Settings/Chats.svelte';
import User from '../icons/User.svelte'; import User from '../icons/User.svelte';
import Personalization from './Settings/Personalization.svelte'; import Personalization from './Settings/Personalization.svelte';
import { updateUserSettings } from '$lib/apis/users';
import { goto } from '$app/navigation';
import Valves from './Settings/Valves.svelte'; import Valves from './Settings/Valves.svelte';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -36,7 +35,7 @@
let selectedTab = 'general'; let selectedTab = 'general';
// Function to handle sideways scrolling // Function to handle sideways scrolling
const handleSidewaysScroll = (event) => { const scrollHandler = (event) => {
const settingsTabsContainer = document.getElementById('settings-tabs-container'); const settingsTabsContainer = document.getElementById('settings-tabs-container');
if (settingsTabsContainer) { if (settingsTabsContainer) {
event.preventDefault(); // Prevent default vertical scrolling event.preventDefault(); // Prevent default vertical scrolling
@ -44,22 +43,27 @@
} }
}; };
// Use afterUpdate to add the event listener after the modal is confirmed to be visible const addScrollListener = async () => {
// and remove it when the modal is closed await tick();
afterUpdate(() => {
if (show) {
const settingsTabsContainer = document.getElementById('settings-tabs-container'); const settingsTabsContainer = document.getElementById('settings-tabs-container');
if (settingsTabsContainer) { if (settingsTabsContainer) {
settingsTabsContainer.addEventListener('wheel', handleSidewaysScroll); settingsTabsContainer.addEventListener('wheel', scrollHandler);
} }
} else { };
const settingsTabsContainer = document.getElementById('settings-tabs-container');
if (settingsTabsContainer) {
settingsTabsContainer.removeEventListener('wheel', handleSidewaysScroll);
}
}
});
const removeScrollListener = async () => {
await tick();
const settingsTabsContainer = document.getElementById('settings-tabs-container');
if (settingsTabsContainer) {
settingsTabsContainer.removeEventListener('wheel', scrollHandler);
}
};
$: if (show) {
addScrollListener();
} else {
removeScrollListener();
}
</script> </script>
<Modal bind:show> <Modal bind:show>