Skip to content

Commit 19b91de

Browse files
committed
feat: integrate TagMultiSelect with TaskDialog for editing
1 parent 42a7330 commit 19b91de

3 files changed

Lines changed: 20 additions & 79 deletions

File tree

frontend/src/components/HomeComponents/Tasks/TaskDialog.tsx

Lines changed: 18 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { useEffect, useRef, useState } from 'react';
3838
import { useTaskDialogKeyboard } from './UseTaskDialogKeyboard';
3939
import { FIELDS } from './constants';
4040
import { useTaskDialogFocusMap } from './UseTaskDialogFocusMap';
41+
import { TagMultiSelect } from './TagMultiSelect';
4142

4243
export const TaskDialog = ({
4344
index,
@@ -54,6 +55,7 @@ export const TaskDialog = ({
5455
isCreatingNewProject,
5556
setIsCreatingNewProject,
5657
uniqueProjects,
58+
uniqueTags,
5759
onSaveDescription,
5860
onSaveTags,
5961
onSavePriority,
@@ -1188,104 +1190,41 @@ export const TaskDialog = ({
11881190
<TableCell>Tags:</TableCell>
11891191
<TableCell>
11901192
{editState.isEditingTags ? (
1191-
<div>
1192-
<div className="flex items-center w-full">
1193-
<Input
1194-
ref={(element) =>
1195-
(inputRefs.current.tags = element)
1196-
}
1197-
type="text"
1198-
value={editState.editTagInput}
1199-
onChange={(e) => {
1200-
// For allowing only alphanumeric characters
1201-
if (e.target.value.length > 1) {
1202-
/^[a-zA-Z0-9]*$/.test(e.target.value.trim())
1203-
? onUpdateState({
1204-
editTagInput: e.target.value.trim(),
1205-
})
1206-
: '';
1207-
} else {
1208-
/^[a-zA-Z]*$/.test(e.target.value.trim())
1209-
? onUpdateState({
1210-
editTagInput: e.target.value.trim(),
1211-
})
1212-
: '';
1213-
}
1214-
}}
1215-
placeholder="Add a tag (press enter to add)"
1216-
className="flex-grow mr-2"
1217-
onKeyDown={(e) => {
1218-
if (
1219-
e.key === 'Enter' &&
1220-
editState.editTagInput.trim()
1221-
) {
1222-
onUpdateState({
1223-
editedTags: [
1224-
...editState.editedTags,
1225-
editState.editTagInput.trim(),
1226-
],
1227-
editTagInput: '',
1228-
});
1229-
}
1230-
}}
1231-
/>
1193+
<div className="space-y-2">
1194+
<TagMultiSelect
1195+
availableTags={uniqueTags}
1196+
selectedTags={editState.editedTags}
1197+
onTagsChange={(tags) =>
1198+
onUpdateState({ editedTags: tags })
1199+
}
1200+
placeholder="Select or create tags"
1201+
/>
1202+
<div className="flex items-center gap-2 whitespace-nowrap">
12321203
<Button
12331204
variant="ghost"
12341205
size="icon"
1235-
aria-label="Save tags"
1206+
aria-label="save"
12361207
onClick={() => {
12371208
onSaveTags(task, editState.editedTags);
1238-
onUpdateState({
1239-
isEditingTags: false,
1240-
editTagInput: '',
1241-
});
1209+
onUpdateState({ isEditingTags: false });
12421210
}}
12431211
>
12441212
<CheckIcon className="h-4 w-4 text-green-500" />
12451213
</Button>
12461214
<Button
12471215
variant="ghost"
12481216
size="icon"
1249-
aria-label="Cancel editing tags"
1250-
onClick={() => {
1217+
aria-label="cancel"
1218+
onClick={() =>
12511219
onUpdateState({
12521220
isEditingTags: false,
12531221
editedTags: task.tags || [],
1254-
editTagInput: '',
1255-
});
1256-
}}
1222+
})
1223+
}
12571224
>
12581225
<XIcon className="h-4 w-4 text-red-500" />
12591226
</Button>
12601227
</div>
1261-
<div className="mt-2">
1262-
{editState.editedTags != null &&
1263-
editState.editedTags.length > 0 && (
1264-
<div>
1265-
<div className="flex flex-wrap gap-2 col-span-3">
1266-
{editState.editedTags.map((tag, index) => (
1267-
<Badge key={index}>
1268-
<span>{tag}</span>
1269-
<button
1270-
type="button"
1271-
className="ml-2 text-red-500"
1272-
onClick={() =>
1273-
onUpdateState({
1274-
editedTags:
1275-
editState.editedTags.filter(
1276-
(t) => t !== tag
1277-
),
1278-
})
1279-
}
1280-
>
1281-
1282-
</button>
1283-
</Badge>
1284-
))}
1285-
</div>
1286-
</div>
1287-
)}
1288-
</div>
12891228
</div>
12901229
) : (
12911230
<div className="flex items-center flex-wrap">

frontend/src/components/HomeComponents/Tasks/Tasks.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ export const Tasks = (
11981198
onUpdateState={updateEditState}
11991199
allTasks={tasks}
12001200
uniqueProjects={uniqueProjects}
1201+
uniqueTags={uniqueTags}
12011202
isCreatingNewProject={isCreatingNewProject}
12021203
setIsCreatingNewProject={setIsCreatingNewProject}
12031204
onSaveDescription={handleSaveDescription}

frontend/src/components/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export interface EditTaskDialogProps {
149149
onUpdateState: (updates: Partial<EditTaskState>) => void;
150150
allTasks: Task[];
151151
uniqueProjects: string[];
152+
uniqueTags: string[];
152153
isCreatingNewProject: boolean;
153154
setIsCreatingNewProject: (value: boolean) => void;
154155
onSaveDescription: (task: Task, description: string) => void;

0 commit comments

Comments
 (0)