Sha256: c349693a90e80e35cd95307f3ad81fb1e659ca5b2c40924e2a51f0d8294e0a5b

Contents?: true

Size: 696 Bytes

Versions: 13

Compression:

Stored size: 696 Bytes

Contents

class Message < Hyperloop::Component
  param :message, type: Hash

  after_mount :scroll_to_bottom
  after_update :scroll_to_bottom

  def render
   div.row.alternating.message do
     div.col_sm_2 { params.message[:from] }
     FormattedDiv class: 'col-sm-8', markdown: params.message[:message]
     div.col_sm_2 { formatted_time }
   end
  end

  def scroll_to_bottom
    Element['html, body'].animate({ scrollTop: Element[Document].height }, :slow)
  end

  def formatted_time
    time = params.message[:time]
    if Time.now < time + 1.day
      time.strftime '%I:%M %p'
    elsif Time.now < time + 7.days
      time.strftime '%A'
    else
      time.strftime '%D %I:%M %p'
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hyper-operation-0.5.12 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.11 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.10 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.9 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.8 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.7 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.6 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.5 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.4 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.3 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.2 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.1 examples/chat-app/app/hyperloop/components/message.rb
hyper-operation-0.5.0 examples/chat-app/app/hyperloop/components/message.rb