Fixed Git integration

This commit is contained in:
2026-06-09 14:18:02 +03:00
parent fb7c4f34b7
commit b976e965f3
6 changed files with 79 additions and 20 deletions
+28 -4
View File
@@ -4,6 +4,7 @@ import {
useCallback,
useContext,
useEffect,
useRef,
useState,
} from "react";
import { api, PomodoroStatus } from "../api/client";
@@ -16,13 +17,22 @@ interface PomodoroContextValue {
const PomodoroContext = createContext<PomodoroContextValue | null>(null);
const POLL_ACTIVE_MS = 1000;
const POLL_IDLE_MS = 30000;
function isTimerActive(status: PomodoroStatus | null): boolean {
return status?.status === "running" || status?.status === "paused";
}
export function PomodoroProvider({ children }: { children: ReactNode }) {
const [status, setStatus] = useState<PomodoroStatus | null>(null);
const [error, setError] = useState<string | null>(null);
const statusRef = useRef<PomodoroStatus | null>(null);
const refresh = useCallback(async () => {
try {
const data = await api.pomodoroStatus();
statusRef.current = data;
setStatus(data);
setError(null);
} catch (err) {
@@ -32,10 +42,24 @@ export function PomodoroProvider({ children }: { children: ReactNode }) {
useEffect(() => {
refresh().catch(console.error);
const timer = setInterval(() => {
refresh().catch(console.error);
}, 1000);
return () => clearInterval(timer);
let cancelled = false;
let timeoutId: ReturnType<typeof setTimeout>;
const schedule = () => {
const delay = isTimerActive(statusRef.current) ? POLL_ACTIVE_MS : POLL_IDLE_MS;
timeoutId = setTimeout(async () => {
if (cancelled) return;
await refresh().catch(console.error);
schedule();
}, delay);
};
schedule();
return () => {
cancelled = true;
clearTimeout(timeoutId);
};
}, [refresh]);
return (
+2 -2
View File
@@ -102,8 +102,8 @@
.message-notice {
align-self: center;
max-width: 90%;
background: #1a2a1f;
border: 1px solid #2d5a3d;
background: #1a2433;
border: 1px solid #2a3f5a;
font-size: 0.92rem;
}
+14 -5
View File
@@ -11,8 +11,15 @@ function shouldShowMessage(msg: ChatMessage): boolean {
return true;
}
function roleLabel(role: string): string {
if (role === "notice") return "таймер";
function noticeLabel(content: string): string {
if (content.startsWith("⏱")) return "таймер";
if (content.startsWith("📋")) return "задачи";
if (content.startsWith("🔀")) return "git";
return "система";
}
function roleLabel(role: string, content = ""): string {
if (role === "notice") return noticeLabel(content);
if (role === "user") return "вы";
return role;
}
@@ -111,7 +118,9 @@ export default function Chat() {
}
if (chunk.event === "notice") {
setLiveNotices((prev) => [...prev, chunk.data.content]);
refreshPomodoro();
if (String(chunk.data.content).startsWith("⏱")) {
refreshPomodoro();
}
}
if (chunk.event === "pomodoro") {
refreshPomodoro();
@@ -166,7 +175,7 @@ export default function Chat() {
<div className="messages">
{visibleMessages.map((msg) => (
<div key={msg.id} className={`message message-${msg.role}`}>
<div className="message-role">{roleLabel(msg.role)}</div>
<div className="message-role">{roleLabel(msg.role, msg.content)}</div>
<div className="message-content">
{msg.role === "assistant" || msg.role === "notice" ? (
<ReactMarkdown>{msg.content}</ReactMarkdown>
@@ -179,7 +188,7 @@ export default function Chat() {
{liveNotices.map((notice, idx) => (
<div key={`notice-${idx}`} className="message message-notice">
<div className="message-role">таймер</div>
<div className="message-role">{noticeLabel(notice)}</div>
<div className="message-content">
<ReactMarkdown>{notice}</ReactMarkdown>
</div>