diff --git a/client/src/pages/AskQuestionPage.jsx b/client/src/pages/AskQuestionPage.jsx index 150c765..07f3d21 100644 --- a/client/src/pages/AskQuestionPage.jsx +++ b/client/src/pages/AskQuestionPage.jsx @@ -14,6 +14,7 @@ const AskQuestionPage = () => { const [tagInput, setTagInput] = useState('') const [content, setContent] = useState('') const [isSubmitting, setIsSubmitting] = useState(false) + const navigate = useNavigate() const queryClient = useQueryClient() @@ -50,6 +51,7 @@ const AskQuestionPage = () => { const addTag = () => { const tag = tagInput.trim().toLowerCase() + if (tag && !tags.includes(tag) && tags.length < 5) { setTags([...tags, tag]) setTagInput('') @@ -57,21 +59,28 @@ const AskQuestionPage = () => { } const removeTag = (tagToRemove) => { - setTags(tags.filter(tag => tag !== tagToRemove)) + setTags(tags.filter((tag) => tag !== tagToRemove)) + } + + const getPlainTextContent = () => { + return content.replace(/<[^>]*>/g, '').trim() } const onSubmit = async (data) => { + const plainTextContent = getPlainTextContent() + if (tags.length === 0) { toast.error('Please add at least one tag') return } - if (content.trim().length < 20) { + if (plainTextContent.length < 20) { toast.error('Question content must be at least 20 characters') return } setIsSubmitting(true) + try { await createQuestionMutation.mutateAsync({ title: data.title, @@ -85,23 +94,30 @@ const AskQuestionPage = () => { const quillModules = { toolbar: [ - [{ 'header': [1, 2, 3, false] }], + [{ header: [1, 2, 3, false] }], ['bold', 'italic', 'underline', 'strike'], - [{ 'list': 'ordered'}, { 'list': 'bullet' }], - [{ 'color': [] }, { 'background': [] }], - [{ 'align': [] }], + [{ list: 'ordered' }, { list: 'bullet' }], + [{ color: [] }, { background: [] }], + [{ align: [] }], ['link', 'image', 'code-block'], - ['clean'] + ['clean'], ], } const quillFormats = [ 'header', - 'bold', 'italic', 'underline', 'strike', - 'list', 'bullet', - 'color', 'background', + 'bold', + 'italic', + 'underline', + 'strike', + 'list', + 'bullet', + 'color', + 'background', 'align', - 'link', 'image', 'code-block' + 'link', + 'image', + 'code-block', ] return ( @@ -116,6 +132,7 @@ const AskQuestionPage = () => {
Share your knowledge and help others learn
@@ -124,9 +141,13 @@ const AskQuestionPage = () => {