From 807d5aab2011dc5b9b01bbe8971e2b37cf2b5d63 Mon Sep 17 00:00:00 2001 From: "@dev-opsss" Date: Tue, 8 Apr 2025 23:47:40 -0500 Subject: [PATCH 1/5] 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 */}
From 493d4488f454db50c5ba9c8e34ded090598bf17d Mon Sep 17 00:00:00 2001 From: "@dev-opsss" Date: Tue, 8 Apr 2025 23:59:29 -0500 Subject: [PATCH 2/5] Updated README.md with Language Selection --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 7c1dffe..47aeaf6 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,13 @@ The packaged applications will be available in the `release` directory. - Window remains invisible to specified screen sharing applications - Start a new problem using [Control or Cmd + R] +6. **Language Selection + + - Easily switch between programming languages with a single click + - Use arrow keys for keyboard navigation through available languages + - The system dynamically adapts to any languages added or removed from the codebase + - Your language preference is saved between sessions + ## Adding More AI Models This application is built with extensibility in mind. You can easily add support for additional LLMs alongside the existing OpenAI integration: From 27e74aca539bd715d073ba158937cd845069be15 Mon Sep 17 00:00:00 2001 From: dev-opsss Date: Wed, 9 Apr 2025 10:26:15 -0500 Subject: [PATCH 3/5] Understandable Variable --- src/components/Queue/QueueCommands.tsx | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/Queue/QueueCommands.tsx b/src/components/Queue/QueueCommands.tsx index a0eaa35..c7c6c73 100644 --- a/src/components/Queue/QueueCommands.tsx +++ b/src/components/Queue/QueueCommands.tsx @@ -386,13 +386,13 @@ const QueueCommands: React.FC = ({ className="flex items-center justify-between cursor-pointer hover:bg-white/10 rounded px-2 py-1 transition-colors" onClick={() => { // 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); + const hiddenRenderContainer = document.createElement('div'); + hiddenRenderContainer.style.position = 'absolute'; + hiddenRenderContainer.style.left = '-9999px'; + document.body.appendChild(hiddenRenderContainer); // Create a root and render the LanguageSelector temporarily - const root = createRoot(tempDiv); + const root = createRoot(hiddenRenderContainer); root.render( = ({ // Use setTimeout to ensure the component has rendered setTimeout(() => { // Extract options from the rendered select element - const selectElement = tempDiv.querySelector('select'); + const selectElement = hiddenRenderContainer.querySelector('select'); if (selectElement) { const options = Array.from(selectElement.options); const values = options.map(opt => opt.value); @@ -419,7 +419,7 @@ const QueueCommands: React.FC = ({ // Clean up root.unmount(); - document.body.removeChild(tempDiv); + document.body.removeChild(hiddenRenderContainer); }, 0); }} tabIndex={0} @@ -428,13 +428,13 @@ const QueueCommands: React.FC = ({ 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); + const hiddenRenderContainer = document.createElement('div'); + hiddenRenderContainer.style.position = 'absolute'; + hiddenRenderContainer.style.left = '-9999px'; + document.body.appendChild(hiddenRenderContainer); // Create a root and render the LanguageSelector temporarily - const root = createRoot(tempDiv); + const root = createRoot(hiddenRenderContainer); root.render( = ({ // Use setTimeout to ensure the component has rendered setTimeout(() => { // Extract options from the rendered select element - const selectElement = tempDiv.querySelector('select'); + const selectElement = hiddenRenderContainer.querySelector('select'); if (selectElement) { const options = Array.from(selectElement.options); const values = options.map(opt => opt.value); @@ -470,7 +470,7 @@ const QueueCommands: React.FC = ({ // Clean up root.unmount(); - document.body.removeChild(tempDiv); + document.body.removeChild(hiddenRenderContainer); }, 0); } }} From 8c8aef99395542b13355625c6fac522ee42826df Mon Sep 17 00:00:00 2001 From: dev-opsss Date: Wed, 9 Apr 2025 10:33:34 -0500 Subject: [PATCH 4/5] component rendered timeout --- src/components/Queue/QueueCommands.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/Queue/QueueCommands.tsx b/src/components/Queue/QueueCommands.tsx index c7c6c73..218f83b 100644 --- a/src/components/Queue/QueueCommands.tsx +++ b/src/components/Queue/QueueCommands.tsx @@ -400,7 +400,8 @@ const QueueCommands: React.FC = ({ /> ); - // Use setTimeout to ensure the component has rendered + // Use a small delay to ensure the component has rendered + // 50ms is generally enough for React to complete a render cycle setTimeout(() => { // Extract options from the rendered select element const selectElement = hiddenRenderContainer.querySelector('select'); @@ -420,7 +421,7 @@ const QueueCommands: React.FC = ({ // Clean up root.unmount(); document.body.removeChild(hiddenRenderContainer); - }, 0); + }, 50); // Increased timeout to ensure render completes }} tabIndex={0} onKeyDown={(e) => { @@ -442,7 +443,8 @@ const QueueCommands: React.FC = ({ /> ); - // Use setTimeout to ensure the component has rendered + // Use a small delay to ensure the component has rendered + // 50ms is generally enough for React to complete a render cycle setTimeout(() => { // Extract options from the rendered select element const selectElement = hiddenRenderContainer.querySelector('select'); @@ -471,7 +473,7 @@ const QueueCommands: React.FC = ({ // Clean up root.unmount(); document.body.removeChild(hiddenRenderContainer); - }, 0); + }, 50); // Increased timeout to ensure render completes } }} > From bacf4c5ed2c57b02203943c0dbf03a49b0b42f46 Mon Sep 17 00:00:00 2001 From: dev-opsss Date: Wed, 9 Apr 2025 11:01:39 -0500 Subject: [PATCH 5/5] Logic change --- src/components/Queue/QueueCommands.tsx | 143 ++++++++++--------------- 1 file changed, 55 insertions(+), 88 deletions(-) diff --git a/src/components/Queue/QueueCommands.tsx b/src/components/Queue/QueueCommands.tsx index 218f83b..88d6c28 100644 --- a/src/components/Queue/QueueCommands.tsx +++ b/src/components/Queue/QueueCommands.tsx @@ -24,6 +24,56 @@ const QueueCommands: React.FC = ({ const tooltipRef = useRef(null) const { showToast } = useToast() + // Extract the repeated language selection logic into a separate function + const extractLanguagesAndUpdate = (direction?: 'next' | 'prev') => { + // Create a hidden instance of LanguageSelector to extract languages + const hiddenRenderContainer = document.createElement('div'); + hiddenRenderContainer.style.position = 'absolute'; + hiddenRenderContainer.style.left = '-9999px'; + document.body.appendChild(hiddenRenderContainer); + + // Create a root and render the LanguageSelector temporarily + const root = createRoot(hiddenRenderContainer); + root.render( + {}} + /> + ); + + // Use a small delay to ensure the component has rendered + // 50ms is generally enough for React to complete a render cycle + setTimeout(() => { + // Extract options from the rendered select element + const selectElement = hiddenRenderContainer.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 (direction === 'prev') { + // Go to previous language + newIndex = (currentIndex - 1 + values.length) % values.length; + } else { + // Default 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(hiddenRenderContainer); + }, 50); + }; + useEffect(() => { let tooltipHeight = 0 if (tooltipRef.current && isTooltipVisible) { @@ -384,96 +434,13 @@ const QueueCommands: React.FC = ({
{ - // Create a hidden instance of LanguageSelector to extract languages - const hiddenRenderContainer = document.createElement('div'); - hiddenRenderContainer.style.position = 'absolute'; - hiddenRenderContainer.style.left = '-9999px'; - document.body.appendChild(hiddenRenderContainer); - - // Create a root and render the LanguageSelector temporarily - const root = createRoot(hiddenRenderContainer); - root.render( - {}} - /> - ); - - // Use a small delay to ensure the component has rendered - // 50ms is generally enough for React to complete a render cycle - setTimeout(() => { - // Extract options from the rendered select element - const selectElement = hiddenRenderContainer.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(hiddenRenderContainer); - }, 50); // Increased timeout to ensure render completes - }} + onClick={() => extractLanguagesAndUpdate('next')} 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 hiddenRenderContainer = document.createElement('div'); - hiddenRenderContainer.style.position = 'absolute'; - hiddenRenderContainer.style.left = '-9999px'; - document.body.appendChild(hiddenRenderContainer); - - // Create a root and render the LanguageSelector temporarily - const root = createRoot(hiddenRenderContainer); - root.render( - {}} - /> - ); - - // Use a small delay to ensure the component has rendered - // 50ms is generally enough for React to complete a render cycle - setTimeout(() => { - // Extract options from the rendered select element - const selectElement = hiddenRenderContainer.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(hiddenRenderContainer); - }, 50); // Increased timeout to ensure render completes + if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') { + extractLanguagesAndUpdate('prev'); + } else if (e.key === 'ArrowDown' || e.key === 'ArrowRight') { + extractLanguagesAndUpdate('next'); } }} >