import { useContext, useState } from "react";
import {
Empty,
Row,
Col,
AutoComplete,
Button,
Input,
Popover,
Toast,
} from "@douyinfe/semi-ui";
import {
IllustrationNoContent,
IllustrationNoContentDark,
} from "@douyinfe/semi-illustrations";
import {
IconPlus,
IconSearch,
IconCheckboxTick,
IconDeleteStroked,
} from "@douyinfe/semi-icons";
import {
defaultTableTheme,
tableThemes,
Action,
ObjectType,
} from "../data/data";
import { AreaContext, UndoRedoContext } from "../pages/Editor";
export default function AreaOverview() {
const { areas, addArea, deleteArea, updateArea } = useContext(AreaContext);
const { setUndoStack, setRedoStack } = useContext(UndoRedoContext);
const [editField, setEditField] = useState({});
const [value, setValue] = useState("");
const [filteredResult, setFilteredResult] = useState(
areas.map((t) => {
return t.name;
})
);
const handleStringSearch = (value) => {
setFilteredResult(
areas
.map((t) => {
return t.name;
})
.filter((i) => i.includes(value))
);
};
return (
}
placeholder="Search..."
emptyContent={
No areas found
}
onSearch={(v) => handleStringSearch(v)}
onChange={(v) => setValue(v)}
onSelect={(v) => {
const { id } = areas.find((t) => t.name === v);
document
.getElementById(`scroll_area_${id}`)
.scrollIntoView({ behavior: "smooth" });
}}
className="w-full"
/>
} block onClick={() => addArea()}>
Add area
{areas.length <= 0 ? (
}
darkModeImage={
}
title="No subject areas"
description="Add subject areas to compartmentalize tables!"
/>
) : (
{areas.map((a, i) => (
updateArea(a.id, { name: value })}
onFocus={(e) => setEditField({ name: e.target.value })}
onBlur={(e) => {
if (e.target.value === editField.name) return;
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.AREA,
aid: i,
undo: editField,
redo: { name: e.target.value },
message: `Edit area name to ${e.target.value}`,
},
]);
setRedoStack([]);
}}
/>
Theme
{tableThemes
.slice(0, Math.ceil(tableThemes.length / 2))
.map((c) => (
))}
{tableThemes
.slice(Math.ceil(tableThemes.length / 2))
.map((c) => (
))}
}
trigger="click"
position="bottomLeft"
showArrow
>
}
type="danger"
onClick={() => {
Toast.success(`Area deleted!`);
deleteArea(i, true);
}}
>
))}
)}
);
}