From 694cd7483ed634c2b27fbc1cd2e3b4af623c5b22 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Tue, 13 Aug 2024 02:18:26 -0700 Subject: [PATCH] EnhancedRenderCode x LiveFileSync: Apply To --- .../WorkspaceLiveFilePicker.tsx | 96 ++++++++++++------- .../livefile-patch/useLiveFilePatch.tsx | 23 +++-- 2 files changed, 77 insertions(+), 42 deletions(-) diff --git a/src/modules/blocks/enhanced-code/livefile-patch/WorkspaceLiveFilePicker.tsx b/src/modules/blocks/enhanced-code/livefile-patch/WorkspaceLiveFilePicker.tsx index 8c03e3c47..8c1e4fc41 100644 --- a/src/modules/blocks/enhanced-code/livefile-patch/WorkspaceLiveFilePicker.tsx +++ b/src/modules/blocks/enhanced-code/livefile-patch/WorkspaceLiveFilePicker.tsx @@ -1,10 +1,11 @@ import * as React from 'react'; -import { Box, Dropdown, IconButton, ListItemDecorator, Menu, MenuButton, MenuItem } from '@mui/joy'; +import { Box, Button, IconButton, ListItemDecorator, MenuItem } from '@mui/joy'; import ClearIcon from '@mui/icons-material/Clear'; import CodeIcon from '@mui/icons-material/Code'; import type { LiveFileId, LiveFileMetadata } from '~/common/livefile/liveFile.types'; +import { CloseableMenu } from '~/common/components/CloseableMenu'; import { LiveFilePatchIcon } from '~/common/components/icons/LiveFilePatchIcon'; import { useContextWorkspaceId } from '~/common/stores/workspace/WorkspaceIdProvider'; import { useWorkspaceContentsMetadata } from '~/common/stores/workspace/useWorkspaceContentsMetadata'; @@ -14,12 +15,15 @@ import { useWorkspaceContentsMetadata } from '~/common/stores/workspace/useWorks * Allows selection of LiveFiles in the current Workspace */ export function WorkspaceLiveFilePicker(props: { - enabled: boolean; autoSelectName: string | null; + buttonLabel: string; + enabled: boolean; liveFileId: LiveFileId | null; onSelectLiveFile: (id: LiveFileId | null) => void; }) { + // state for anchor + const [menuAnchor, setMenuAnchor] = React.useState(null); // external state const workspaceId = useContextWorkspaceId(); @@ -47,37 +51,61 @@ export function WorkspaceLiveFilePicker(props: { }, [enabled, wLiveFiles, autoSelectName, onSelectLiveFile]); - return ( - + // handlers - {/* Activation button */} - {/**/} - ) => { + event.preventDefault(); // added for the Right mouse click (to prevent the menu) + setMenuAnchor(anchor => anchor ? null : event.currentTarget); + }, []); + + const handleCloseMenu = React.useCallback(() => { + setMenuAnchor(null); + }, []); + + const handleSelectLiveFile = React.useCallback((id: LiveFileId | null) => { + onSelectLiveFile(id); + setMenuAnchor(null); + }, [onSelectLiveFile]); + + + return <> + + {/**/} + {liveFileId ? ( + - - - {/**/} + + + ) : ( + + )} + {/**/} - {/* List of the Workspace LiveFiles to pair */} - + {/**/} {/* Recent Workspace Files*/} {/**/} @@ -86,7 +114,7 @@ export function WorkspaceLiveFilePicker(props: { onSelectLiveFile(lfm.id)} + onClick={() => handleSelectLiveFile(lfm.id)} > @@ -101,12 +129,14 @@ export function WorkspaceLiveFilePicker(props: { {/**/} {!!liveFileId && ( - onSelectLiveFile(null)}> + handleSelectLiveFile(null)}> Remove )} - - - ); + + + )} + + ; } \ No newline at end of file diff --git a/src/modules/blocks/enhanced-code/livefile-patch/useLiveFilePatch.tsx b/src/modules/blocks/enhanced-code/livefile-patch/useLiveFilePatch.tsx index 322e54d52..b3a2f0ffd 100644 --- a/src/modules/blocks/enhanced-code/livefile-patch/useLiveFilePatch.tsx +++ b/src/modules/blocks/enhanced-code/livefile-patch/useLiveFilePatch.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import { Typography } from '@mui/joy'; +import { Box, Typography } from '@mui/joy'; import { useContextWorkspaceId } from '~/common/stores/workspace/WorkspaceIdProvider'; import { useWorkspaceContentsMetadata } from '~/common/stores/workspace/useWorkspaceContentsMetadata'; @@ -36,16 +36,21 @@ export function useLiveFilePatch(title: string, code: string, isPartial: boolean // components - const button = React.useMemo(() => !isEnabled ? null : <> + const button = React.useMemo(() => !isEnabled ? null : ( - + - , [isEnabled, liveFileId, title]); + + + + + ), [isEnabled, liveFileId, title]); const actionBar = React.useMemo(() => (!isEnabled || !liveFilesMetadata || true) ? null : (