import * as Uebersicht from "uebersicht"; import * as Utils from "../../utils"; import SettingsInner from "./settings-inner.jsx"; import SettingsWidgets from "./settings-widgets.jsx"; import * as Settings from "../../settings"; const { React } = Uebersicht; const TABS_STORAGE_KEY = "simple-bar-last-current-settings-tab"; const TABS = [ "global", "themes", "process", "spacesDisplay", "widgets", "customStyles", ]; /** * Main settings component. * @param {Object} props - Component properties. * @param {Function} props.closeSettings - Function to close the settings. */ export default function Component({ closeSettings }) { // State to keep track of the current tab const [currentTab, setCurrentTab] = React.useState(getLastCurrentTab()); // State to keep track of pending changes const [pendingChanges, setPendingChanges] = React.useState(0); // Get current settings const settings = Settings.get(); // State to keep track of new settings const [newSettings, setNewSettings] = React.useState(settings); /** * Update the current tab and store it in session storage. * @param {number} tab - The index of the tab to switch to. */ const updateTab = (tab) => { setCurrentTab(tab); window.sessionStorage.setItem(TABS_STORAGE_KEY, tab); }; /** * Refresh the simple-bar with new settings. * @param {Event} e - The event object. */ const refreshSimpleBar = async (e) => { Utils.clickEffect(e); setPendingChanges(0); await Settings.set(newSettings); Utils.hardRefresh(); }; // Effect to calculate the number of pending changes React.useEffect(() => { const diffs = Utils.compareObjects(settings, newSettings); const deepDiffs = Object.keys(diffs).reduce( (acc, key) => [...acc, ...Object.keys(diffs[key])], [], ); setPendingChanges(deepDiffs.length); }, [newSettings, settings]); return (