Skip to content

Commit d9d20f9

Browse files
汤圆汤圆
authored andcommitted
feat: add task
1 parent dd16071 commit d9d20f9

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

public/locales/en/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@
3333
"donation": "Donation",
3434
"continue": "Continue",
3535
"placeholder-agent-goal": "Make the world a better place.",
36-
"paused": "Paused"
36+
"paused": "Paused",
37+
"add-task": "Add Task",
38+
"custom-task":"Custom Task"
3739
}

public/locales/zh/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@
3333
"donation": "捐赠",
3434
"continue": "继续",
3535
"placeholder-agent-goal": "让世界变得更美好。",
36-
"paused": "已暂停"
36+
"paused": "已暂停",
37+
"add-task": "新增任务",
38+
"custom-task": "自定义任务"
3739
}

src/components/Input.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { isArrayOfType } from "../utils/helpers";
66
import type { toolTipProperties } from "./types";
77

88
interface InputProps {
9+
small?: boolean; // Will lower padding and font size. Currently only works for the default input
910
left?: React.ReactNode;
1011
value: string | number | undefined;
1112
onChange: (
@@ -30,6 +31,7 @@ interface InputProps {
3031

3132
const Input = (props: InputProps) => {
3233
const {
34+
small,
3335
placeholder,
3436
left,
3537
value,
@@ -87,7 +89,8 @@ const Input = (props: InputProps) => {
8789
className={clsx(
8890
"border:black delay-50 h-15 w-full resize-none rounded-xl border-[2px] border-white/10 bg-[#3a3a3a] p-2 text-sm tracking-wider outline-0 transition-all placeholder:text-white/20 hover:border-[#1E88E5]/40 focus:border-[#1E88E5] sm:h-20 md:text-lg",
8991
disabled && " cursor-not-allowed hover:border-white/10",
90-
left && "md:rounded-l-none"
92+
left && "md:rounded-l-none",
93+
small && "text-sm sm:py-[0]"
9194
)}
9295
placeholder={placeholder}
9396
value={value}
@@ -120,9 +123,11 @@ const Input = (props: InputProps) => {
120123

121124
return (
122125
<div
123-
className={`items-left z-5 flex w-full flex-col rounded-xl font-mono text-lg text-white/75 shadow-xl md:flex-row md:items-center md:bg-[#3a3a3a] ${
124-
isTypeRange() ? "md: border-white/10 md:border-[2px]" : ""
125-
} shadow-xl md:flex-row md:items-center`}
126+
className={clsx(
127+
`items-left z-5 flex h-fit w-full flex-col rounded-xl font-mono text-lg text-white/75 shadow-xl md:flex-row md:items-center md:bg-[#3a3a3a]`,
128+
isTypeRange() && "md: border-white/10 md:border-[2px]",
129+
`shadow-xl md:flex-row md:items-center`
130+
)}
126131
>
127132
{left && (
128133
<Label left={left} type={type} toolTipProperties={toolTipProperties} />

src/components/TaskWindow.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,63 @@
11
import React from "react";
22
import FadeIn from "./motions/FadeIn";
33
import Expand from "./motions/expand";
4-
import { Task } from "../types/agentTypes";
4+
import {
5+
Task,
6+
MESSAGE_TYPE_TASK,
7+
TASK_STATUS_STARTED,
8+
} from "../types/agentTypes";
59
import { getMessageContainerStyle, getTaskStatusIcon } from "./utils/helpers";
610
import { useMessageStore } from "./stores";
711
import { FaListAlt, FaTimesCircle } from "react-icons/fa";
812
import { useAgentStore } from "./stores";
913
import clsx from "clsx";
14+
import Input from "./Input";
15+
import Button from "./Button";
16+
import { v1 } from "uuid";
1017
import { useTranslation } from "next-i18next";
1118

1219
export const TaskWindow = () => {
20+
const [customTask, setCustomTask] = React.useState("");
1321
const tasks = useMessageStore.use.tasks();
22+
const addMessage = useMessageStore.use.addMessage();
1423
const { t } = useTranslation();
1524

25+
const handleAddTask = () => {
26+
addMessage({
27+
taskId: v1().toString(),
28+
value: customTask,
29+
status: TASK_STATUS_STARTED,
30+
type: MESSAGE_TYPE_TASK,
31+
});
32+
setCustomTask("");
33+
};
34+
1635
return (
1736
<Expand className="xl mx-2 mt-4 hidden w-[20rem] flex-col items-center rounded-2xl border-2 border-white/20 bg-zinc-900 px-1 font-mono shadow-2xl xl:flex">
1837
<div className="sticky top-0 my-2 flex items-center justify-center gap-2 bg-zinc-900 p-2 text-gray-300 ">
1938
<FaListAlt /> <span>{t("current-tasks")}</span>
2039
</div>
21-
<div className="window-heights mb-2 w-full px-1 ">
22-
<div className="flex flex-col gap-2 overflow-y-auto overflow-x-hidden">
40+
<div className="flex h-full w-full flex-col gap-2 px-1 py-1">
41+
<div className="window-heights flex w-full flex-col gap-2 overflow-y-auto overflow-x-hidden pr-1">
2342
{tasks.map((task, i) => (
2443
<Task key={i} task={task} />
2544
))}
2645
</div>
46+
<div className="flex flex-row gap-1">
47+
<Input
48+
value={customTask}
49+
onChange={(e) => setCustomTask(e.target.value)}
50+
placeholder={t("custom-task") as string}
51+
small
52+
/>
53+
<Button
54+
className="font-sm px-2 py-[0] text-sm sm:px-2 sm:py-[0]"
55+
onClick={handleAddTask}
56+
disabled={!customTask}
57+
>
58+
{t("add-task")}
59+
</Button>
60+
</div>
2761
</div>
2862
</Expand>
2963
);

src/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ const Home: NextPage = () => {
292292
displaySettings
293293
openSorryDialog={() => setShowSorryDialog(true)}
294294
/>
295-
{tasks.length > 0 && <TaskWindow />}
295+
{(agent || tasks.length > 0) && <TaskWindow />}
296296
</Expand>
297297

298298
<div className="flex w-full flex-col gap-2 sm:mt-4 md:mt-10">

0 commit comments

Comments
 (0)