Skip to content
Snippets Groups Projects
spacemanager.tsx 3.19 KiB
Newer Older
import React, { useState } from "react";
import "./spacemanager.css";

interface SpaceManagerProps {
    spaces: string[];
    spaceId: string;
    onDeleteSpace: (spaceId: string) => void;
    onRenameSpace: (newId: string) => void;
    onDuplicateSpace: (newId: string) => void;
    onCreateSpace: (spaceId: string) => void;
}
    spaceId,
    onDeleteSpace,
    onRenameSpace,
    onDuplicateSpace,
    onCreateSpace,
}: SpaceManagerProps) {
    const [deleteConfirmationVisible, setDeleteConfirmationVisible] =
        useState(false);
    const [newSpaceName, setNewSpaceName] = useState("New space");
    const handleDeleteSpace = () => {
        setDeleteConfirmationVisible(false);
        onDeleteSpace(spaceId);
    };
    const normalizedNewSpaceName = () => newSpaceName.trim();
    const isSpaceCreationAllowed = () =>
        newSpaceName.length === 0 || spaces.includes(normalizedNewSpaceName());
    return (
        <div id="space-manager">
            <label htmlFor="space-name">New space name</label>
            <br />
            <input
                id="space-name"
                type={"text"}
                value={newSpaceName}
                onChange={(e) => setNewSpaceName(e.target.value)}
            />
                        disabled={isSpaceCreationAllowed()}
Maximilian Giller's avatar
Maximilian Giller committed
                        onClick={() => onCreateSpace(normalizedNewSpaceName())}
Maximilian Giller's avatar
Maximilian Giller committed
                        Create empty space{" "}
                        {'"' + normalizedNewSpaceName() + '"'}
                        disabled={isSpaceCreationAllowed()}
                        onClick={() =>
                            onDuplicateSpace(normalizedNewSpaceName())
                        }
                        Duplicate as {'"' + normalizedNewSpaceName() + '"'}
                        disabled={isSpaceCreationAllowed()}
Maximilian Giller's avatar
Maximilian Giller committed
                        onClick={() => onRenameSpace(normalizedNewSpaceName())}
Maximilian Giller's avatar
Maximilian Giller committed
                        Rename to {'"' + normalizedNewSpaceName() + '"'}
                    </button>
                </li>
            </ul>
            <hr />
            <ul>
                <li>
                    <button
                        onClick={() =>
                            setDeleteConfirmationVisible(
                                !deleteConfirmationVisible
                            )
                        }
                    >
                        Delete space {'"' + spaceId + '"'}?
                    </button>
                </li>
                {deleteConfirmationVisible && (
                    <li>
                        <button className="warning" onClick={handleDeleteSpace}>
                            Delete the space {'"' + spaceId + '"'} and all its

export default SpaceManager;