Create snippet with tags

This commit is contained in:
unknown
2021-09-28 12:17:59 +02:00
parent 3cd2688589
commit 86ea246e90
8 changed files with 121 additions and 76 deletions

View File

@@ -64,8 +64,8 @@ export const SnippetDetails = (props: Props): JSX.Element => {
{/* TAGS */}
<div>
{tags.map(tag => (
<span className='me-2'>
{tags.map((tag, idx) => (
<span className='me-2' key={idx}>
<Badge text={tag} color='dark' />
</span>
))}

View File

@@ -26,7 +26,7 @@ export const SnippetForm = (props: Props): JSX.Element => {
code: '',
docs: '',
isPinned: false,
tags: ''
tags: []
});
useEffect(() => {
@@ -46,6 +46,14 @@ export const SnippetForm = (props: Props): JSX.Element => {
});
};
const stringToTags = (e: ChangeEvent<HTMLInputElement>) => {
const tags = e.target.value.split(',');
setFormData({
...formData,
tags
});
};
const formHandler = (e: FormEvent) => {
e.preventDefault();
@@ -126,13 +134,13 @@ export const SnippetForm = (props: Props): JSX.Element => {
className='form-control'
id='tags'
name='tags'
value={formData.tags}
// value={formData.tags}
placeholder='automation, files, loop'
required
onChange={e => inputHandler(e)}
onChange={e => stringToTags(e)}
/>
<div className='form-text'>
Language tag will be added automatically
Tags should be separate with a comma. Language tag will be added
automatically
</div>
</div>
<hr />