Skip to content

Commit 0fef96b

Browse files
committed
add/remove tags individually in ui
1 parent 08aa8e3 commit 0fef96b

1 file changed

Lines changed: 50 additions & 7 deletions

File tree

client/pages/upload.js

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import slugify from "slugify";
88
import { Link as LinkIcon } from "@styled-icons/boxicons-regular/Link";
99
import { Check } from "@styled-icons/boxicons-regular/Check";
1010
import { InfoCircle } from "@styled-icons/boxicons-regular/InfoCircle";
11+
import { Plus } from "@styled-icons/boxicons-regular/Plus";
12+
import { X } from "@styled-icons/boxicons-regular/X";
1113
import { withAuth } from "../utils/withAuth";
1214
import SEO from "../components/SEO";
1315
import Box from "../components/Box";
@@ -48,6 +50,7 @@ export const TorrentFields = ({
4850
values?.type ?? slugify(Object.keys(categories)[0], { lower: true })
4951
);
5052
const [sources, setSources] = useState([]);
53+
const [tags, setTags] = useState(values?.tags?.split(",") ?? []);
5154

5255
useEffect(() => {
5356
setSources(
@@ -126,13 +129,53 @@ export const TorrentFields = ({
126129
fontFamily="mono"
127130
mb={4}
128131
/>
129-
<Input
130-
name="tags"
131-
label="Tags"
132-
placeholder="Separated by commas"
133-
defaultValue={values?.tags}
134-
mb={4}
135-
/>
132+
<WrapLabel as={Box} label="Tags" mb={4}>
133+
<Box display="flex" flexWrap="wrap" m={-2}>
134+
{tags.map((tag, i) => (
135+
<Box key={`tag-${i}`} display="flex" m={2}>
136+
<Input
137+
value={tag}
138+
onChange={(e) => {
139+
setTags((t) => {
140+
const curTags = [...t];
141+
curTags.splice(i, 1, e.target.value);
142+
return curTags;
143+
});
144+
}}
145+
width="138px"
146+
mr={2}
147+
/>
148+
<Button
149+
onClick={() => {
150+
setTags((t) => {
151+
const curTags = [...t];
152+
curTags.splice(i, 1);
153+
return curTags;
154+
});
155+
}}
156+
type="button"
157+
variant="secondary"
158+
px={3}
159+
>
160+
<X size={20} />
161+
</Button>
162+
</Box>
163+
))}
164+
<Button
165+
onClick={() => setTags((t) => [...t, ""])}
166+
type="button"
167+
display="flex"
168+
alignItems="center"
169+
m={2}
170+
>
171+
<Plus size={18} />
172+
<Text as="span" ml={3}>
173+
Add tag
174+
</Text>
175+
</Button>
176+
</Box>
177+
</WrapLabel>
178+
<Input name="tags" value={tags.join(",")} display="none" />
136179
</>
137180
);
138181
};

0 commit comments

Comments
 (0)