Skip to content

Commit

Permalink
hotfix: removed maxlength option in comment
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilmhdh committed Oct 8, 2021
1 parent 6e25807 commit b95eb13
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idea-hub",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"homepage": "/ideas",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/CommentField/CommentField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const CommentField: FC<Props> & CompoundComponents = ({

return (
<Flex flexWrap={{ default: 'nowrap' }} alignItems={{ default: 'alignItemsFlexStart' }}>
<FlexItem>
<FlexItem style={{ flexShrink: 0 }}>
<Avatar
src={
avatar ||
Expand Down
43 changes: 23 additions & 20 deletions src/containers/CommentsContainer/CommentsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const CommentsContainer = ({ ideaDetails }: Props): JSX.Element => {

const dbChangeFeed = useRef<PouchDB.Core.Changes<IdeaDoc | CommentDoc>>();

const commentArea = useRef<HTMLInputElement | null>(null);
const commentWatch = watch('comment');

const { fetchState, handleFetchState } = useInfiniteScroll(() => {
Expand Down Expand Up @@ -126,18 +125,22 @@ export const CommentsContainer = ({ ideaDetails }: Props): JSX.Element => {
}: PouchDB.Core.ChangesResponseChange<IdeaDoc | CommentDoc>) => {
if (doc && doc?.type === 'comment' && commentsRef.current) {
const newCommentList = await onCommentChange(doc, commentsRef.current.docs, commentModel);
mutateComments((comments) => ({
cb: comments?.cb,
hasNextPage: Boolean(comments?.hasNextPage),
docs: newCommentList,
}));
mutateComments(
(comments) => ({
cb: comments?.cb,
hasNextPage: Boolean(comments?.hasNextPage),
docs: newCommentList,
}),
false
);
}
};

const onFormSubmit = async ({ comment: commentFieldValue }: FormData) => {
try {
await commentModel.createComment(ideaId, commentFieldValue);
setValue('comment', '');
commentModel.updateTotalCommentCountOfAnIdea(ideaId);
} catch (error) {
console.error(error);
window.OpNotification.danger({
Expand Down Expand Up @@ -250,13 +253,17 @@ export const CommentsContainer = ({ ideaDetails }: Props): JSX.Element => {
</SplitItem>
<SplitItem isFilled>
<Form onSubmit={handleSubmit(onFormSubmit)}>
<FormGroup fieldId="comment">
<Controller
name="comment"
control={control}
rules={{ required: true, maxLength: '150' }}
defaultValue=""
render={({ field: { ref, ...field }, fieldState: { error } }) => (
<Controller
name="comment"
control={control}
rules={{ required: true }}
defaultValue=""
render={({ field, fieldState: { error } }) => (
<FormGroup
fieldId="comment"
helperTextInvalid={error?.message}
validated={error?.message ? 'error' : 'default'}
>
<TextArea
style={{ resize: 'none' }}
id="comment"
Expand All @@ -265,15 +272,11 @@ export const CommentsContainer = ({ ideaDetails }: Props): JSX.Element => {
allowFullScreen
isRequired
validated={error?.message ? 'error' : 'default'}
ref={(e) => {
ref(e);
commentArea.current = e;
}}
{...field}
/>
)}
/>
</FormGroup>
</FormGroup>
)}
/>
<ActionGroup className="pf-u-mt-0">
<Button
variant="primary"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/HomePage/components/Categories/Categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const Categories = ({ tags, isLoading }: Props): JSX.Element => {
</div>
) : (
<MenuList>
{tags.map(({ key, value }) => (
{tags.slice(0, 5).map(({ key, value }) => (
<MenuItem
key={key}
onClick={() => handleMenuClick('category', category === key ? null : key)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,20 @@ export const IdeaCreateUpdateContainer = ({
name="title"
control={control}
defaultValue=""
rules={{ required: true }}
render={({ field }) => (
<FormGroup fieldId="title" isRequired label="Give a title for your idea:">
rules={{ required: true, maxLength: 250 }}
render={({ field, fieldState: { error } }) => (
<FormGroup
fieldId="title"
isRequired
label="Give a title for your idea:"
helperTextInvalid={
error?.type === 'maxLength' && 'Should be less than 250 characters'
}
validated={error ? 'error' : 'default'}
>
<TextInput
id="title"
validated={error ? 'error' : 'default'}
aria-label="title"
isRequired
placeholder="What is your idea about?"
Expand All @@ -107,11 +116,20 @@ export const IdeaCreateUpdateContainer = ({
name="description"
control={control}
defaultValue=""
rules={{ required: true }}
render={({ field }) => (
<FormGroup fieldId="desc" isRequired label=" Brief description">
rules={{ required: true, maxLength: 500 }}
render={({ field, fieldState: { error } }) => (
<FormGroup
fieldId="desc"
isRequired
label=" Brief description"
helperTextInvalid={
error?.type === 'maxLength' && 'Should be less than 500 characters'
}
validated={error ? 'error' : 'default'}
>
<TextArea
isRequired
validated={error ? 'error' : 'default'}
id="description"
aria-label="description"
placeholder="Describe you idea in simple terms…"
Expand Down
5 changes: 2 additions & 3 deletions src/pouchDB/api/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class CommentModel {
async createComment(ideaId: string, content: string): Promise<PouchDB.Core.Response> {
const { rhatUUID, fullName } = window.OpAuthHelper.getUserInfo();
const timestamp = new Date().getTime();
await this._db.put<CreateCommentDoc>({
return this._db.put<CreateCommentDoc>({
_id: `comment:${ideaId}:${timestamp}-${rhatUUID}`,
createdAt: timestamp,
updatedAt: timestamp,
Expand All @@ -143,10 +143,9 @@ export class CommentModel {
authorId: rhatUUID,
ideaId,
});
return this.updateTotalCommentCountOfaAnIdea(ideaId);
}

async updateTotalCommentCountOfaAnIdea(ideaId: string): Promise<PouchDB.Core.Response> {
async updateTotalCommentCountOfAnIdea(ideaId: string): Promise<PouchDB.Core.Response> {
const { rows } = await this._db.query(DesignDoc.CountOfCommentsForAnIdea, {
reduce: true,
group: true,
Expand Down

0 comments on commit b95eb13

Please sign in to comment.