These are chat archives for opal/opal

7th
Mar 2017
dan-klasson
@dan-klasson
Mar 07 2017 05:36
I'm trying to move some display a filter box logic out from a component to a store. And I am trying to change the state inside the store when a button is clicked. The problem is that the state isn't being changed.
class ToggleNavBarStore < Hyperloop::Store

    state display_filter_box: true, scope: :class, reader: true

    def self.toggle
      display = Element.find(:body).has_class? 'sidebar-collapse'
      self.mutate.display_filter_box(!display)
      LocalStorage['nav_bar_expanded'] = !display
    end

    def self.nav_bar_initial_state
      collapsed = LocalStorage['nav_bar_expanded'] == 'false' ? false : true
      display_filter_box(collapsed)
      Element.find(:body).add_class 'sidebar-collapse' unless collapsed
    end

end
so in my component i call nav_bar_initial_state like so:
    before_mount do
      ToggleNavBarStore.nav_bar_initial_state
    end
when the button is clicked:
          end.on(:click) { ::ToggleNavBarStore.toggle }
and whether to render the box div:
        if ToggleNavBarStore.display_filter_box
dan-klasson
@dan-klasson
Mar 07 2017 07:12
oops. wrong channel. sorry