Skip to content

Commit 09f0bbe

Browse files
committed
Remove unnecessary from ModuleNameComponent
1 parent feb86e2 commit 09f0bbe

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

src/reactComponents/AddTabDialog.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ export default function AddTabDialog(props: AddTabDialogProps) {
178178
setNewItemName={setNewItemName}
179179
onAddNewItem={handleAddNewItem}
180180
project={props.project}
181-
availableItems={availableItems}
182-
handleSelectItem={handleSelectItem}
183181
storage={props.storage}
184182
buttonLabel={t("New")}
185183
/>

src/reactComponents/ModuleNameComponent.tsx

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ type ModuleNameComponentProps = {
3636
setNewItemName: (name: string) => void;
3737
onAddNewItem: () => void;
3838
project: commonStorage.Project | null;
39-
availableItems: Module[];
40-
handleSelectItem: (item: Module) => void;
4139
storage: commonStorage.Storage | null;
4240
buttonLabel : string;
4341
};
@@ -48,34 +46,20 @@ export default function ModuleNameComponent(props: ModuleNameComponentProps) {
4846
const [alertErrorVisible, setAlertErrorVisible] = React.useState(false);
4947

5048
const handleAddNewItem = () => {
51-
if (props.newItemName.trim()) {
52-
// Check if there's an exact match in available items
53-
const matchingItem = props.availableItems.find(item =>
54-
item.title.toLowerCase() === props.newItemName.trim().toLowerCase()
55-
);
56-
57-
if (matchingItem) {
58-
// Move the matching item to selected
59-
props.handleSelectItem(matchingItem);
60-
props.setNewItemName("");
61-
setAlertErrorVisible(false);
62-
setAlertErrorMessage('');
63-
} else {
64-
if (props.project) {
65-
const { ok, error } = commonStorage.isClassNameOk(props.project, props.newItemName.trim());
66-
if (ok) {
67-
setAlertErrorVisible(false);
68-
setAlertErrorMessage('');
69-
// Create new item logic here if needed
70-
props.onAddNewItem();
71-
}else {
72-
setAlertErrorMessage(error);
73-
setAlertErrorVisible(true);
74-
}
49+
let trimmedName = props.newItemName.trim();
50+
if (trimmedName) {
51+
if (props.project) {
52+
const { ok, error } = commonStorage.isClassNameOk(props.project, trimmedName);
53+
if (ok) {
54+
setAlertErrorVisible(false);
55+
setAlertErrorMessage('');
56+
// Create new item logic here if needed
57+
props.onAddNewItem();
7558
} else {
76-
props.onAddNewItem();
59+
setAlertErrorMessage(error);
60+
setAlertErrorVisible(true);
7761
}
78-
}
62+
}
7963
}
8064
};
8165

0 commit comments

Comments
 (0)