Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion client/src/components/MindMapHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ import Profile from "@/components/MindMapHeader/Profile";
import { useNodeListContext } from "@/store/NodeListProvider";
import { useConnectionStore } from "@/store/useConnectionStore";
import { Input } from "@headlessui/react";
import { useState } from "react";
import { useEffect, useRef, useState } from "react";
import { FaPencilAlt } from "react-icons/fa";

export default function MindMapHeader() {
const { title, updateTitle } = useNodeListContext();
const originalContent = title;
const inputRef = useRef<HTMLInputElement | null>(null);
const [editMode, setEditMode] = useState(false);
const handleSocketEvent = useConnectionStore((state) => state.handleSocketEvent);
const role = useConnectionStore((state) => state.currentRole);
const currentJobStatus = useConnectionStore((state) => state.currentJobStatus);

useEffect(() => {
if (editMode && inputRef.current) {
inputRef.current.focus();
inputRef.current.select();
}
}, [editMode]);

function handleInputBlur() {
if (!title.length) {
setEditMode(false);
Expand Down Expand Up @@ -48,6 +56,7 @@ export default function MindMapHeader() {
<MindMapHeaderButtons />
{editMode ? (
<Input
ref={inputRef}
className="flex w-80 items-center bg-transparent text-center"
value={title}
onChange={(e) => updateTitle(e.target.value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export default function NodeItem({ node, parentNodeId, open, handleAccordion, op
if (isSelected) openAccordion();
}, [isSelected]);

useEffect(() => {
if (isEditing && inputRef.current) {
inputRef.current.focus();
inputRef.current.select();
}
}, [isEditing]);

function handleAddButton() {
selectNode({ nodeId: node.id, parentNodeId: parentNodeId });
addNode(data, { nodeId: node.id, parentNodeId: parentNodeId }, overrideNodeData, (newNodeId) => {
Expand Down
9 changes: 9 additions & 0 deletions client/src/konva_mindmap/components/EditableTextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useRef } from "react";
import { Html } from "react-konva-utils";

interface EditableTextInputProps {
Expand All @@ -23,11 +24,19 @@ export default function EditableTextInput({
focus,
scale,
}: EditableTextInputProps) {
const inputRef = useRef<HTMLInputElement | null>(null);
const fontSize = scale >= 1 ? 16 : 16 / scale;

useEffect(() => {
if (inputRef.current && focus) {
inputRef.current.select();
}
}, [focus]);

return (
<Html groupProps={{ offset: { x: offsetX, y: offsetY } }}>
<input
ref={inputRef}
autoFocus={focus}
value={value}
onChange={onChange}
Expand Down