Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

:zap: Adds a helper function, to process component visiblity

Alicia Sykesec95fafe04ae
diff --git a/src/utils/ConfigHelpers.js b/src/utils/ConfigHelpers.js
new file mode 100644
index 00000000..365d1b19
--- /dev/null
+++ b/src/utils/ConfigHelpers.js
@@ -0,0 +1,42 @@
+import ConfigAccumulator from '@/utils/ConfigAccumalator';
+
+import { visibleComponents } from '@/utils/defaults';
+
+/**
+ * Initiates the Accumulator class and generates a complete config object
+ * Self-executing function, returns the full user config as a JSON object
+ */
+export const config = (() => {
+ const Accumulator = new ConfigAccumulator();
+ return Accumulator.config();
+})();
+
+/**
+ * Generates an object containing booleans indicating which
+ * components should be hidden. This enables the user to hide
+ * parts of the page and disable functionality that they don't need/ want
+ * All options fallback on the values defined in the defaults
+ * @param {object} appConfig The full app config
+ * @returns {object} result
+ */
+export const componentVisibility = (appConfig) => {
+ // Get users choice from app config
+ const usersChoice = appConfig.hideComponents || {};
+ // Checks if value is defined, and is a boolean
+ const isThere = (userValue) => typeof userValue === 'boolean';
+ // For each option, return users choice (if specified), else use the default
+ return {
+ pageTitle: isThere(usersChoice.hideHeading)
+ ? !usersChoice.hideHeading : visibleComponents.pageTitle,
+ navigation: isThere(usersChoice.hideNav)
+ ? !usersChoice.hideNav : visibleComponents.navigation,
+ searchBar: isThere(usersChoice.hideSearch)
+ ? !usersChoice.hideSearch : visibleComponents.searchBar,
+ settings: isThere(usersChoice.hideSettings)
+ ? !usersChoice.hideSettings : visibleComponents.settings,
+ footer: isThere(usersChoice.hideFooter)
+ ? !usersChoice.hideFooter : visibleComponents.footer,
+ splashScreen: isThere(usersChoice.hideSplashScreen)
+ ? !usersChoice.hideSplashScreen : visibleComponents.splashScreen,
+ };
+};