fixed double-GET & change editor focus on mobile
authorPhiTux <redacted>
Thu, 2 Oct 2025 15:11:11 +0000 (17:11 +0200)
committerPhiTux <redacted>
Thu, 2 Oct 2025 15:11:11 +0000 (17:11 +0200)
frontend/src/routes/(authed)/write/+page.svelte

index 9fd93e5c6425f98389cd4d74e45622bc007d0be3..6458773b9e790f2aadc4dc0e0fa571d02df12d93 100644 (file)
@@ -49,6 +49,7 @@
        let cancelDownload = new AbortController();
 
        let tinyMDE;
+       let isMobile = false;
        onMount(() => {
                // If we come from read mode, keep the last visible day as the active selected day
                if ($readingDate) {
                }
                $readingDate = null; // no reading-highlighting when in write mode
 
+               // Detect mobile (simple heuristic: viewport width OR user agent)
+               isMobile =
+                       typeof window !== 'undefined' &&
+                       (window.matchMedia('(max-width: 768px)').matches ||
+                               /Mobi|Android/i.test(navigator.userAgent));
+
                tinyMDE = new TinyMDE.Editor({ element: 'editor', content: '' });
                let commandBar = new TinyMDE.CommandBar({ element: 'toolbar', editor: tinyMDE });
                document.getElementsByClassName('TinyMDE')[0].classList.add('focus-ring');
 
                        savedLog = currentLog;
 
+                       // Update editor content
                        tinyMDE.setContent(currentLog);
-                       tinyMDE.setSelection({ row: 0, col: 0 });
+                       // Only auto-focus/select on non-mobile devices
+                       if (!isMobile) {
+                               try {
+                                       tinyMDE.setSelection({ row: 0, col: 0 });
+                                       // Ensure the underlying editable div gets focus
+                                       const editorEl = document.querySelector(
+                                               '#editor .TinyMDE textarea, #editor .TinyMDE [contenteditable="true"]'
+                                       );
+                                       if (editorEl) editorEl.focus();
+                               } catch {}
+                       }
 
                        logDateWritten = response.data.date_written;
 
        }
 
        // Re-trigger aLookBack when settings are loaded/changed
+       let initial_aLookBack = $state(false);
        $effect(() => {
-               if ($settings && $settings.useALookBack !== undefined) {
+               if (!initial_aLookBack && $settings && $settings.useALookBack) {
                        getALookBack();
+                       initial_aLookBack = true;
                }
        });
 
git clone https://git.99rst.org/PROJECT