Sha256: 26545edb9db323c7b2ab843e98d364fe56ca73a41f18df01c76cf1d729a62d79

Contents?: true

Size: 879 Bytes

Versions: 5

Compression:

Stored size: 879 Bytes

Contents

class ChatComponent < Roda::Component
  comp_name :chat
  comp_html "../public/chat/index.html"

  def display
    return unless server?

    request.redirect 'login' unless current_user

    dom.find('.my-account .name span').html current_user.full_name

    component(:layout) do
      dom.find('body').html
    end
  end

  on :reconnect do
    puts 'reconnected'
  end

  on :disconnect do
    puts 'disconnected'
  end

  on :connect do
    puts 'connected'
  end

  on :join do |data|
    if client?
      `console.log(#{data});`
      puts 'joined'
    else
      user_details
    end
  end

  on :leave do |data|
    if client?
      `console.log(#{data});`
      puts 'leave'
    else
      user_details
    end
  end

  def user_details
    {
      id: current_user.id,
      first_name: current_user.first_name,
      last_name: current_user.last_name
    }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roda-component-0.1.7 test/dummy/components/chat.rb
roda-component-0.1.6 test/dummy/components/chat.rb
roda-component-0.1.5 test/dummy/components/chat.rb
roda-component-0.1.4 test/dummy/components/chat.rb
roda-component-0.1.3 test/dummy/components/chat.rb