Skip to content

Commit

Permalink
feat: add global toggle to Preferences screen
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Jun 19, 2018
1 parent 8b2197b commit a7851d2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "Label for IPFS icon (panel_headerIpfsNodeIconLabel)"
},
"panel_headerActiveToggleTitle": {
"message": "Toggle to activate or suspend gateway redirect and all active API integrations",
"message": "Global toggle: activate or suspend all IPFS integrations",
"description": "Label for an embedded IPFS node (panel_headerActiveToggleTitle)"
},
"panel_statusOffline": {
Expand Down
19 changes: 19 additions & 0 deletions add-on/src/options/forms/global-toggle-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'
/* eslint-env browser, webextensions */

const browser = require('webextension-polyfill')
const html = require('choo/html')

function globalToggleForm ({ active, onOptionChange }) {
const toggle = onOptionChange('active')
return html`
<form class="dib mb3">
<label for="active" class="dib pa3 pointer ${!active ? 'bg-aqua-muted br2' : ''}">
<input class="mr2 pointer" id="active" type="checkbox" onchange=${toggle} checked=${active} />
${browser.i18n.getMessage('panel_headerActiveToggleTitle')}
</label>
</form>
`
}

module.exports = globalToggleForm
4 changes: 3 additions & 1 deletion add-on/src/options/options.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
html.is-chrome {
@import url('/ui-kit/tachyons.css');
@import url('/ui-kit/ipfs.css');
html {
overflow: hidden;
}
.is-chrome body {
Expand Down
17 changes: 17 additions & 0 deletions add-on/src/options/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-env browser, webextensions */

const html = require('choo/html')
const globalToggleForm = require('./forms/global-toggle-form')
const ipfsNodeForm = require('./forms/ipfs-node-form')
const gatewaysForm = require('./forms/gateways-form')
const apiForm = require('./forms/api-form')
Expand All @@ -28,8 +29,24 @@ module.exports = function optionsPage (state, emit) {
emit('optionsReset')
}

if (!state.options.active) {
// we don't want to confuse users by showing "active" checkboxes
// when global toggle is in "suspended" state
return html`
<div>
${globalToggleForm({
active: state.options.active,
onOptionChange
})}
</div>
`
}
return html`
<div>
${globalToggleForm({
active: state.options.active,
onOptionChange
})}
${ipfsNodeForm({
ipfsNodeType: state.options.ipfsNodeType,
ipfsNodeConfig: state.options.ipfsNodeConfig,
Expand Down

0 comments on commit a7851d2

Please sign in to comment.