Skip to content

Commit 39e4406

Browse files
Ограничил максимальное количество тегов и длину тега (#319)
* Ограничил максимальное количество тегов и длину тега * Вернул правило для проверки console.log в конфиг преттера * Рефактор кода. Удалил лишний участок кода * Рефактор кода. Изменил имена констант
1 parent a402425 commit 39e4406

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/app/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ export const QUESTIONS_PER_PAGE = 5;
1414
export const AVAILABLE_THEME_COLORS = Object.keys(theme.colors);
1515
export const DEFAULT_COLOR = theme.defaultColor;
1616
export const SCROLL_TO_TOP_SHOW = 500;
17+
18+
export const TAG_MAX_LENGTH = 15;
19+
20+
export const MAX_NUMBER_OF_TAGS = 5;

src/features/questions/create-question/CreateQuestionPage.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Paper } from 'components/layout/Paper';
1010
import { addQuestion } from 'features/questions/questionsSlice';
1111
import { selectProfile } from 'features/profile/profileSlice';
1212
import { useAuth } from 'common/context/Auth/useAuth';
13+
import { MAX_NUMBER_OF_TAGS, TAG_MAX_LENGTH } from 'app/constants';
1314

1415
const StyledQuestionWrapper = styled.div`
1516
& .new-tag {
@@ -130,6 +131,11 @@ const CreateQuestion = () => {
130131
setFullDescription(instance.getMarkdown());
131132
};
132133

134+
const handleChangeTag = (e) => {
135+
const limitedValue = e.target.value.substring(0, TAG_MAX_LENGTH);
136+
setTagValue(limitedValue);
137+
};
138+
133139
useEffect(() => {
134140
if (/\?[^?]+\?/.test(question)) {
135141
setTooManyQuestions(true);
@@ -218,22 +224,21 @@ const CreateQuestion = () => {
218224
</StyledTagBlock>
219225
))}
220226

221-
{!tagEditMode && (
227+
{!tagEditMode && tags.length < MAX_NUMBER_OF_TAGS && (
222228
<StyledTagBlock>
223229
<Tag className="site-tag-plus" onClick={() => setTagEditMode(true)}>
224230
<PlusOutlined /> New Tag
225231
</Tag>
226232
</StyledTagBlock>
227233
)}
228-
229234
{tagEditMode && (
230235
<StyledInputBlock>
231236
<Input
232237
ref={callbackRef}
233238
type="text"
234239
size="small"
235240
value={tagValue}
236-
onChange={(e) => setTagValue(e.target.value)}
241+
onChange={handleChangeTag}
237242
onKeyPress={handleKeyPress}
238243
onBlur={() => setTagEditMode(false)}
239244
/>

0 commit comments

Comments
 (0)