From e970262ba01628278754e756237472fa3ff53d48 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Thu, 9 Jan 2025 20:09:49 +1030 Subject: [PATCH] chore: remove old file --- .../settings/git/status/GitContainer.jsx | 408 ------------------ 1 file changed, 408 deletions(-) delete mode 100644 frontend/src/components/settings/git/status/GitContainer.jsx diff --git a/frontend/src/components/settings/git/status/GitContainer.jsx b/frontend/src/components/settings/git/status/GitContainer.jsx deleted file mode 100644 index cc10e4e..0000000 --- a/frontend/src/components/settings/git/status/GitContainer.jsx +++ /dev/null @@ -1,408 +0,0 @@ -import React, {useState, useEffect} from 'react'; -import { - Loader, - Unlink, - Link, - Eye, - GitBranch, - GitCommit, - Star, - CircleDot, - GitFork, - Info -} from 'lucide-react'; -import GithubIcon from '@logo/GitHub.svg'; -import Tooltip from '@ui/Tooltip'; -import {unlinkRepo, getSettings} from '@api/api'; -import Alert from '@ui/Alert'; -import LinkRepo from '../repo/LinkRepo'; -import UnlinkRepo from '../repo/UnlinkRepo'; -import ViewBranches from '../repo/ViewBranches'; -import ViewCommits from '../repo/ViewCommits'; - -const RepoContainer = ({settings, setSettings, fetchGitStatus, status}) => { - const [loadingAction, setLoadingAction] = useState(''); - const [showLinkModal, setShowLinkModal] = useState(false); - const [showUnlinkRepo, setShowUnlinkRepo] = useState(false); - const [showBranchModal, setShowBranchModal] = useState(false); - const [showCommitModal, setShowCommitModal] = useState(false); - const [avatarUrl, setAvatarUrl] = useState(null); - const [repoStats, setRepoStats] = useState(null); - - const getRepoFullName = url => { - if (!url) return ''; - const parts = url.split('/'); - const repo = parts[parts.length - 1].replace('.git', ''); - const org = parts[parts.length - 2]; - - // Special case for Dictionarry-Hub - if (org === 'Dictionarry-Hub') { - return 'Dictionarry / Database'; - } - return `${org}/${repo}`; - }; - - const getFirstLetter = url => { - if (!url) return ''; - const parts = url.split('/'); - return parts[parts.length - 1].charAt(0).toUpperCase(); - }; - - const getAvatarColor = repoName => { - const colors = [ - 'bg-blue-600', - 'bg-purple-600', - 'bg-green-600', - 'bg-red-600', - 'bg-indigo-600' - ]; - const index = repoName - .split('') - .reduce((acc, char) => acc + char.charCodeAt(0), 0); - return colors[index % colors.length]; - }; - - useEffect(() => { - const fetchAvatarAndStats = async () => { - if (!settings?.gitRepo) return; - - // Get the raw owner/repo for API calls - const parts = settings.gitRepo.split('/'); - const owner = parts[parts.length - 2]; - const repo = parts[parts.length - 1].replace('.git', ''); - - const avatarCacheKey = `github-avatar-${owner}`; - const statsCacheKey = `github-stats-${repoFullName}`; - - const cachedAvatar = localStorage.getItem(avatarCacheKey); - const cachedStats = localStorage.getItem(statsCacheKey); - const avatarTimestamp = localStorage.getItem( - `${avatarCacheKey}-timestamp` - ); - const statsTimestamp = localStorage.getItem( - `${statsCacheKey}-timestamp` - ); - - const isAvatarValid = - avatarTimestamp && - Date.now() - parseInt(avatarTimestamp) < 24 * 60 * 60 * 1000; - const isStatsValid = - statsTimestamp && - Date.now() - parseInt(statsTimestamp) < 1 * 60 * 60 * 1000; // 1 hour for stats - - if (cachedAvatar && isAvatarValid) { - setAvatarUrl(cachedAvatar); - } - - if (cachedStats && isStatsValid) { - setRepoStats(JSON.parse(cachedStats)); - } - - try { - const [avatarResponse, repoResponse] = await Promise.all([ - !isAvatarValid && - fetch(`https://api.github.com/users/${owner}`), - !isStatsValid && - fetch(`https://api.github.com/repos/${owner}/${repo}`) - ]); - - if (!isAvatarValid && avatarResponse.ok) { - const userData = await avatarResponse.json(); - localStorage.setItem(avatarCacheKey, userData.avatar_url); - localStorage.setItem( - `${avatarCacheKey}-timestamp`, - Date.now().toString() - ); - setAvatarUrl(userData.avatar_url); - } - - if (!isStatsValid && repoResponse.ok) { - const repoData = await repoResponse.json(); - const stats = { - stars: repoData.stargazers_count, - forks: repoData.forks_count, - issues: repoData.open_issues_count - }; - localStorage.setItem(statsCacheKey, JSON.stringify(stats)); - localStorage.setItem( - `${statsCacheKey}-timestamp`, - Date.now().toString() - ); - setRepoStats(stats); - } - } catch (error) { - console.error('Error fetching GitHub data:', error); - // Use cached data if available, regardless of age - if (cachedAvatar && !isAvatarValid) setAvatarUrl(cachedAvatar); - if (cachedStats && !isStatsValid) - setRepoStats(JSON.parse(cachedStats)); - } - }; - - fetchAvatarAndStats(); - }, [settings?.gitRepo]); - - const handleLinkRepo = () => { - setLoadingAction('link_repo'); - setShowLinkModal(true); - }; - - const handleUnlinkRepo = async removeFiles => { - setLoadingAction('unlink_repo'); - try { - const response = await unlinkRepo(removeFiles); - if (response.success) { - setSettings(null); - Alert.success('Repository unlinked successfully'); - setShowUnlinkRepo(false); - } else { - Alert.error(response.error || 'Failed to unlink repository'); - } - } catch (error) { - Alert.error( - 'An unexpected error occurred while unlinking the repository' - ); - console.error('Error unlinking repository:', error); - } finally { - setLoadingAction(''); - } - }; - - const onLinkSubmit = async () => { - try { - const fetchedSettings = await getSettings(); - setSettings(fetchedSettings); - if (fetchedSettings) { - await fetchGitStatus(); - } - } catch (error) { - console.error('Error fetching settings:', error); - Alert.error('Failed to update repository settings'); - } finally { - setLoadingAction(''); - setShowLinkModal(false); - } - }; - - const repoFullName = settings ? getRepoFullName(settings.gitRepo) : ''; - - return ( -
-
-
-
-
- {!settings ? ( -
- GitHub -
-

- No Repository Connected -

-

- Profilarr leverages Git to create an - open-source configuration sharing - system. Connect to the{' '} - - Dictionarry Database - {' '} - or any external database to get - started. -

-
-
- ) : avatarUrl ? ( - {`${repoFullName} { - e.target.style.display = 'none'; - e.target.nextElementSibling.style.display = - 'flex'; - }} - /> - ) : ( -
- {getFirstLetter(settings.gitRepo)} -
- )} - {settings && ( -
- - {repoFullName} - -
- {repoStats ? ( - <> -
- - - {repoStats.stars} - -
-
- - - {repoStats.issues} - -
-
- - - {repoStats.forks} - -
- - ) : ( - - )} -
-
- )} -
-
- {settings && ( - <> - - {status && status.local_commits && ( -
- - - { - status.local_commits - .length - } - {' '} - local commits - -
- )} - - - )} - - - -
-
-
-
- - { - setShowLinkModal(false); - setLoadingAction(''); - }} - onSubmit={onLinkSubmit} - /> - setShowUnlinkRepo(false)} - onSubmit={handleUnlinkRepo} - /> - {settings && status && ( - <> - setShowBranchModal(false)} - repoUrl={settings.gitRepo} - currentBranch={status.branch} - onBranchChange={fetchGitStatus} - /> - setShowCommitModal(false)} - repoUrl={settings.gitRepo} - currentBranch={status.branch} - localCommits={status.local_commits || []} - remoteCommits={status.remote_commits || []} - outgoingChanges={status.outgoing_changes || []} - incomingChanges={status.incoming_changes || []} - /> - - )} -
- ); -}; - -export default RepoContainer;