Back
Version 10
11/17/2024
/** @jsxImportSource https://esm.sh/react */
import React from "https://esm.sh/react";
import ReactDOM from "https://esm.sh/react-dom";
import { createRoot } from "https://esm.sh/react-dom/client";
// [Rest of the existing code remains the same until handleEditNode function]
const handleEditNode = async (node, isSpouse = false) => {
const currentName = isSpouse && node.spouse ? node.spouse.name : node.name;
const newName = prompt(`Enter new ${isSpouse ? 'spouse' : 'person'} name`, currentName);
if (newName !== null) {
try {
// Send updated name to server
const response = await fetch('/edit-node', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
nodeId: isSpouse ? node.spouse.id : node.id,
name: newName,
isSpouse: isSpouse
})
});
if (response.ok) {
setNodes(prevNodes => {
const updatedNodes = { ...prevNodes };
if (isSpouse) {
updatedNodes[node.id] = {
...updatedNodes[node.id],
spouse: {
...updatedNodes[node.id].spouse,
name: newName
}
nirwan-family100.web.val.run
Updated: November 18, 2024