Updating snippets with tags

This commit is contained in:
unknown
2021-09-28 13:26:48 +02:00
parent 86ea246e90
commit 714793a407
11 changed files with 97 additions and 67 deletions

View File

@@ -54,6 +54,10 @@ export const SnippetForm = (props: Props): JSX.Element => {
});
};
const tagsToString = (): string => {
return formData.tags.join(',');
};
const formHandler = (e: FormEvent) => {
e.preventDefault();
@@ -134,13 +138,13 @@ export const SnippetForm = (props: Props): JSX.Element => {
className='form-control'
id='tags'
name='tags'
// value={formData.tags}
value={tagsToString()}
placeholder='automation, files, loop'
onChange={e => stringToTags(e)}
/>
<div className='form-text'>
Tags should be separate with a comma. Language tag will be added
automatically
Tags should be separated with a comma. Language tag will be
added automatically
</div>
</div>
<hr />

View File

@@ -53,13 +53,13 @@ export const SnippetsContextProvider = (props: Props): JSX.Element => {
};
const setSnippet = (id: number): void => {
getSnippetById(id);
if (id < 0) {
setCurrentSnippet(null);
return;
}
getSnippetById(id);
const snippet = snippets.find(s => s.id === id);
if (snippet) {