From a9ddbb5f87a29a03841b4a7693a535345d996cac Mon Sep 17 00:00:00 2001 From: Kenshin Date: Thu, 21 Jun 2018 15:54:14 +0800 Subject: [PATCH] Add plugin bar logicn. --- src/module/pluginbar.jsx | 71 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/src/module/pluginbar.jsx b/src/module/pluginbar.jsx index 7b791cdd..55e44622 100644 --- a/src/module/pluginbar.jsx +++ b/src/module/pluginbar.jsx @@ -1,11 +1,80 @@ console.log( "=== simpread plugin bar load ===" ) +import {storage} from 'storage'; + +import Button from 'button'; export default class Pluginbar extends React.Component { + state = { + category: [] + }; + + category = {}; + + getCategory() { + Object.values( storage.plugins ).forEach( ( item, idx ) => { + // test code + idx == 0 && ( item.category = "通用" ); + idx == 1 && ( item.category = "美化" ); + + if ( this.category[item.category] ) { + this.category[item.category].push( item ); + } else { + this.category[item.category] = []; + this.category[item.category].push( item ); + } + }); + this.setState({ category: Object.keys( this.category ) }); + } + + enable( id ) { + const plugin = storage.plugins[id]; + plugin.enable = !plugin.enable; + storage.Plugins( () => { + new Notify().Render( "当前插件已" + ( plugin.enable ? "启用" : "禁用" ) + ",请重新进入阅读模式以便生效。" ); + //this.category = {}; + //this.getCategory(); + //const bgColor = ( plugin.enable == undefined || plugin.enable == true ) ? plugin.icon.bgColor : "#c3c6c7"; + //console.log( $( this.refs[id] )[0] ) + //$( this.refs[id] ).css( "background-color", bgColor ); + }, storage.plugins ); + } + + componentWillMount() { + $( "head" ).append( '' ); + storage.Plugins( () => { + this.category = {}; + this.getCategory(); + }); + } + render() { + const child = this.state.category.map( item => { + + const actions = this.category[item].map( plugin => { + const bgColor = ( plugin.enable == undefined || plugin.enable == true ) ? plugin.icon.bgColor : "#c3c6c7"; + return ( +