From 807d5aab2011dc5b9b01bbe8971e2b37cf2b5d63 Mon Sep 17 00:00:00 2001 From: "@dev-opsss" Date: Tue, 8 Apr 2025 23:47:40 -0500 Subject: [PATCH] feat: Language option undetectable --- src/components/Queue/QueueCommands.tsx | 113 +++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 5 deletions(-) diff --git a/src/components/Queue/QueueCommands.tsx b/src/components/Queue/QueueCommands.tsx index 1f8d471..a0eaa35 100644 --- a/src/components/Queue/QueueCommands.tsx +++ b/src/components/Queue/QueueCommands.tsx @@ -1,4 +1,5 @@ import React, { useState, useEffect, useRef } from "react" +import { createRoot } from "react-dom/client" import { useToast } from "../../contexts/toast" import { LanguageSelector } from "../shared/LanguageSelector" @@ -164,7 +165,7 @@ const QueueCommands: React.FC = ({ strokeLinejoin="round" className="w-3.5 h-3.5" > - + @@ -379,10 +380,112 @@ const QueueCommands: React.FC = ({ {/* Separator and Log Out */}
- + {/* Simplified Language Selector */} +
+
{ + // Create a hidden instance of LanguageSelector to extract languages + const tempDiv = document.createElement('div'); + tempDiv.style.position = 'absolute'; + tempDiv.style.left = '-9999px'; + document.body.appendChild(tempDiv); + + // Create a root and render the LanguageSelector temporarily + const root = createRoot(tempDiv); + root.render( + {}} + /> + ); + + // Use setTimeout to ensure the component has rendered + setTimeout(() => { + // Extract options from the rendered select element + const selectElement = tempDiv.querySelector('select'); + if (selectElement) { + const options = Array.from(selectElement.options); + const values = options.map(opt => opt.value); + + // Find current language index + const currentIndex = values.indexOf(currentLanguage); + const nextIndex = (currentIndex + 1) % values.length; + + // Update language + setLanguage(values[nextIndex]); + window.electronAPI.updateConfig({ language: values[nextIndex] }); + } + + // Clean up + root.unmount(); + document.body.removeChild(tempDiv); + }, 0); + }} + tabIndex={0} + onKeyDown={(e) => { + if (e.key === 'ArrowUp' || e.key === 'ArrowDown' || + e.key === 'ArrowLeft' || e.key === 'ArrowRight') { + + // Create a hidden instance of LanguageSelector to extract languages + const tempDiv = document.createElement('div'); + tempDiv.style.position = 'absolute'; + tempDiv.style.left = '-9999px'; + document.body.appendChild(tempDiv); + + // Create a root and render the LanguageSelector temporarily + const root = createRoot(tempDiv); + root.render( + {}} + /> + ); + + // Use setTimeout to ensure the component has rendered + setTimeout(() => { + // Extract options from the rendered select element + const selectElement = tempDiv.querySelector('select'); + if (selectElement) { + const options = Array.from(selectElement.options); + const values = options.map(opt => opt.value); + + // Find current language index + const currentIndex = values.indexOf(currentLanguage); + let newIndex = currentIndex; + + if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') { + // Go to previous language + newIndex = (currentIndex - 1 + values.length) % values.length; + } else if (e.key === 'ArrowDown' || e.key === 'ArrowRight') { + // Go to next language + newIndex = (currentIndex + 1) % values.length; + } + + if (newIndex !== currentIndex) { + setLanguage(values[newIndex]); + window.electronAPI.updateConfig({ language: values[newIndex] }); + } + } + + // Clean up + root.unmount(); + document.body.removeChild(tempDiv); + }, 0); + } + }} + > + Language +
+ {currentLanguage} +
+ + + +
+
+
+
{/* API Key Settings */}