Skip to content

Commit

Permalink
add tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric committed May 4, 2023
1 parent deb0924 commit 6e084c2
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 36 deletions.
44 changes: 44 additions & 0 deletions components/tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState } from "react";
import { Space, Tag } from "antd";

const { CheckableTag } = Tag;

interface Props {
Data: string[];
onClick?: (tag: string) => void;
}

const App = ({ Data, onClick }: Props) => {
const [selectedTags, setSelectedTags] = useState<string[]>([]);
// const tagsData = ["V1", "V2", "V3", "V4"];
const handleChange = (tag: string, checked: boolean) => {
if (!checked) return;
const nextSelectedTags = checked
? [...selectedTags, tag]
: selectedTags.filter((t) => t !== tag);
console.log("You are interested in: ", nextSelectedTags);
onClick && onClick(tag);
setSelectedTags(nextSelectedTags);
};

return (
<>
<Space className="ml-5" size={16} wrap>
{Data.map((tag) => (
<CheckableTag
className={
selectedTags.includes(tag) ? "bg-neutral-700" : "bg-neutral-200"
}
key={tag}
checked={selectedTags.includes(tag)}
onChange={(checked) => handleChange(tag, checked)}
>
{tag}
</CheckableTag>
))}
</Space>
</>
);
};

export default App;
5 changes: 4 additions & 1 deletion interfaces/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export interface Message {
text: string;
img: string;
}
msgID?: string;
msgHash?: string;
hasTag: boolean;
}
Loading

0 comments on commit 6e084c2

Please sign in to comment.