From c1f90b3c3789c035e8efc5e4fd16356f6262ec7c Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Thu, 19 Sep 2024 08:44:42 +0930 Subject: [PATCH] refactor: move branch functionality into repo container. Add some icons --- .../src/components/settings/SettingsPage.jsx | 106 +++++++++++------- .../components/settings/git/RepoContainer.jsx | 103 ++++++++++++++--- .../settings/git/StatusContainer.jsx | 18 +-- 3 files changed, 159 insertions(+), 68 deletions(-) diff --git a/frontend/src/components/settings/SettingsPage.jsx b/frontend/src/components/settings/SettingsPage.jsx index 670e06a..b43c396 100644 --- a/frontend/src/components/settings/SettingsPage.jsx +++ b/frontend/src/components/settings/SettingsPage.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, {useState, useEffect, useRef} from 'react'; import { getSettings, getGitStatus, @@ -8,15 +8,17 @@ import { pullBranch, checkDevMode } from '../../api/api'; -import { - Loader, -} from 'lucide-react'; +import {Loader} from 'lucide-react'; import ViewBranches from './git/modal/ViewBranches'; import Alert from '../ui/Alert'; import ArrContainer from './arrs/ArrContainer'; import RepoContainer from './git/RepoContainer'; import StatusContainer from './git/StatusContainer'; -import { statusLoadingMessages, noChangesMessages, getRandomMessage } from '../../utils/messages'; +import { + statusLoadingMessages, + noChangesMessages, + getRandomMessage +} from '../../utils/messages'; const SettingsPage = () => { const [settings, setSettings] = useState(null); @@ -27,8 +29,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 + const [activeTab, setActiveTab] = useState('git'); // New state for tab navigation + const tabsRef = useRef({}); // Ref for tabs useEffect(() => { fetchSettings(); @@ -66,10 +68,14 @@ const SettingsPage = () => { if (result.success) { setChanges({ ...result.data, - outgoing_changes: Array.isArray(result.data.outgoing_changes) + outgoing_changes: Array.isArray( + result.data.outgoing_changes + ) ? result.data.outgoing_changes : [], - incoming_changes: Array.isArray(result.data.incoming_changes) + incoming_changes: Array.isArray( + result.data.incoming_changes + ) ? result.data.incoming_changes : [] }); @@ -82,11 +88,11 @@ const SettingsPage = () => { } }; - const handleTabChange = (tab) => { + const handleTabChange = tab => { setActiveTab(tab); }; - const handleStageSelectedChanges = async (selectedChanges) => { + const handleStageSelectedChanges = async selectedChanges => { setLoadingAction('stage_selected'); try { const response = await addFiles(selectedChanges); @@ -104,7 +110,10 @@ const SettingsPage = () => { } }; - const handleCommitSelectedChanges = async (selectedChanges, commitMessage) => { + const handleCommitSelectedChanges = async ( + selectedChanges, + commitMessage + ) => { setLoadingAction('commit_selected'); try { const response = await pushFiles(selectedChanges, commitMessage); @@ -115,33 +124,43 @@ const SettingsPage = () => { Alert.error(response.error); } } catch (error) { - Alert.error('An unexpected error occurred while committing changes.'); + Alert.error( + 'An unexpected error occurred while committing changes.' + ); console.error('Error committing changes:', error); } finally { setLoadingAction(''); } }; - const handleRevertSelectedChanges = async (selectedChanges) => { + const handleRevertSelectedChanges = async selectedChanges => { setLoadingAction('revert_selected'); try { - const response = await Promise.all(selectedChanges.map(filePath => revertFile(filePath))); + 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.'); + Alert.success( + 'Selected changes have been reverted successfully.' + ); } else { - Alert.error('Some changes could not be reverted. Please try again.'); + Alert.error( + 'Some changes could not be reverted. Please try again.' + ); } } catch (error) { - Alert.error('An unexpected error occurred while reverting changes.'); + Alert.error( + 'An unexpected error occurred while reverting changes.' + ); console.error('Error reverting changes:', error); } finally { setLoadingAction(''); } }; - const handlePullSelectedChanges = async (selectedChanges) => { + const handlePullSelectedChanges = async selectedChanges => { setLoadingAction('pull_changes'); try { const response = await pullBranch(changes.branch, selectedChanges); @@ -161,51 +180,62 @@ const SettingsPage = () => { return (
-