Mailspring/internal_packages/mode-switch/lib/mode-toggle.cjsx
dillon 6f9e2194eb fix(mode-toggle): mode toggler now toggles the sidebar rather than the list/split view. fixes T3462.
Summary:
add functioning toggling

add correct hide/show behavior for toggler

remove old hide/show button

add padding to make buttons prettier

Test Plan: tested manually. all tests remain green.

Reviewers: evan

Reviewed By: evan

Maniphest Tasks: T3462

Differential Revision: https://phab.nylas.com/D1980
2015-09-04 12:32:19 -07:00

50 lines
1.4 KiB
CoffeeScript

{ComponentRegistry,
WorkspaceStore,
Actions} = require "nylas-exports"
{RetinaImg} = require 'nylas-component-kit'
React = require "react"
_ = require "underscore"
class ModeToggle extends React.Component
@displayName: 'ModeToggle'
constructor: (@props) ->
@column = WorkspaceStore.Location.MessageListSidebar
@state = @_getStateFromStores()
componentDidMount: =>
@_unsubscriber = WorkspaceStore.listen(@_onStateChanged)
@_mounted = true
componentWillUnmount: =>
@_mounted = false
@_unsubscriber?()
render: =>
<button className="btn btn-toolbar mode-toggle mode-#{@state.hidden}"
style={order:500}
onClick={@_onToggleMode}>
<RetinaImg
name="toolbar-icon-toggle-pane.png"
mode={RetinaImg.Mode.ContentIsMask} />
</button>
_onStateChanged: =>
# We need to keep track of this because our parent unmounts us in the same
# event listener cycle that we receive the event in. ie:
#
# for listener in listeners
# # 1. workspaceView remove left column
# # ---- Mode toggle unmounts, listeners array mutated in place
# # 2. ModeToggle update
return unless @_mounted
@setState(@_getStateFromStores())
_getStateFromStores: =>
{hidden: WorkspaceStore.isLocationHidden(@column)}
_onToggleMode: =>
Actions.toggleWorkspaceLocationHidden(@column)
module.exports = ModeToggle