Bio length -> 413 characters

Increase the cybre.space profile bio text length limit to 413
characters. Also modifies the account settings page to automatically
resize the textbox to the size of the contained text, so that it's
easier to type longer bios.
This commit is contained in:
khr 2018-11-12 20:30:47 -08:00
parent ba06a5f485
commit df0855a91b
4 changed files with 47 additions and 11 deletions

View File

@ -1,4 +1,4 @@
import loadPolyfills from '../mastodon/load_polyfills'; import loadPolyfills from '../mastodon/load_polyfills';
import ready from '../mastodon/ready'; import ready from '../mastodon/ready';
import { start } from '../mastodon/common'; import { start } from '../mastodon/common';
@ -17,6 +17,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();
}
}); });
}); });
@ -93,6 +99,17 @@ function main() {
detailedStatuses[0].scrollIntoView(); detailedStatuses[0].scrollIntoView();
history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true }); history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true });
} }
[].forEach.call(document.querySelectorAll('[data-component="Card"]'), (content) => {
const props = JSON.parse(content.getAttribute('data-props'));
ReactDOM.render(<CardContainer locale={locale} {...props} />, content);
});
if (document.fonts && document.fonts.ready) {
document.fonts.ready.then(sizeBioText);
} else {
sizeBioText();
}
}); });
delegate(document, '.webapp-btn', 'click', ({ target, button }) => { delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
@ -188,6 +205,22 @@ function main() {
console.error(err); console.error(err);
} }
}); });
delegate(document, '#account_note', 'input', sizeBioText);
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 => {

View File

@ -75,7 +75,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
@ -279,10 +280,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
@ -306,6 +305,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, :verified_at, :account, :errors attributes :name, :value, :verified_at, :account, :errors

View File

@ -7,7 +7,7 @@
.fields-row .fields-row
.fields-row__column.fields-group.fields-row__column-6 .fields-row__column.fields-group.fields-row__column-6
= f.input :display_name, wrapper: :with_label, input_html: { maxlength: 30 }, hint: false = f.input :display_name, wrapper: :with_label, input_html: { maxlength: 30 }, hint: false
= f.input :note, wrapper: :with_label, input_html: { maxlength: 160 }, hint: false = f.input :note, wrapper: :with_label, input_html: { maxlength: 413 }, hint: false
.fields-row .fields-row
.fields-row__column.fields-row__column-6 .fields-row__column.fields-row__column-6

View File

@ -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