mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Hold errors in GitSyncProvider
This commit is contained in:
5 files changed
+98
-19
No files matched your search
@@ -3,6 +3,8 @@ import { CloudUpload } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { useGitStatus } from '@/hooks/useGitStatus';
|
||||
import { useGitSyncState } from '@/hooks/useGitSyncState';
|
||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { GitSyncSteps } from './GitSyncSteps';
|
||||
|
||||
@@ -15,9 +17,19 @@ export function GitSyncButton({ projectId, className }: GitSyncButtonProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const { data: gitStatus, isLoading: isGitStatusLoading } = useGitStatus(projectId);
|
||||
const { getError } = useGitSyncState();
|
||||
const { projectsPath } = useFSPaths();
|
||||
|
||||
// Determine which indicator to show (only one at a time)
|
||||
const dir = `${projectsPath}/${projectId}`;
|
||||
const hasError = !!getError(dir);
|
||||
|
||||
// Determine which indicator to show (only one at a time, in priority order)
|
||||
const renderIndicator = () => {
|
||||
// Red indicator: error state - highest priority
|
||||
if (hasError) {
|
||||
return <IndicatorDot color="red" />;
|
||||
}
|
||||
|
||||
if (isGitStatusLoading || !gitStatus) return null;
|
||||
|
||||
const originRemote = gitStatus.remotes.find(r => r.name === 'origin');
|
||||
@@ -25,13 +37,13 @@ export function GitSyncButton({ projectId, className }: GitSyncButtonProps) {
|
||||
|
||||
const { remoteBranchExists, ahead, behind, totalCommits } = gitStatus;
|
||||
|
||||
// Yellow indicator: unsynced changes (ahead or behind remote) - highest priority
|
||||
// Yellow indicator: unsynced changes (ahead or behind remote) - second priority
|
||||
const hasUnsyncedChanges = hasRemote && remoteBranchExists && (ahead > 0 || behind > 0);
|
||||
if (hasUnsyncedChanges) {
|
||||
return <IndicatorDot color="yellow" />;
|
||||
}
|
||||
|
||||
// Purple indicator: no remote configured, but has commits - lower priority
|
||||
// Purple indicator: no remote configured, but has commits - lowest priority
|
||||
const needsRemote = !hasRemote && totalCommits >= 2;
|
||||
if (needsRemote) {
|
||||
return <IndicatorDot color="primary" />;
|
||||
@@ -64,13 +76,14 @@ export function GitSyncButton({ projectId, className }: GitSyncButtonProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function IndicatorDot({ color }: { color: 'primary' | 'yellow' }) {
|
||||
function IndicatorDot({ color }: { color: 'primary' | 'yellow' | 'red' }) {
|
||||
return (
|
||||
<span className={cn(
|
||||
"absolute top-1 right-1 h-2 w-2 rounded-full",
|
||||
{
|
||||
'bg-primary': color === 'primary',
|
||||
'bg-yellow-500': color === 'yellow',
|
||||
'bg-red-500': color === 'red',
|
||||
},
|
||||
)} />
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user