Skip to content

Commit 89596f4

Browse files
committed
Refactoring
1 parent 59fac6e commit 89596f4

File tree

9 files changed

+32
-29
lines changed

9 files changed

+32
-29
lines changed

packages/shared/src/tasks/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export interface TaskActionParams {
4646
const deleteTask = defineRequest<TaskActionParams, void>("deleteTask");
4747
const pauseTask = defineRequest<TaskActionParams, void>("pauseTask");
4848
const resumeTask = defineRequest<TaskActionParams, void>("resumeTask");
49+
const downloadLogs = defineRequest<{ taskId: string }, void>("downloadLogs");
4950

5051
const viewInCoder = defineCommand<{ taskId: string }>("viewInCoder");
5152
const viewLogs = defineCommand<{ taskId: string }>("viewLogs");
52-
const downloadLogs = defineRequest<{ taskId: string }, void>("downloadLogs");
5353
const sendTaskMessage = defineCommand<{
5454
taskId: string;
5555
message: string;

packages/tasks/src/components/ActionMenu.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
VscodeIcon,
55
VscodeProgressRing,
66
} from "@vscode-elements/react-elements";
7-
import { useState, useRef, useEffect, useCallback } from "react";
7+
import { useState, useRef, useEffect } from "react";
88

99
interface ActionMenuAction {
1010
separator?: false;
@@ -33,8 +33,6 @@ export function ActionMenu({ items }: ActionMenuProps) {
3333
} | null>(null);
3434
const menuRef = useRef<HTMLDivElement>(null);
3535
const buttonRef = useRef<HTMLDivElement>(null);
36-
const dropdownRef = useRef<HTMLDivElement>(null);
37-
3836
function toggle() {
3937
setPosition((prev) => {
4038
if (prev) {
@@ -50,11 +48,6 @@ export function ActionMenu({ items }: ActionMenuProps) {
5048

5149
const isOpen = position !== null;
5250

53-
const dropdownRefCallback = useCallback((node: HTMLDivElement | null) => {
54-
dropdownRef.current = node;
55-
node?.focus();
56-
}, []);
57-
5851
function onKeyDown(event: React.KeyboardEvent) {
5952
if (event.key === "Escape") {
6053
setPosition(null);
@@ -93,7 +86,7 @@ export function ActionMenu({ items }: ActionMenuProps) {
9386
</div>
9487
{position && (
9588
<div
96-
ref={dropdownRefCallback}
89+
ref={(node) => node?.focus()}
9790
className="action-menu-dropdown"
9891
style={position}
9992
tabIndex={-1}

packages/tasks/src/components/TaskItem.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { getTaskLabel, type Task } from "@repo/shared";
22
import { VscodeProgressRing } from "@vscode-elements/react-elements";
33

4+
import { getActionLabel } from "../utils/taskAction";
5+
46
import { ActionMenu } from "./ActionMenu";
57
import { StatusIndicator } from "./StatusIndicator";
6-
import { useTaskMenuItems, type TaskAction } from "./useTaskMenuItems";
7-
8-
const actionLabels: Record<NonNullable<TaskAction>, string> = {
9-
pausing: "Pausing...",
10-
resuming: "Resuming...",
11-
deleting: "Deleting...",
12-
downloading: "Downloading...",
13-
};
8+
import { useTaskMenuItems } from "./useTaskMenuItems";
149

1510
interface TaskItemProps {
1611
task: Task;
@@ -50,7 +45,7 @@ export function TaskItem({ task, onSelect }: TaskItemProps) {
5045
<span className="task-title" title={displayName}>
5146
{displayName}
5247
{action && (
53-
<span className="task-action-label">{actionLabels[action]}</span>
48+
<span className="task-action-label">{getActionLabel(action)}</span>
5449
)}
5550
</span>
5651
<span className="task-subtitle" title={subtitle}>

packages/tasks/src/components/useTaskMenuItems.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@ import { logger } from "@repo/webview-shared/logger";
33
import { useMutation } from "@tanstack/react-query";
44

55
import { useTasksApi } from "../hooks/useTasksApi";
6+
import { type TaskAction } from "../utils/taskAction";
67

78
import type { ActionMenuItem } from "./ActionMenu";
89

9-
export type TaskAction =
10-
| "pausing"
11-
| "resuming"
12-
| "deleting"
13-
| "downloading"
14-
| null;
15-
1610
interface ActionRequest {
1711
action: NonNullable<TaskAction>;
1812
fn: () => Promise<void>;

packages/tasks/src/hooks/useTasksData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { useIpc } from "@repo/webview-shared/react";
1010
import { useQuery, useQueryClient } from "@tanstack/react-query";
1111
import { useEffect, useRef, useState } from "react";
1212

13-
import { TASK_LIST_POLL_INTERVAL_MS } from "../config";
14-
import { taskArraysEqual, templateArraysEqual } from "../utils";
13+
import { taskArraysEqual, templateArraysEqual } from "../utils/compare";
14+
import { TASK_LIST_POLL_INTERVAL_MS } from "../utils/config";
1515

1616
import { useTasksApi } from "./useTasksApi";
1717

packages/tasks/src/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ vscode-collapsible::part(body) {
219219
display: inline-flex;
220220
align-items: center;
221221
gap: 4px;
222+
background: none;
223+
border: none;
224+
padding: 0;
225+
font: inherit;
226+
cursor: pointer;
222227
text-decoration: none;
223228
}
224229

packages/tasks/src/utils/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export type TaskAction =
2+
| "pausing"
3+
| "resuming"
4+
| "deleting"
5+
| "downloading"
6+
| null;
7+
8+
const ACTION_LABELS: Record<NonNullable<TaskAction>, string> = {
9+
pausing: "Pausing...",
10+
resuming: "Resuming...",
11+
deleting: "Deleting...",
12+
downloading: "Downloading...",
13+
};
14+
15+
export function getActionLabel(action: TaskAction): string | null {
16+
return action ? ACTION_LABELS[action] : null;
17+
}

0 commit comments

Comments
 (0)