mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add MiniScanner component and git service tests
- Extract session busy indicator to reusable MiniScanner component - Refactor SessionCard to use MiniScanner for cleaner code - Add comprehensive tests for GitBranchService, GitDiffService - Add repo-git route tests
This commit is contained in:
1 parent
7f30a28be9
commit
570a67e7b0
5 files changed
+1259
-9
No files matched your search
@@ -1,9 +1,9 @@
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { MiniScanner } from "@/components/ui/mini-scanner";
|
||||
import { Trash2, Clock } from "lucide-react";
|
||||
import { formatDistanceToNow } from "date-fns";
|
||||
import type { Session } from "@/api/types";
|
||||
import { useSessionStatusForSession } from "@/stores/sessionStatusStore";
|
||||
|
||||
interface SessionCardProps {
|
||||
session: Session;
|
||||
@@ -22,8 +22,6 @@ export const SessionCard = ({
|
||||
onToggleSelection,
|
||||
onDelete,
|
||||
}: SessionCardProps) => {
|
||||
const sessionStatus = useSessionStatusForSession(session.id);
|
||||
const isSessionBusy = sessionStatus.type === 'busy' || sessionStatus.type === 'retry' || sessionStatus.type === 'compact';
|
||||
|
||||
return (
|
||||
<Card
|
||||
@@ -49,12 +47,7 @@ export const SessionCard = ({
|
||||
}}
|
||||
className="w-5 h-5 flex-shrink-0"
|
||||
/>
|
||||
{isSessionBusy && (
|
||||
<span className="relative flex h-2.5 w-2.5 flex-shrink-0">
|
||||
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"></span>
|
||||
<span className="relative inline-flex rounded-full h-2.5 w-2.5 bg-green-500"></span>
|
||||
</span>
|
||||
)}
|
||||
<MiniScanner sessionID={session.id} />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { memo, useEffect, useState } from 'react'
|
||||
import { useSessionStatusForSession, type SessionStatusType } from '@/stores/sessionStatusStore'
|
||||
|
||||
interface MiniScannerProps {
|
||||
sessionID: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
const SCANNER_WIDTH = 6
|
||||
const SCANNER_SEGMENTS = 12
|
||||
|
||||
export const MiniScanner = memo(function MiniScanner({
|
||||
sessionID,
|
||||
className = ''
|
||||
}: MiniScannerProps) {
|
||||
const status = useSessionStatusForSession(sessionID)
|
||||
const [position, setPosition] = useState(0)
|
||||
const [direction, setDirection] = useState(1)
|
||||
|
||||
useEffect(() => {
|
||||
if (status.type !== 'busy' && status.type !== 'retry' && status.type !== 'compact') {
|
||||
return
|
||||
}
|
||||
|
||||
const interval = setInterval(() => {
|
||||
setPosition(prev => {
|
||||
const next = prev + direction
|
||||
if (next >= SCANNER_SEGMENTS - SCANNER_WIDTH) {
|
||||
setDirection(-1)
|
||||
return SCANNER_SEGMENTS - SCANNER_WIDTH
|
||||
}
|
||||
if (next <= 0) {
|
||||
setDirection(1)
|
||||
return 0
|
||||
}
|
||||
return next
|
||||
})
|
||||
}, 60)
|
||||
|
||||
return () => clearInterval(interval)
|
||||
}, [status.type, direction])
|
||||
|
||||
const getSegmentColor = (index: number, statusType: SessionStatusType['type']) => {
|
||||
if (statusType === 'idle') {
|
||||
return 'bg-transparent'
|
||||
}
|
||||
|
||||
const distance = Math.abs(index - (position + SCANNER_WIDTH / 2))
|
||||
const maxDistance = SCANNER_WIDTH / 2
|
||||
|
||||
if (distance > maxDistance + 1) {
|
||||
return 'bg-muted/20'
|
||||
}
|
||||
|
||||
const intensity = Math.max(0, 1 - distance / (maxDistance + 2))
|
||||
|
||||
if (statusType === 'retry') {
|
||||
if (intensity > 0.8) return 'bg-amber-500'
|
||||
if (intensity > 0.5) return 'bg-amber-500/70'
|
||||
if (intensity > 0.2) return 'bg-amber-500/40'
|
||||
return 'bg-amber-500/20'
|
||||
}
|
||||
|
||||
if (statusType === 'compact') {
|
||||
if (intensity > 0.8) return 'bg-purple-500'
|
||||
if (intensity > 0.5) return 'bg-purple-500/70'
|
||||
if (intensity > 0.2) return 'bg-purple-500/40'
|
||||
return 'bg-purple-500/20'
|
||||
}
|
||||
|
||||
if (intensity > 0.8) return 'bg-blue-500'
|
||||
if (intensity > 0.5) return 'bg-blue-500/70'
|
||||
if (intensity > 0.2) return 'bg-blue-500/40'
|
||||
return 'bg-blue-500/20'
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`flex items-center ${className}`}>
|
||||
<div className="flex gap-0.5">
|
||||
{Array.from({ length: SCANNER_SEGMENTS }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={`w-0.5 h-2 rounded-sm transition-colors duration-75 ${getSegmentColor(i, status.type)}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
Reference in new issue
Block a user