Skip to content

Commit

Permalink
fix: remove tag creation from dropdown (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitu committed May 19, 2024
1 parent 4c8d23e commit c23c3cf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 55 deletions.
14 changes: 2 additions & 12 deletions packages/next/src/components/FancyMultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export function FancyMultiSelect({
placeholder = 'Select option...',
initialSelected = [],
onSelected,
onRemoved,
onCreated
onRemoved
}: {
readonly initialSelected?: string[];
onCreated?(created: string): void;
onRemoved(removed: string): void;
onSelected(selected: string): void;
readonly options: Option[];
Expand Down Expand Up @@ -63,17 +61,9 @@ export function FancyMultiSelect({
if (e.key === 'Escape') {
input.blur();
}

if (e.key === 'Enter') {
const currentValue = input.value.trim();
if (options.filter(option => option.label === currentValue).length === 0 && onCreated) {
onCreated(currentValue);
setInputValue('');
}
}
}
},
[onCreated, onRemoved, options, selected]
[onRemoved, selected]
);

const selectables = options.filter(option => !selected.includes(option));
Expand Down
43 changes: 0 additions & 43 deletions packages/next/src/components/FileDialogInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,48 +120,6 @@ export const FileDialogInformation = ({
[file?.uuid]
);

const createTag = useCallback(
async (tag: string) => {
if (tag.trim() === '') return;
if (!tag) return;

try {
const { data: response, error } = await request.post({
url: `tag/create`,
body: { name: tag }
});

if (error) {
toast.error(error);
return;
}

if (response.tag) {
setTags([
...tags,
{
uuid: response.tag.uuid,
name: response.tag.name
}
]);

setFileTags([
...fileTags,
{
uuid: response.tag.uuid,
name: response.tag.name
}
]);

void addTagToFile(response.tag.uuid);
}
} catch (error: any) {
toast.error(error);
}
},
[addTagToFile, fileTags, tags]
);

const removeTagFromFile = useCallback(
async (tagUuid: string) => {
try {
Expand Down Expand Up @@ -337,7 +295,6 @@ export const FileDialogInformation = ({
initialSelected={fileTags.map(tag => tag.uuid)}
onSelected={async value => addTagToFile(value)}
onRemoved={async value => removeTagFromFile(value)}
onCreated={async value => createTag(value)}
/>
</div>
</div>
Expand Down

0 comments on commit c23c3cf

Please sign in to comment.