Skip to content

Commit f542ab5

Browse files
committed
キーワードを更新できるようにする
Closes #7
1 parent 146056d commit f542ab5

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

Diff for: public/style.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ textarea {
2121
margin: auto 8px;
2222
}
2323

24-
.keyword:after {
25-
content: " X";
24+
.keyword {
25+
white-space: nowrap;
2626
}
2727

2828
.row {

Diff for: src/App.jsx

+15
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ function App() {
7373
await save();
7474
};
7575

76+
const handleUpdate = (key, keyword, index) => {
77+
const keywords = keyword.split(",").map((keyword) => keyword.trim());
78+
setData(key, "keywords", (prev) => [
79+
...prev.slice(0, index),
80+
...keywords,
81+
...prev.slice(index + 1),
82+
]);
83+
};
84+
7685
return (
7786
<>
7887
<h1>Prompter</h1>
@@ -90,6 +99,9 @@ function App() {
9099
onAdd={(keyword) => handleAdd("prompt", keyword)}
91100
onClear={() => handleClear("prompt")}
92101
onRemove={(index) => handleRemove("prompt", index)}
102+
onUpdate={(keyword, index) =>
103+
handleUpdate("prompt", keyword, index)
104+
}
93105
/>
94106
)}
95107
</For>
@@ -102,6 +114,9 @@ function App() {
102114
onAdd={(keyword) => handleAdd("negativePrompt", keyword)}
103115
onClear={() => handleClear("negativePrompt")}
104116
onRemove={(index) => handleRemove("negativePrompt", index)}
117+
onUpdate={(keyword, index) =>
118+
handleUpdate("negativePrompt", keyword, index)
119+
}
105120
/>
106121
)}
107122
</For>

Diff for: src/components/Prompt.jsx

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import { createSignal, createMemo, Index } from "solid-js";
22

33
function Prompt(props) {
4+
const [index, setIndex] = createSignal(-1);
45
const [keyword, setKeyword] = createSignal("");
56
const result = createMemo(() => props.keywords.join(", "));
7+
const isAdd = createMemo(() => index() < 0);
68

79
const handleAdd = () => {
810
props.onAdd?.(keyword());
911
setKeyword("");
1012
};
1113

14+
const handleCancel = (keyword, index) => {
15+
setKeyword("");
16+
setIndex(-1);
17+
};
18+
19+
const handleChange = (keyword, index) => {
20+
setKeyword(keyword);
21+
setIndex(index);
22+
};
23+
1224
const handleCopy = () => {
1325
navigator.clipboard.writeText(result());
1426
};
@@ -21,6 +33,12 @@ function Prompt(props) {
2133
setKeyword((prev) => `(${prev})`);
2234
};
2335

36+
const handleUpdate = () => {
37+
props.onUpdate?.(keyword(), index());
38+
setKeyword("");
39+
setIndex(-1);
40+
};
41+
2442
return (
2543
<>
2644
Keyword:
@@ -35,7 +53,17 @@ function Prompt(props) {
3553
&nbsp;
3654
<button onclick={handleDecreaseAttention}>Decrease Attention</button>
3755
&nbsp;
38-
<button onClick={handleAdd}>Add</button>
56+
<button onClick={handleAdd} disabled={!isAdd()}>
57+
Add
58+
</button>
59+
&nbsp;
60+
<button onClick={handleUpdate} disabled={isAdd()}>
61+
Update
62+
</button>
63+
&nbsp;
64+
<button onClick={handleCancel} disabled={isAdd()}>
65+
Cancel
66+
</button>
3967
</div>
4068
<br />
4169
Keywords:
@@ -44,9 +72,13 @@ function Prompt(props) {
4472
<Index each={props.keywords}>
4573
{(keyword, i) => (
4674
<>
47-
<button class="keyword" onClick={[props.onRemove, i]}>
48-
{keyword()}
49-
</button>
75+
<span class="keyword">
76+
<button onClick={() => handleChange(keyword(), i)}>
77+
{keyword()}
78+
</button>
79+
{"\n"}
80+
<button onClick={[props.onRemove, i]}>X</button>
81+
</span>
5082
{"\n"}
5183
</>
5284
)}

0 commit comments

Comments
 (0)