From 1deea4c67124effc30f5ff7fb712f14057481be8 Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Mon, 27 Apr 2026 16:39:43 +0800 Subject: [PATCH] fix(frontend): resolve TypeScript type errors in repository pages - commits.tsx: fix Unix timestamp (time_secs) not multiplied by 1000 - RoomMessageSearch.tsx: add explicit generic type for resp.data - RoomPinPanel.tsx: make sender_id optional (string | null) - message-list.tsx: remove unused index variable in map - repository-context.tsx: use correct RepoInfo field names - use-audio-recording.ts: use audioStream state instead of undefined var - universal-ws.ts: rename unused id to _id --- src/app/repository/commits.tsx | 4 ++-- src/components/room/RoomMessageSearch.tsx | 4 ++-- src/components/room/RoomPinPanel.tsx | 2 +- src/components/ui/message-list.tsx | 2 +- src/contexts/repository-context.tsx | 7 ++++--- src/hooks/use-audio-recording.ts | 4 ++-- src/lib/universal-ws.ts | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/app/repository/commits.tsx b/src/app/repository/commits.tsx index a3b5dc6..6afc7e6 100644 --- a/src/app/repository/commits.tsx +++ b/src/app/repository/commits.tsx @@ -350,9 +350,9 @@ export const RepoCommits = () => { {commit.author?.name || "Unknown"} - + - {getRelativeTime(commit.committer?.time_secs)} + {getRelativeTime(commit.committer?.time_secs ? new Date(commit.committer.time_secs * 1000).toISOString() : null)} diff --git a/src/components/room/RoomMessageSearch.tsx b/src/components/room/RoomMessageSearch.tsx index 7451398..825ee0f 100644 --- a/src/components/room/RoomMessageSearch.tsx +++ b/src/components/room/RoomMessageSearch.tsx @@ -37,11 +37,11 @@ export function RoomMessageSearch({ roomId, onSelectMessage, onClose }: RoomMess setIsSearching(true); try { - const resp = await client.get({ + const resp = await client.get({ url: `/api/rooms/${roomId}/messages/search`, params: { q: searchQuery, limit: 20, offset: searchOffset }, }); - const data = resp.data?.data as SearchResult | undefined; + const data = resp.data; if (data) { setResults(data); setOffset(searchOffset); diff --git a/src/components/room/RoomPinPanel.tsx b/src/components/room/RoomPinPanel.tsx index 0aa88cd..5fe20d1 100644 --- a/src/components/room/RoomPinPanel.tsx +++ b/src/components/room/RoomPinPanel.tsx @@ -58,7 +58,7 @@ interface RoomPinPanelProps { messages: Array<{ id: string; content: string; - sender_id: string; + sender_id?: string | null; sender_type: string; send_at: string; }>; diff --git a/src/components/ui/message-list.tsx b/src/components/ui/message-list.tsx index 7f07542..933c758 100644 --- a/src/components/ui/message-list.tsx +++ b/src/components/ui/message-list.tsx @@ -24,7 +24,7 @@ export function MessageList({ }: MessageListProps) { return (
- {messages.map((message, index) => { + {messages.map((message) => { const additionalOptions = typeof messageOptions === "function" ? messageOptions(message) diff --git a/src/contexts/repository-context.tsx b/src/contexts/repository-context.tsx index bcd74d2..1898f71 100644 --- a/src/contexts/repository-context.tsx +++ b/src/contexts/repository-context.tsx @@ -111,9 +111,10 @@ export const RepositoryContextProvider = ({ // Return a minimal placeholder during loading to avoid unmounting // the entire subtree (which causes state loss and flash). const fallbackRepo: RepoInfo = { - id: '', name: '', namespace: '', display_name: '', - description: '', is_private: false, default_branch: '', - fork_count: 0, star_count: 0, watch_count: 0, + namespace: '', repo_name: '', uid: '', + description: null, is_private: false, default_branch: '', + commit_count: 0, branch_count: 0, tag_count: 0, + star_count: 0, watch_count: 0, last_commit_at: new Date().toISOString(), is_star: false, is_watch: false, ssh_clone_url: '', https_clone_url: '', ai_code_review_enabled: false, diff --git a/src/hooks/use-audio-recording.ts b/src/hooks/use-audio-recording.ts index d5458c5..f9ad7a8 100644 --- a/src/hooks/use-audio-recording.ts +++ b/src/hooks/use-audio-recording.ts @@ -77,8 +77,8 @@ export function useAudioRecording({ console.error("Error recording audio:", error) setIsListening(false) setIsRecording(false) - if (stream) { - stream.getTracks().forEach((track) => track.stop()) + if (audioStream) { + audioStream.getTracks().forEach((track: MediaStreamTrack) => track.stop()) } setAudioStream(null) } diff --git a/src/lib/universal-ws.ts b/src/lib/universal-ws.ts index 6ad86c8..e12156c 100644 --- a/src/lib/universal-ws.ts +++ b/src/lib/universal-ws.ts @@ -89,7 +89,7 @@ export class UniversalWsClient { // Reject all pending requests const pending = [...this.pendingRequests.entries()]; this.pendingRequests.clear(); - for (const [id, req] of pending) { + for (const [_id, req] of pending) { clearTimeout(req.timeout); req.reject(new Error(`WebSocket closed: ${ev.reason || 'unknown'}`)); }