Feature: increase bio length to 413 characters
This commit is contained in:
		
							parent
							
								
									7ac5151b74
								
							
						
					
					
						commit
						fcc5feceab
					
				
					 4 changed files with 34 additions and 17 deletions
				
			
		| 
						 | 
					@ -14,6 +14,12 @@ window.addEventListener('message', e => {
 | 
				
			||||||
      id: data.id,
 | 
					      id: data.id,
 | 
				
			||||||
      height: document.getElementsByTagName('html')[0].scrollHeight,
 | 
					      height: document.getElementsByTagName('html')[0].scrollHeight,
 | 
				
			||||||
    }, '*');
 | 
					    }, '*');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (document.fonts && document.fonts.ready) {
 | 
				
			||||||
 | 
					      document.fonts.ready.then(sizeBioText);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      sizeBioText();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,13 +117,7 @@ function main() {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  delegate(document, '.account_note', 'input', ({ target }) => {
 | 
					  delegate(document, '.account_note', 'input', sizeBioText);
 | 
				
			||||||
    const noteCounter = document.querySelector('.note-counter');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (noteCounter) {
 | 
					 | 
				
			||||||
      noteCounter.textContent = 160 - length(target.value);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  delegate(document, '#account_avatar', 'change', ({ target }) => {
 | 
					  delegate(document, '#account_avatar', 'change', ({ target }) => {
 | 
				
			||||||
    const avatar = document.querySelector('.card.compact .avatar img');
 | 
					    const avatar = document.querySelector('.card.compact .avatar img');
 | 
				
			||||||
| 
						 | 
					@ -134,6 +134,20 @@ function main() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    header.style.backgroundImage = `url(${url})`;
 | 
					    header.style.backgroundImage = `url(${url})`;
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  function sizeBioText() {
 | 
				
			||||||
 | 
					    const noteCounter = document.querySelector('.note-counter');
 | 
				
			||||||
 | 
					    const bioTextArea = document.querySelector('#account_note');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (noteCounter) {
 | 
				
			||||||
 | 
					      noteCounter.textContent = 413 - length(bioTextArea.value);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (bioTextArea) {
 | 
				
			||||||
 | 
					      bioTextArea.style.height = 'auto';
 | 
				
			||||||
 | 
					      bioTextArea.style.height = (bioTextArea.scrollHeight+3) + 'px';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
loadPolyfills().then(main).catch(error => {
 | 
					loadPolyfills().then(main).catch(error => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,7 +74,8 @@ class Account < ApplicationRecord
 | 
				
			||||||
  validates_with UniqueUsernameValidator, if: -> { local? && will_save_change_to_username? }
 | 
					  validates_with UniqueUsernameValidator, if: -> { local? && will_save_change_to_username? }
 | 
				
			||||||
  validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? }
 | 
					  validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? }
 | 
				
			||||||
  validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? }
 | 
					  validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? }
 | 
				
			||||||
  validates :note, length: { maximum: 160 }, if: -> { local? && will_save_change_to_note? }
 | 
					  validates :note, length: { maximum: 413 }, if: -> { local? && will_save_change_to_note? }
 | 
				
			||||||
 | 
					  validate :note_has_eight_newlines?, if: -> { local? && will_save_change_to_note? }
 | 
				
			||||||
  validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? }
 | 
					  validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Timelines
 | 
					  # Timelines
 | 
				
			||||||
| 
						 | 
					@ -254,10 +255,8 @@ class Account < ApplicationRecord
 | 
				
			||||||
  def save_with_optional_media!
 | 
					  def save_with_optional_media!
 | 
				
			||||||
    save!
 | 
					    save!
 | 
				
			||||||
  rescue ActiveRecord::RecordInvalid
 | 
					  rescue ActiveRecord::RecordInvalid
 | 
				
			||||||
    self.avatar              = nil
 | 
					    self.avatar = nil if errors[:avatar].present?
 | 
				
			||||||
    self.header              = nil
 | 
					    self.header = nil if errors[:header].present?
 | 
				
			||||||
    self[:avatar_remote_url] = ''
 | 
					 | 
				
			||||||
    self[:header_remote_url] = ''
 | 
					 | 
				
			||||||
    save!
 | 
					    save!
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -281,6 +280,10 @@ class Account < ApplicationRecord
 | 
				
			||||||
    shared_inbox_url.presence || inbox_url
 | 
					    shared_inbox_url.presence || inbox_url
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def note_has_eight_newlines?
 | 
				
			||||||
 | 
					    errors.add(:note, 'Bio can\'t have more then 8 newlines') unless note.count("\n") <= 8
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  class Field < ActiveModelSerializers::Model
 | 
					  class Field < ActiveModelSerializers::Model
 | 
				
			||||||
    attributes :name, :value, :account, :errors
 | 
					    attributes :name, :value, :account, :errors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  .fields-group
 | 
					  .fields-group
 | 
				
			||||||
    = f.input :display_name, placeholder: t('simple_form.labels.defaults.display_name'), hint: t('simple_form.hints.defaults.display_name', count: 30 - @account.display_name.size).html_safe
 | 
					    = f.input :display_name, placeholder: t('simple_form.labels.defaults.display_name'), hint: t('simple_form.hints.defaults.display_name', count: 30 - @account.display_name.size).html_safe
 | 
				
			||||||
    = f.input :note, placeholder: t('simple_form.labels.defaults.note'), hint: t('simple_form.hints.defaults.note', count: 160 - @account.note.size).html_safe
 | 
					    = f.input :note, placeholder: t('simple_form.labels.defaults.note'), hint: t('simple_form.hints.defaults.note', count: 413 - @account.note.size).html_safe
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  .card.compact{ style: "background-image: url(#{@account.header.url(:original)})", data: { original_src: @account.header.url(:original) } }
 | 
					  .card.compact{ style: "background-image: url(#{@account.header.url(:original)})", data: { original_src: @account.header.url(:original) } }
 | 
				
			||||||
    .avatar= image_tag @account.avatar.url(:original), data: { original_src: @account.avatar.url(:original) }
 | 
					    .avatar= image_tag @account.avatar.url(:original), data: { original_src: @account.avatar.url(:original) }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -596,8 +596,8 @@ RSpec.describe Account, type: :model do
 | 
				
			||||||
        expect(account).to model_have_error_on_field(:display_name)
 | 
					        expect(account).to model_have_error_on_field(:display_name)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'is invalid if the note is longer than 160 characters' do
 | 
					      it 'is invalid if the note is longer than 413 characters' do
 | 
				
			||||||
        account = Fabricate.build(:account, note: Faker::Lorem.characters(161))
 | 
					        account = Fabricate.build(:account, note: Faker::Lorem.characters(414))
 | 
				
			||||||
        account.valid?
 | 
					        account.valid?
 | 
				
			||||||
        expect(account).to model_have_error_on_field(:note)
 | 
					        expect(account).to model_have_error_on_field(:note)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
| 
						 | 
					@ -636,8 +636,8 @@ RSpec.describe Account, type: :model do
 | 
				
			||||||
        expect(account).not_to model_have_error_on_field(:display_name)
 | 
					        expect(account).not_to model_have_error_on_field(:display_name)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'is valid even if the note is longer than 160 characters' do
 | 
					      it 'is valid even if the note is longer than 413 characters' do
 | 
				
			||||||
        account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(161))
 | 
					        account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(414))
 | 
				
			||||||
        account.valid?
 | 
					        account.valid?
 | 
				
			||||||
        expect(account).not_to model_have_error_on_field(:note)
 | 
					        expect(account).not_to model_have_error_on_field(:note)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue