Skip to content

Commit

Permalink
chore: add delete tag action
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Mar 9, 2024
1 parent 999a053 commit 8cdc0c7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion web/src/components/TagList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useFilterStore, useTagStore } from "@/store/module";
import { useMemoList } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import showCreateTagDialog from "./CreateTagDialog";
import { showCommonDialog } from "./Dialog/CommonDialog";
import Icon from "./Icon";
import showRenameTagDialog from "./RenameTagDialog";

Expand Down Expand Up @@ -97,7 +98,9 @@ interface TagItemContainerProps {
}

const TagItemContainer: React.FC<TagItemContainerProps> = (props: TagItemContainerProps) => {
const t = useTranslate();
const filterStore = useFilterStore();
const tagStore = useTagStore();
const { tag, tagQuery } = props;
const isActive = tagQuery === tag.text;
const hasSubTags = tag.subTags.length > 0;
Expand All @@ -116,6 +119,18 @@ const TagItemContainer: React.FC<TagItemContainerProps> = (props: TagItemContain
toggleSubTags();
};

const handleDeleteTag = async () => {
showCommonDialog({
title: "Delete Tag",
content: "Are you sure to delete this tag?",
style: "danger",
dialogName: "delete-tag-dialog",
onConfirm: async () => {
await tagStore.deleteTag(tag.text);
},
});
};

return (
<>
<div className="relative group flex flex-row justify-between items-center w-full h-8 py-0 mt-px first:mt-1 rounded-lg text-base sm:text-sm cursor-pointer select-none shrink-0 hover:opacity-80">
Expand All @@ -131,7 +146,10 @@ const TagItemContainer: React.FC<TagItemContainerProps> = (props: TagItemContain
</div>
</MenuButton>
<Menu size="sm" placement="bottom-start">
<MenuItem onClick={() => showRenameTagDialog({ tag: tag.text })}>Rename</MenuItem>
<MenuItem onClick={() => showRenameTagDialog({ tag: tag.text })}>{t("common.rename")}</MenuItem>
<MenuItem color="danger" onClick={handleDeleteTag}>
{t("common.delete")}
</MenuItem>
</Menu>
</Dropdown>
<span className="truncate" onClick={handleTagClick}>
Expand Down

0 comments on commit 8cdc0c7

Please sign in to comment.