From 1fa52ae9f5654d09c7bb2ae8ef51a13dcbed5d88 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Sat, 4 Mar 2023 03:51:05 +0000 Subject: [PATCH] generate settings reading files --- packages/app/constants/settings/index.js | 42 +++++++++++++---------- packages/app/src/pages/settings/index.jsx | 8 +++-- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/packages/app/constants/settings/index.js b/packages/app/constants/settings/index.js index a10a9b52..10395dda 100755 --- a/packages/app/constants/settings/index.js +++ b/packages/app/constants/settings/index.js @@ -1,22 +1,26 @@ -import GeneralSettings from "./general" -import ProfileSettings from "./profile" -import SecuritySettings from "./security" -import NotificationsSettings from "./notifications" -import ApparenceSettings from "./apparence" -import ExtensionsSettings from "./extensions" -import SyncSettings from "./sync" -import PlayerSettings from "./player" +const settingsPaths = import.meta.glob("/constants/settings/*/index.jsx") -import AboutPage from "./about" +export default async () => { + const settings = {} -export default { - general: GeneralSettings, - profile: ProfileSettings, - apparence: ApparenceSettings, - player: PlayerSettings, - security: SecuritySettings, - notifications: NotificationsSettings, - extensions: ExtensionsSettings, - sync: SyncSettings, - about: AboutPage, + for (const [key, value] of Object.entries(settingsPaths)) { + const path = key.split("/").slice(-2) + const name = path[0] + + if (name === "components" || name === "index") { + continue + } + + if (!settings[name]) { + settings[name] = {} + } + + let setting = await value() + + setting = setting.default || setting + + settings[name] = setting + } + + return settings } \ No newline at end of file diff --git a/packages/app/src/pages/settings/index.jsx b/packages/app/src/pages/settings/index.jsx index 590d95db..6285fccd 100755 --- a/packages/app/src/pages/settings/index.jsx +++ b/packages/app/src/pages/settings/index.jsx @@ -6,10 +6,12 @@ import classnames from "classnames" import { Icons, createIconRender } from "components/Icons" -import SettingsList from "schemas/settings" +import getSettingsList from "schemas/settings" import menuGroupsDecorators from "schemas/settingsMenuGroupsDecorators" import groupsDecorators from "schemas/settingsGroupsDecorators" +const SettingsList = await getSettingsList() + import "./index.less" const ItemTypes = { @@ -477,7 +479,7 @@ const generateMenuItems = () => { }) } -export default React.memo(() => { +export default () => { const [activeKey, setActiveKey] = React.useState("general") const [menuItems, setMenuItems] = React.useState([]) @@ -515,4 +517,4 @@ export default React.memo(() => { } -}) \ No newline at end of file +} \ No newline at end of file