Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Commit

Permalink
Change the max and min note body size (on the client)
Browse files Browse the repository at this point in the history
None of this is tested yet; I'll do that next.
  • Loading branch information
helloworld12321 committed Apr 21, 2020
1 parent 6cf3afa commit e85de73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
10 changes: 5 additions & 5 deletions client/src/app/add/add-note.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Router } from '@angular/router';
import { Note } from '../note';
import { Note, MAXIMUM_BODY_LENGTH, MINIMUM_BODY_LENGTH } from '../note';
import { Owner } from '../owner';
import { NotesService } from '../notes.service';
import { OwnerService } from '../owner.service';
Expand Down Expand Up @@ -33,8 +33,8 @@ export class AddNoteComponent implements OnInit {
addNoteValidationMessages = {
body: [
{type: 'required', message: 'Body is required'},
{type: 'minlength', message: 'Body must be at least 2 characters long'},
{type: 'maxlength', message: 'Body cannot be more than 300 characters long'}
{type: 'minlength', message: `Body must be at least ${MINIMUM_BODY_LENGTH} characters long`},
{type: 'maxlength', message: `Body cannot be more than ${MAXIMUM_BODY_LENGTH} characters long`},
]
};

Expand All @@ -44,8 +44,8 @@ export class AddNoteComponent implements OnInit {
this.addNoteForm = this.fb.group({
body: new FormControl('', Validators.compose([
Validators.required,
Validators.minLength(2),
Validators.maxLength(300),
Validators.minLength(MAXIMUM_BODY_LENGTH),
Validators.maxLength(MINIMUM_BODY_LENGTH),
])),
});
}
Expand Down
18 changes: 12 additions & 6 deletions client/src/app/edit/edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Router } from '@angular/router';
import { Note } from '../note';
import { Note, MAXIMUM_BODY_LENGTH, MINIMUM_BODY_LENGTH } from '../note';
import { NotesService } from '../notes.service';
import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
Expand All @@ -21,14 +21,20 @@ export class EditComponent implements OnInit {
id: string;
getNoteSub: Subscription;

constructor(private fb: FormBuilder, private _location: Location, private noteService: NotesService, private snackBar: MatSnackBar, private router: Router, private route: ActivatedRoute) {
constructor(
private fb: FormBuilder,
private _location: Location,
private noteService: NotesService,
private snackBar: MatSnackBar,
private router: Router,
private route: ActivatedRoute) {
}

editNoteValidationMessages = {
body: [
{type: 'required', message: 'Body is required'},
{type: 'minlength', message: 'Body must be at least 2 characters long'},
{type: 'maxlength', message: 'Body cannot be more than 300 characters long'}
{type: 'minlength', message: `Body must be at least ${MINIMUM_BODY_LENGTH} characters long`},
{type: 'maxlength', message: `Body cannot be more than ${MAXIMUM_BODY_LENGTH} characters long`}
]
};

Expand All @@ -38,8 +44,8 @@ export class EditComponent implements OnInit {
this.editNoteForm = this.fb.group({
body: new FormControl('', Validators.compose([
Validators.required,
Validators.minLength(2),
Validators.maxLength(300),
Validators.minLength(MINIMUM_BODY_LENGTH),
Validators.maxLength(MAXIMUM_BODY_LENGTH),
])),
});

Expand Down
10 changes: 10 additions & 0 deletions client/src/app/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ export interface Note {
body: string;
posted: boolean;
}

/**
* The length of a note's body should be less than or equal to this value.
*/
export const MAXIMUM_BODY_LENGTH = 10_000;

/**
* The length of a note's body should be greater than or equal to this value.
*/
export const MINIMUM_BODY_LENGTH = 1;

0 comments on commit e85de73

Please sign in to comment.