diff --git a/app/components/workbench/PortDropdown.tsx b/app/components/workbench/PortDropdown.tsx index 13457b2d..d84f940a 100644 --- a/app/components/workbench/PortDropdown.tsx +++ b/app/components/workbench/PortDropdown.tsx @@ -1,5 +1,4 @@ import { memo, useEffect, useRef } from 'react'; -import { IconButton } from '~/components/ui/IconButton'; import type { PreviewInfo } from '~/lib/stores/previews'; interface PortDropdownProps { @@ -48,9 +47,18 @@ export const PortDropdown = memo( return (
- setIsDropdownOpen(!isDropdownOpen)} /> + {/* Display the active port if available, otherwise show the plug icon */} + {isDropdownOpen && ( -
+
Ports
diff --git a/app/components/workbench/Preview.tsx b/app/components/workbench/Preview.tsx index 97cd848f..9c5bf9c5 100644 --- a/app/components/workbench/Preview.tsx +++ b/app/components/workbench/Preview.tsx @@ -58,8 +58,7 @@ export const Preview = memo(() => { const hasSelectedPreview = useRef(false); const previews = useStore(workbenchStore.previews); const activePreview = previews[activePreviewIndex]; - - const [url, setUrl] = useState(''); + const [displayPath, setDisplayPath] = useState('/'); const [iframeUrl, setIframeUrl] = useState(); const [isSelectionMode, setIsSelectionMode] = useState(false); @@ -92,36 +91,17 @@ export const Preview = memo(() => { useEffect(() => { if (!activePreview) { - setUrl(''); setIframeUrl(undefined); + setDisplayPath('/'); return; } const { baseUrl } = activePreview; - setUrl(baseUrl); setIframeUrl(baseUrl); + setDisplayPath('/'); }, [activePreview]); - const validateUrl = useCallback( - (value: string) => { - if (!activePreview) { - return false; - } - - const { baseUrl } = activePreview; - - if (value === baseUrl) { - return true; - } else if (value.startsWith(baseUrl)) { - return ['/', '?', '#'].includes(value.charAt(baseUrl.length)); - } - - return false; - }, - [activePreview], - ); - const findMinPortIndex = useCallback( (minIndex: number, preview: { port: number }, index: number, array: { port: number }[]) => { return preview.port < array[minIndex].port ? index : minIndex; @@ -653,40 +633,46 @@ export const Preview = memo(() => { />
-
+
+ (hasSelectedPreview.current = value)} + setIsDropdownOpen={setIsPortDropdownOpen} + previews={previews} + /> { - setUrl(event.target.value); + setDisplayPath(event.target.value); }} onKeyDown={(event) => { - if (event.key === 'Enter' && validateUrl(url)) { - setIframeUrl(url); + if (event.key === 'Enter' && activePreview) { + let targetPath = displayPath.trim(); + + if (!targetPath.startsWith('/')) { + targetPath = '/' + targetPath; + } + + const fullUrl = activePreview.baseUrl + targetPath; + setIframeUrl(fullUrl); + setDisplayPath(targetPath); if (inputRef.current) { inputRef.current.blur(); } } }} + disabled={!activePreview} />
- {previews.length > 1 && ( - (hasSelectedPreview.current = value)} - setIsDropdownOpen={setIsPortDropdownOpen} - previews={previews} - /> - )} -