diff --git a/packages/comty/package-lock.json b/packages/comty/package-lock.json index 598a61d0..4c3e4650 100644 --- a/packages/comty/package-lock.json +++ b/packages/comty/package-lock.json @@ -11,7 +11,6 @@ "@icons-pack/react-simple-icons": "^3.8.0", "@lingui/react": "^3.3.0", "@ragestudio/nodecore-api-lib": "^0.2.6", - "@types/jest": "^26.0.15", "@types/lodash": "^4.14.165", "antd": "^4.8.2", "axios": "^0.21.1", @@ -33,6 +32,7 @@ "moment": "^2.28.0", "path-to-regexp": "^6.1.0", "platform": "^1.3.6", + "react": "^16.14.0", "react-animations": "^1.0.0", "react-color": "^2.19.3", "react-dazzle": "^1.4.0", @@ -4797,16 +4797,6 @@ "@types/istanbul-lib-report": "*" } }, - "node_modules/@types/jest": { - "version": "26.0.19", - "resolved": "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.19.tgz", - "integrity": "sha512-jqHoirTG61fee6v6rwbnEuKhpSKih0tuhqeFbCmMmErhtu3BYlOZaXWjffgOstMM4S/3iQD31lI5bGLTrs97yQ==", - "license": "MIT", - "dependencies": { - "jest-diff": "^26.0.0", - "pretty-format": "^26.0.0" - } - }, "node_modules/@types/json-schema": { "version": "7.0.6", "resolved": "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz", @@ -38902,15 +38892,6 @@ "@types/istanbul-lib-report": "*" } }, - "@types/jest": { - "version": "26.0.19", - "resolved": "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.19.tgz", - "integrity": "sha512-jqHoirTG61fee6v6rwbnEuKhpSKih0tuhqeFbCmMmErhtu3BYlOZaXWjffgOstMM4S/3iQD31lI5bGLTrs97yQ==", - "requires": { - "jest-diff": "^26.0.0", - "pretty-format": "^26.0.0" - } - }, "@types/json-schema": { "version": "7.0.6", "resolved": "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz", diff --git a/packages/comty/package.json b/packages/comty/package.json index 60550647..f5d50f3f 100644 --- a/packages/comty/package.json +++ b/packages/comty/package.json @@ -35,6 +35,7 @@ "moment": "^2.28.0", "path-to-regexp": "^6.1.0", "platform": "^1.3.6", + "react": "^16.14.0", "react-animations": "^1.0.0", "react-color": "^2.19.3", "react-dazzle": "^1.4.0", diff --git a/packages/comty/schemas/settings.json b/packages/comty/schemas/settings.json deleted file mode 100644 index 6f54d735..00000000 --- a/packages/comty/schemas/settings.json +++ /dev/null @@ -1,37 +0,0 @@ -[ - { - "id": "session_noexpire", - "icon": "Watch", - "type": "switch", - "title": "No expire session", - "description": "Force the app to not expire any session... [Developer]" - }, - { - "id": "search_ontype", - "icon": "CornerDownRight", - "type": "switch", - "title": "Detect input on search bar", - "description": "Force the app to automaticly search when a type input is detected... [Developer]" - }, - { - "id": "post_hidebar", - "icon": "Menu", - "type": "switch", - "title": "Auto hide postbar", - "description": "Force the app to hide the post actions (likes, comments ...etc) automaticly... [Developer]" - }, - { - "id": "post_autoposition", - "icon": "AlignCenter", - "type": "switch", - "title": "Auto center on click", - "description": "" - }, - { - "id": "verbosity", - "icon": "Terminal", - "type": "switch", - "title": "Enable core verbosity", - "description": "Show all console logs... [Developer]" - } -] diff --git a/packages/comty/schemas/settings_general.json b/packages/comty/schemas/settings_general.json new file mode 100644 index 00000000..06866df4 --- /dev/null +++ b/packages/comty/schemas/settings_general.json @@ -0,0 +1,37 @@ +[ + { + "id": "session_noexpire", + "icon": "Watch", + "type": "Switch", + "title": "No expire session", + "description": "Force the app to not expire any session" + }, + { + "id": "search_ontype", + "icon": "CornerDownRight", + "type": "Switch", + "title": "Auto search on input", + "description": "Search automaticly when type something" + }, + { + "id": "post_hidebar", + "icon": "Menu", + "type": "Switch", + "title": "Auto hide postbar", + "description": "Hide post actions bar when loose focus" + }, + { + "id": "post_autoposition", + "icon": "AlignCenter", + "type": "Switch", + "title": "Center on click", + "description": "Center posts element when then is clicked" + }, + { + "id": "verbosity", + "icon": "Terminal", + "type": "Switch", + "title": "Verbosity", + "description": "Show all development logs of the application" + } +] diff --git a/packages/comty/src/pages/settings/components/general/index.js b/packages/comty/src/pages/settings/components/general/index.js index 02ea9460..41b0cb59 100644 --- a/packages/comty/src/pages/settings/components/general/index.js +++ b/packages/comty/src/pages/settings/components/general/index.js @@ -1,127 +1,83 @@ -import React, { Component, Fragment } from 'react' -import { List, Switch, Button, notification, InputNumber } from 'antd' +import React from 'react' +import { List, Button, Switch, Checkbox, InputNumber, Input } from 'antd' +import * as Icons from 'components/Icons' import { verbosity } from '@nodecorejs/utils' -import * as Icons from 'components/Icons' import { settings, newSetting } from 'core/libs/settings' -import SettingList from 'schemas/settings.json' +import listSettings from 'schemas/settings_general.json' -import {connect} from 'umi' - -@connect(({ app }) => ({ app })) -export default class GeneralSettings extends Component { - constructor(props) { - super(props); - this.state = { - list: SettingList, - }; +const AntdComponents = { Button, Switch, Checkbox, InputNumber, Input } +export default class GeneralSettings extends React.Component { + state = { + list: listSettings, } - renderSetting = item => { + renderSetting = (item) => { + if (!item.type || !item.id) { + verbosity.log("Invalid component >", item) + return null + } + if (typeof(AntdComponents[item.type]) == "undefined") { + verbosity.log(`Invalid component, '${item.type}' not exists >`, item) + return null + } + + let itemProps = { + onChange: (e) => this.onChange(item, e), + checked: settings.get(item.id) + } + switch (item.type) { - case 'switch': - return ( - this.onChange(item)} - /> - ) - case 'numeric': - return ( - this.onChangeNumeric(item, value)} - /> - ) + case 'Switch': { + itemProps = { ...itemProps } // checkedChildren: "Enabled", unCheckedChildren: "Disabled" + break + } default: break } + + return React.createElement(AntdComponents[item.type], itemProps) } - handleControlBar() { - const ListControls = [ -
- -
, - ] - ControlController.set(ListControls) - } - - saveChanges() { - localStorage.setItem('app_settings', JSON.stringify(this.state.SettingRepo)) - this.setState({ forSave: false }) - notification.success({ - message: 'Settings saved', - description: - 'The configuration has been saved, it may for some configuration to make changes you need to reload the application', - }) - ControlController.close() - } - - onChange(item) { + onChange(item, event) { try { - switch (item.type) { - case 'switch': { - item.to = !settings.get(item.id) - verbosity.log(`Changing setting (${item.id}: ${settings.get(item.id)}) => ${item.to}`) - settings.set(item.id, item.to) - this.handleChange(item) + let to = event - } - case 'numeric': { + verbosity.colors({ log: { textColor: "blue" } }).log(`Updating setting (${item.id}) > ${to}`) + settings.set(item.id, to) - } - default: { - return null - } - } - } catch (err) { - console.log(err) - } - } - - - handleChange(item) { - try { - const updatedValue = this.state.list.map(element => - element.id === item.id ? Object.assign(element, { value: item.to }) : element + const updatedValues = this.state.list.map(element => + element.id === item.id ? Object.assign(element, { value: to }) : element ) - this.setState({ list: updatedValue}) + this.setState({ list: updatedValues }) } catch (err) { console.log(err) } } - + + renderIcon(icon, props) { + if (!Icons[icon]) { + verbosity.log(`${icon} not exist!`) + return null + } + return React.createElement(Icons[icon], props ?? null) + } render() { return ( - -
- ( - - {item.icon}{item.title}} - description={item.description} - /> - {this.renderSetting(item)} - - )} - /> -
-
+ ( + + {this.renderIcon(item.icon)}{item.title}} + description={item.description} + /> + {this.renderSetting(item)} + + )} + /> ) } } \ No newline at end of file diff --git a/packages/comty/src/pages/settings/components/theme/index.js b/packages/comty/src/pages/settings/components/theme/index.js index 447c7f38..f969f7be 100644 --- a/packages/comty/src/pages/settings/components/theme/index.js +++ b/packages/comty/src/pages/settings/components/theme/index.js @@ -2,7 +2,7 @@ import React from 'react' import * as Icons from 'components/Icons' import * as antd from 'antd' import { connect } from 'umi' -import { arrayToObject, objectToArrayMap } from 'core' +import { arrayToObject } from 'core' import ThemeSettingsList from 'schemas/theme_settings.json' import BackgroundSetting from './components/background' @@ -62,7 +62,7 @@ export default class ThemeSettings extends React.Component { renderItem={item => (
handleClick(item.id)}> -

{item.icon}{item.title}
{isActive(arrayToObject(this.props.app.app_theme)[item.id]) ? "Enabled" : "Disabled"}

+

{React.createElement(Icons[item.icon])}{item.title}
{isActive(arrayToObject(this.props.app.app_theme)[item.id]) ? "Enabled" : "Disabled"}

{item.description}