From 9faf46a3ea0363084766b689a58ec9b30daccb6e Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Wed, 18 Sep 2024 14:33:12 +0930 Subject: [PATCH] feat: add tab navigation to settings page --- .../src/components/settings/SettingsPage.jsx | 196 +++++++----------- 1 file changed, 76 insertions(+), 120 deletions(-) diff --git a/frontend/src/components/settings/SettingsPage.jsx b/frontend/src/components/settings/SettingsPage.jsx index 2ed1241..b187285 100644 --- a/frontend/src/components/settings/SettingsPage.jsx +++ b/frontend/src/components/settings/SettingsPage.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { getSettings, getGitStatus, @@ -27,6 +27,8 @@ const SettingsPage = () => { const [statusLoading, setStatusLoading] = useState(true); const [statusLoadingMessage, setStatusLoadingMessage] = useState(''); const [noChangesMessage, setNoChangesMessage] = useState(''); + const [activeTab, setActiveTab] = useState('git'); // New state for tab navigation + const tabsRef = useRef({}); // Ref for tabs useEffect(() => { fetchSettings(); @@ -80,137 +82,91 @@ const SettingsPage = () => { } }; - const handleStageSelectedChanges = async (selectedChanges) => { - setLoadingAction('stage_selected'); - try { - const response = await addFiles(selectedChanges); - if (response.success) { - await fetchGitStatus(); - Alert.success(response.message); - } else { - Alert.error(response.error); - } - } catch (error) { - Alert.error('An unexpected error occurred while staging changes.'); - console.error('Error staging changes:', error); - } finally { - setLoadingAction(''); - } - }; - - const handleCommitSelectedChanges = async (selectedChanges, commitMessage) => { - setLoadingAction('commit_selected'); - try { - const response = await pushFiles(selectedChanges, commitMessage); - if (response.success) { - await fetchGitStatus(); - Alert.success(response.message); - } else { - Alert.error(response.error); - } - } catch (error) { - Alert.error('An unexpected error occurred while committing changes.'); - console.error('Error committing changes:', error); - } finally { - setLoadingAction(''); - } - }; - - const handleRevertSelectedChanges = async (selectedChanges) => { - setLoadingAction('revert_selected'); - try { - const response = await Promise.all(selectedChanges.map(filePath => revertFile(filePath))); - const allSuccessful = response.every(res => res.success); - if (allSuccessful) { - await fetchGitStatus(); - Alert.success('Selected changes have been reverted successfully.'); - } else { - Alert.error('Some changes could not be reverted. Please try again.'); - } - } catch (error) { - Alert.error('An unexpected error occurred while reverting changes.'); - console.error('Error reverting changes:', error); - } finally { - setLoadingAction(''); - } - }; - - const handlePullSelectedChanges = async (selectedChanges) => { - setLoadingAction('pull_changes'); - try { - const response = await pullBranch(changes.branch, selectedChanges); - if (response.success) { - await fetchGitStatus(); - Alert.success(response.message); - } else { - Alert.error(response.error); - } - } catch (error) { - Alert.error('An unexpected error occurred while pulling changes.'); - console.error('Error pulling changes:', error); - } finally { - setLoadingAction(''); - } + const handleTabChange = (tab) => { + setActiveTab(tab); }; return (
-

- Git Settings - - {isDevMode ? 'Dev Mode: Enabled' : 'Dev Mode: Disabled'} - -

+ - + {activeTab === 'git' && ( + <> - {settings && ( -
- {statusLoading ? ( -
- - {statusLoadingMessage} -
- ) : changes && (changes.incoming_changes.length > 0 || changes.outgoing_changes.length > 0) ? ( - setShowBranchModal(true)} - onStageSelected={handleStageSelectedChanges} - onCommitSelected={handleCommitSelectedChanges} - onRevertSelected={handleRevertSelectedChanges} - onPullSelected={handlePullSelectedChanges} - loadingAction={loadingAction} - /> - ) : ( -
- {noChangesMessage} + + + {settings && ( +
+ {statusLoading ? ( +
+ + {statusLoadingMessage} +
+ ) : changes && (changes.incoming_changes.length > 0 || changes.outgoing_changes.length > 0) ? ( + setShowBranchModal(true)} + onStageSelected={handleStageSelectedChanges} + onCommitSelected={handleCommitSelectedChanges} + onRevertSelected={handleRevertSelectedChanges} + onPullSelected={handlePullSelectedChanges} + loadingAction={loadingAction} + /> + ) : ( +
+ {noChangesMessage} +
+ )}
)} -
+ + {settings && changes && ( + setShowBranchModal(false)} + repoUrl={settings.gitRepo} + currentBranch={changes.branch} + onBranchChange={fetchGitStatus} + isDevMode={isDevMode} + /> + )} + )} -

- Arr Management -

- - - {settings && changes && ( - setShowBranchModal(false)} - repoUrl={settings.gitRepo} - currentBranch={changes.branch} - onBranchChange={fetchGitStatus} - isDevMode={isDevMode} - /> + {activeTab === 'app' && ( + <> +

+ App Settings +

+ + )}
); }; -export default SettingsPage; \ No newline at end of file +export default SettingsPage;