// src/BubblesManager.js import React, { useEffect, useState } from "react"; import axios from "axios"; const BubblesManager = () => { const [bubbles, setBubbles] = useState([]); const [bubbleName, setBubbleName] = useState(""); const [bubbleText, setBubbleText] = useState(""); const [isEditing, setIsEditing] = useState(false); const [currentBubbleIndex, setCurrentBubbleIndex] = useState(null); useEffect(() => { fetchBubbles(); }, []); const fetchBubbles = async () => { try { const response = await axios.get( "https://api.config-fencing.com/api/get-bubbles" ); setBubbles(response.data.bubbles); } catch (error) { console.error("Error fetching bubbles:", error); } }; const addBubble = async () => { if (bubbleName.trim() !== "" && bubbleText.trim() !== "") { const response = await axios.post( "https://api.config-fencing.com/api/create-bubble", { name: bubbleName, text: bubbleText, } ); setBubbles([ ...bubbles, { id: response.data.bubble.id, name: bubbleName, text: bubbleText }, ]); setBubbleName(""); setBubbleText(""); } }; const editBubble = (index) => { setBubbleName(bubbles[index].name); setBubbleText(bubbles[index].text); setIsEditing(true); setCurrentBubbleIndex(index); }; const updateBubble = async () => { const response = await axios.post( `https://api.config-fencing.com/api/update-bubble/${bubbles[currentBubbleIndex].id}`, { name: bubbleName, text: bubbleText, } ); const updatedBubbles = bubbles.map((bubble, index) => index === currentBubbleIndex ? { id: bubble.id, name: bubbleName, text: bubbleText } : bubble ); setBubbles(updatedBubbles); setBubbleName(""); setBubbleText(""); setIsEditing(false); setCurrentBubbleIndex(null); }; const removeBubble = (index) => { const newBubbles = bubbles.filter((_, i) => i !== index); setBubbles(newBubbles); }; return (
{bubble.text}