From aa68517e79e07346b08bdbce69865425b726ac75 Mon Sep 17 00:00:00 2001 From: Ricardo Costa Date: Tue, 9 Jul 2024 00:23:13 +0100 Subject: [PATCH] Minor Fixes --- code/client/src/contexts/workspace/WorkspaceContext.tsx | 6 ++++-- .../components/workspace-tree/TreeResourceView.tsx | 2 +- code/client/src/ui/hooks/useEditing.tsx | 6 ++---- .../src/ui/pages/workspace/components/DocumentView.tsx | 4 ++-- .../src/ui/pages/workspaces/components/WorkspaceView.tsx | 8 +++----- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/code/client/src/contexts/workspace/WorkspaceContext.tsx b/code/client/src/contexts/workspace/WorkspaceContext.tsx index f497a73f..54429372 100644 --- a/code/client/src/contexts/workspace/WorkspaceContext.tsx +++ b/code/client/src/contexts/workspace/WorkspaceContext.tsx @@ -21,10 +21,12 @@ type WorkspaceContextType = { workspace?: WorkspaceMeta; resources?: Resources; operations?: WorkspaceOperations; - isMember?: boolean; + isMember: boolean; }; -export const WorkspaceContext = createContext({}); +export const WorkspaceContext = createContext({ + isMember: false, +}); export function WorkspaceProvider({ children }: { children: React.ReactNode }) { const services = useWorkspaceService(); diff --git a/code/client/src/ui/components/sidebar/components/workspace-tree/TreeResourceView.tsx b/code/client/src/ui/components/sidebar/components/workspace-tree/TreeResourceView.tsx index 3e0ca80a..e36fa2fe 100644 --- a/code/client/src/ui/components/sidebar/components/workspace-tree/TreeResourceView.tsx +++ b/code/client/src/ui/components/sidebar/components/workspace-tree/TreeResourceView.tsx @@ -37,7 +37,7 @@ function TreeResourceView({ }: TreeResourceViewProps) { const { isMember } = useWorkspace(); const [isOpen, setIsOpen] = useState(true); - const { component, isEditing, setIsEditing } = useEditing(resource.name || 'Untitled', (name: string) => + const { component, isEditing, setIsEditing } = useEditing(resource.name || 'Untitled', isMember, (name: string) => onRenameResource!(resource.id, name) ); diff --git a/code/client/src/ui/hooks/useEditing.tsx b/code/client/src/ui/hooks/useEditing.tsx index 99141fe3..ffe0f436 100644 --- a/code/client/src/ui/hooks/useEditing.tsx +++ b/code/client/src/ui/hooks/useEditing.tsx @@ -1,10 +1,8 @@ import { useEffect, useState } from 'react'; -import useWorkspace from '@/contexts/workspace/useWorkspace'; -function useEditing(initialValue: string, onEdit: (value: string) => void) { +function useEditing(initialValue: string, allowEdit: boolean, onEdit: (value: string) => void) { const [value, setValue] = useState(initialValue); const [isEditing, setIsEditing] = useState(false); - const { isMember } = useWorkspace(); // listen for changes in the initial value useEffect(() => { @@ -35,7 +33,7 @@ function useEditing(initialValue: string, onEdit: (value: string) => void) { return { component, isEditing, - setIsEditing: isMember ? setIsEditing : () => {}, + setIsEditing: allowEdit ? setIsEditing : () => {}, }; } diff --git a/code/client/src/ui/pages/workspace/components/DocumentView.tsx b/code/client/src/ui/pages/workspace/components/DocumentView.tsx index c22a9849..e9ae5939 100644 --- a/code/client/src/ui/pages/workspace/components/DocumentView.tsx +++ b/code/client/src/ui/pages/workspace/components/DocumentView.tsx @@ -18,9 +18,9 @@ type DocumentViewProps = { function DocumentView({ document, onSelect, onDelete, onRename, onDuplicate, selected }: DocumentViewProps) { const { wid } = useParams(); - const { component, isEditing, setIsEditing } = useEditing(document.name || 'Untitled', onRename); - const [isSelected, setSelected] = useState(selected); const { isMember } = useWorkspace(); + const { component, isEditing, setIsEditing } = useEditing(document.name || 'Untitled', isMember, onRename); + const [isSelected, setSelected] = useState(selected); useEffect(() => { setSelected(selected); diff --git a/code/client/src/ui/pages/workspaces/components/WorkspaceView.tsx b/code/client/src/ui/pages/workspaces/components/WorkspaceView.tsx index 2a350520..f1be9b13 100644 --- a/code/client/src/ui/pages/workspaces/components/WorkspaceView.tsx +++ b/code/client/src/ui/pages/workspaces/components/WorkspaceView.tsx @@ -28,7 +28,7 @@ function WorkspaceView({ onRemoveMember, toggleVisibility, }: WorkspacePreviewProps) { - const { component, isEditing, setIsEditing } = useEditing(workspace.name, onRename); + const { component, isEditing, setIsEditing } = useEditing(workspace.name, true, onRename); const [isSelected, setSelected] = useState(selected); useEffect(() => { @@ -49,9 +49,7 @@ function WorkspaceView({

{workspace.isPrivate ? 'Private' : 'Public'}

); - return isEditing ? ( - WorkspaceComponent - ) : ( + return ( setIsEditing(true)} @@ -60,7 +58,7 @@ function WorkspaceView({ onRemoveMember={onRemoveMember} toggleVisibility={toggleVisibility} > - {WorkspaceComponent} + {isEditing ? WorkspaceComponent : {WorkspaceComponent}} ); }