blob: 30f616117045f2849010668b0304f711c9065d59 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
"use client";
import type { Memory, Project } from "@imemio/sdk";
import { useEffect, useState } from "react";
type MemoryWithProject = Memory & {
project: Project | null;
};
type MemoryEditModalProps = {
memory: MemoryWithProject;
projects: Project[];
onSave: (data: { content: string; projectId: string }) => void;
onClose: () => void;
isSaving?: boolean;
};
export function MemoryEditModal({
memory,
projects,
onSave,
onClose,
isSaving,
}: MemoryEditModalProps) {
const [content, setContent] = useState(memory.content);
const [projectId, setProjectId] = useState(memory.projectId);
useEffect(() => {
setContent(memory.content);
setProjectId(memory.projectId);
}, [memory]);
const handleSubmit = (formSubmitEvent: React.FormEvent) => {
formSubmitEvent.preventDefault();
if (content.trim()) {
onSave({ content, projectId });
}
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/80">
<div className="w-full max-w-lg border border-[#2a2a2a] bg-[#0f0f0f] p-6">
<div className="mb-4 flex items-center justify-between">
<h2 className="text-lg text-white">
<span className="text-[#999999]">></span> edit memory
</h2>
<button
className="text-[#666666] transition hover:text-white"
onClick={onClose}
type="button"
>
[esc]
</button>
</div>
<form className="flex flex-col gap-4" onSubmit={handleSubmit}>
<div>
<label className="mb-1 block text-xs text-[#666666]">content</label>
<textarea
className="w-full border border-[#2a2a2a] bg-[#070707] px-3 py-2 text-white placeholder:text-[#666666] focus:border-[#666666] focus:outline-none"
onChange={(textareaChangeEvent) =>
setContent(textareaChangeEvent.target.value)
}
rows={5}
value={content}
/>
</div>
<div>
<label className="mb-1 block text-xs text-[#666666]">project</label>
<select
className="w-full border border-[#2a2a2a] bg-[#070707] px-3 py-2 text-white focus:border-[#666666] focus:outline-none"
onChange={(selectChangeEvent) =>
setProjectId(selectChangeEvent.target.value)
}
value={projectId}
>
{projects.map((project) => (
<option key={project.id} value={project.id}>
{project.isGlobal ? `* ${project.name} (global)` : project.name}
</option>
))}
</select>
</div>
<div className="flex justify-end gap-2">
<button
className="border border-[#2a2a2a] bg-[#0f0f0f] px-4 py-2 text-[#999999] transition hover:border-[#666666] hover:text-white"
onClick={onClose}
type="button"
>
cancel
</button>
<button
className="border border-[#2a2a2a] bg-[#0f0f0f] px-4 py-2 text-white transition hover:border-[#666666] disabled:text-[#666666] disabled:hover:border-[#2a2a2a]"
disabled={isSaving || !content.trim()}
type="submit"
>
{isSaving ? "saving ..." : "save changes"}
</button>
</div>
</form>
</div>
</div>
);
}
|