diff --git a/frontend/src/components/SettingsBar.tsx b/frontend/src/components/SettingsBar.tsx new file mode 100644 index 000000000..2b7c2a33c --- /dev/null +++ b/frontend/src/components/SettingsBar.tsx @@ -0,0 +1,96 @@ +import React, { useCallback, useRef, useState } from 'react'; +import ArrowLeft from '../assets/arrow-left.svg'; +import ArrowRight from '../assets/arrow-right.svg'; +import { useTranslation } from 'react-i18next'; + +type HiddenGradientType = 'left' | 'right' | undefined; + +const useTabs = () => { + const { t } = useTranslation(); + const tabs = [ + t('settings.general.label'), + t('settings.documents.label'), + t('settings.apiKeys.label'), + t('settings.analytics.label'), + t('settings.logs.label'), + ]; + return tabs; +}; + +interface SettingsBarProps { + setActiveTab: React.Dispatch>; + activeTab: string; +} + +const SettingsBar = ({ setActiveTab, activeTab }: SettingsBarProps) => { + const [hiddenGradient, setHiddenGradient] = + useState('left'); + const containerRef = useRef(null); + const tabs = useTabs(); + const scrollTabs = useCallback( + (direction: number) => { + if (containerRef.current) { + const container = containerRef.current; + container.scrollLeft += direction * 100; // Adjust the scroll amount as needed + if (container.scrollLeft === 0) { + setHiddenGradient('left'); + } else if ( + container.scrollLeft + container.offsetWidth === + container.scrollWidth + ) { + setHiddenGradient('right'); + } else { + setHiddenGradient(undefined); + } + } + }, + [containerRef.current], + ); + return ( +
+
+
+ +
+ +
+
+ {tabs.map((tab, index) => ( + + ))} +
+
+ +
+
+ ); +}; + +export default SettingsBar; diff --git a/frontend/src/settings/index.tsx b/frontend/src/settings/index.tsx index ef5434aa6..ea3d44281 100644 --- a/frontend/src/settings/index.tsx +++ b/frontend/src/settings/index.tsx @@ -3,8 +3,7 @@ import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import userService from '../api/services/userService'; -import ArrowLeft from '../assets/arrow-left.svg'; -import ArrowRight from '../assets/arrow-right.svg'; +import SettingsBar from '../components/SettingsBar'; import i18n from '../locale/i18n'; import { Doc } from '../models/misc'; import { @@ -21,13 +20,6 @@ import Widgets from './Widgets'; export default function Settings() { const dispatch = useDispatch(); const { t } = useTranslation(); - const tabs = [ - t('settings.general.label'), - t('settings.documents.label'), - t('settings.apiKeys.label'), - t('settings.analytics.label'), - t('settings.logs.label'), - ]; const [activeTab, setActiveTab] = React.useState(t('settings.general.label')); const [widgetScreenshot, setWidgetScreenshot] = React.useState( null, @@ -61,39 +53,7 @@ export default function Settings() {

{t('settings.label')}

-
-
- -
-
- {tabs.map((tab, index) => ( - - ))} -
-
- -
-
+ {renderActiveTab()} {/* {activeTab === 'Widgets' && ( @@ -105,13 +65,6 @@ export default function Settings() { ); - function scrollTabs(direction: number) { - const container = document.querySelector('.flex-nowrap'); - if (container) { - container.scrollLeft += direction * 100; // Adjust the scroll amount as needed - } - } - function renderActiveTab() { switch (activeTab) { case t('settings.general.label'):