Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. private getNoteSize(note: Note): Size {
  2. let attachmentsImage;
  3.  
  4. if (note.attachments) {
  5. attachmentsImage = note.attachments.filter(
  6. (attachment: Attachment) => attachment.type === TypeAttachment.Image,
  7. );
  8. }
  9.  
  10. let attachmentsSize = attachmentsImage && attachmentsImage.length;
  11.  
  12. if (attachmentsSize > 4) {
  13. return Size.L;
  14. }
  15.  
  16. if (note.type === TypeNote.List) {
  17. let noteList: NoteList = note;
  18.  
  19. if (!noteList) {
  20. throw new Error('Wrong note type');
  21. }
  22.  
  23. let noteListSize = noteList.items && noteList.items.length;
  24.  
  25. if (noteListSize > 10) {
  26. return Size.L;
  27. }
  28.  
  29. if (noteListSize > 5 || attachmentsSize > 2) {
  30. return Size.M;
  31. }
  32.  
  33. return Size.S;
  34. }
  35.  
  36. if (note.type === TypeNote.Text) {
  37. let noteText: NoteText = note;
  38.  
  39. if (!noteText) {
  40. throw new Error('Wrong note type');
  41. }
  42.  
  43. let noteTextSize = noteText.items && noteText.items.length;
  44.  
  45. if (noteTextSize > 300) {
  46. return Size.L;
  47. }
  48.  
  49. if (noteTextSize > 100 || attachmentsSize > 2) {
  50. return Size.M;
  51. }
  52.  
  53. return Size.S;
  54. }
  55.  
  56. if (note.type === TypeNote.Image) {
  57. return Size.M;
  58. }
  59.  
  60. return Size.S;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement