From e8d902ae494c7f57c1fba947c28bf8aff36b204b Mon Sep 17 00:00:00 2001 From: chr Date: Mon, 12 Nov 2018 20:30:47 -0800 Subject: [PATCH] Bio length -> 500 characters Increase the cybre.space profile bio text length limit to 500 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. --- app/javascript/packs/public.js | 41 ++++++++++++++++++++++++++++++++++ app/models/account.rb | 6 ++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js index 2fb9cb29d..b37edd555 100644 --- a/app/javascript/packs/public.js +++ b/app/javascript/packs/public.js @@ -19,6 +19,12 @@ window.addEventListener('message', e => { id: data.id, height: document.getElementsByTagName('html')[0].scrollHeight, }, '*'); + + if (document.fonts && document.fonts.ready) { + document.fonts.ready.then(sizeBioText); + } else { + sizeBioText(); + } }); }); @@ -118,6 +124,25 @@ function main() { delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original')); delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static')); + + if (document.body.classList.contains('with-modals')) { + const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth; + const scrollbarWidthStyle = document.createElement('style'); + scrollbarWidthStyle.id = 'scrollbar-width'; + document.head.appendChild(scrollbarWidthStyle); + scrollbarWidthStyle.sheet.insertRule(`body.with-modals--active { margin-right: ${scrollbarWidth}px; }`, 0); + } + + [].forEach.call(document.querySelectorAll('[data-component="Card"]'), (content) => { + const props = JSON.parse(content.getAttribute('data-props')); + ReactDOM.render(, content); + }); + + if (document.fonts && document.fonts.ready) { + document.fonts.ready.then(sizeBioText); + } else { + sizeBioText(); + } }); delegate(document, '.webapp-btn', 'click', ({ target, button }) => { @@ -249,6 +274,22 @@ function main() { target.style.display = 'block'; } }); + + delegate(document, '#account_note', 'input', sizeBioText); + + function sizeBioText() { + const noteCounter = document.querySelector('.note-counter'); + const bioTextArea = document.querySelector('#account_note'); + + if (noteCounter) { + noteCounter.textContent = 500 - length(bioTextArea.value); + } + + if (bioTextArea) { + bioTextArea.style.height = 'auto'; + bioTextArea.style.height = (bioTextArea.scrollHeight+3) + 'px'; + } + } } loadPolyfills() diff --git a/app/models/account.rb b/app/models/account.rb index 0eb719d65..bcdb21f38 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -80,6 +80,7 @@ class Account < ApplicationRecord 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 :note, note_length: { maximum: 500 }, 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? } scope :remote, -> { where.not(domain: nil) } @@ -318,7 +319,6 @@ class Account < ApplicationRecord rescue ActiveRecord::RecordInvalid self.avatar = nil self.header = nil - save! end @@ -342,6 +342,10 @@ class Account < ApplicationRecord shared_inbox_url.presence || inbox_url 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 attributes :name, :value, :verified_at, :account, :errors