) =>
+ $mobile ? { duration: 0, css: () => '' } : slide(node, params);
let scrollTop = 0;
@@ -554,32 +558,6 @@
draggedOver = false; // Reset draggedOver status after drop
};
- let touchstart;
- let touchend;
-
- function checkDirection() {
- const screenWidth = window.innerWidth;
- const swipeDistance = Math.abs(touchend.screenX - touchstart.screenX);
- if (touchstart.clientX < 40 && swipeDistance >= screenWidth / 8) {
- if (touchend.screenX < touchstart.screenX) {
- showSidebar.set(false);
- }
- if (touchend.screenX > touchstart.screenX) {
- showSidebar.set(true);
- }
- }
- }
-
- const onTouchStart = (e) => {
- touchstart = e.changedTouches[0];
- console.log(touchstart.clientX);
- };
-
- const onTouchEnd = (e) => {
- touchend = e.changedTouches[0];
- checkDirection();
- };
-
const onKeyDown = (e) => {
if (e.key === 'Shift') {
shiftKey = true;
@@ -599,6 +577,21 @@
selectedChatId = null;
};
+ const focusChatInputSoon = () => {
+ setTimeout(() => {
+ document.getElementById('chat-input')?.focus({ preventScroll: true });
+ }, MOBILE_SIDEBAR_SETTLE_MS);
+ };
+
+ const closeMobileSidebar = (focusChatInput = false) => {
+ if ($mobile) {
+ showSidebar.set(false);
+ if (focusChatInput) {
+ focusChatInputSoon();
+ }
+ }
+ };
+
const MIN_WIDTH = 220;
const MAX_WIDTH = 480;
@@ -701,9 +694,6 @@
window.addEventListener('keydown', onKeyDown);
window.addEventListener('keyup', onKeyUp);
- window.addEventListener('touchstart', onTouchStart);
- window.addEventListener('touchend', onTouchEnd);
-
window.addEventListener('focus', onFocus);
window.addEventListener('blur', onBlur);
@@ -739,9 +729,6 @@
window.removeEventListener('keydown', onKeyDown);
window.removeEventListener('keyup', onKeyUp);
- window.removeEventListener('touchstart', onTouchStart);
- window.removeEventListener('touchend', onTouchEnd);
-
window.removeEventListener('focus', onFocus);
window.removeEventListener('blur', onBlur);
@@ -811,27 +798,20 @@
const newChatHandler = async () => {
selectedChatId = null;
selectedFolder.set(null);
+ closeMobileSidebar(true);
if ($user?.role !== 'admin' && $user?.permissions?.chat?.temporary_enforced) {
await temporaryChatEnabled.set(true);
} else {
await temporaryChatEnabled.set(false);
}
-
- setTimeout(() => {
- if ($mobile) {
- showSidebar.set(false);
- }
- }, 0);
};
const itemClickHandler = async () => {
selectedChatId = null;
chatId.set('');
- if ($mobile) {
- showSidebar.set(false);
- }
+ closeMobileSidebar();
await tick();
};
@@ -887,37 +867,6 @@
}}
/>
-
-
-{#if $showSidebar}
- {
- showSidebar.set(!$showSidebar);
- }}
- />
-{/if}
-
- {
- if ($mobile) {
- showSidebar.set(false);
- }
- }}
-/>
-
-