feat: #1303 improve long text input ux and mobile modal

This commit is contained in:
Yidadaa 2023-05-08 22:49:51 +08:00
parent 1f2ef1cdb7
commit 1b19fdfe11
5 changed files with 76 additions and 48 deletions

View File

@ -106,6 +106,59 @@ export function MaskConfig(props: {
);
}
function ContextPromptItem(props: {
prompt: Message;
update: (prompt: Message) => void;
remove: () => void;
}) {
const [focusingInput, setFocusingInput] = useState(false);
return (
<div className={chatStyle["context-prompt-row"]}>
{!focusingInput && (
<select
value={props.prompt.role}
className={chatStyle["context-role"]}
onChange={(e) =>
props.update({
...props.prompt,
role: e.target.value as any,
})
}
>
{ROLES.map((r) => (
<option key={r} value={r}>
{r}
</option>
))}
</select>
)}
<Input
value={props.prompt.content}
type="text"
className={chatStyle["context-content"]}
rows={focusingInput ? 5 : 1}
onFocus={() => setFocusingInput(true)}
onBlur={() => setFocusingInput(false)}
onInput={(e) =>
props.update({
...props.prompt,
content: e.currentTarget.value as any,
})
}
/>
{!focusingInput && (
<IconButton
icon={<DeleteIcon />}
className={chatStyle["context-delete-button"]}
onClick={() => props.remove()}
bordered
/>
)}
</div>
);
}
export function ContextPrompts(props: {
context: Message[];
updateContext: (updater: (context: Message[]) => void) => void;
@ -128,42 +181,12 @@ export function ContextPrompts(props: {
<>
<div className={chatStyle["context-prompt"]} style={{ marginBottom: 20 }}>
{context.map((c, i) => (
<div className={chatStyle["context-prompt-row"]} key={i}>
<select
value={c.role}
className={chatStyle["context-role"]}
onChange={(e) =>
updateContextPrompt(i, {
...c,
role: e.target.value as any,
})
}
>
{ROLES.map((r) => (
<option key={r} value={r}>
{r}
</option>
))}
</select>
<Input
value={c.content}
type="text"
className={chatStyle["context-content"]}
rows={1}
onInput={(e) =>
updateContextPrompt(i, {
...c,
content: e.currentTarget.value as any,
})
}
/>
<IconButton
icon={<DeleteIcon />}
className={chatStyle["context-delete-button"]}
onClick={() => removeContextPrompt(i)}
bordered
/>
</div>
<ContextPromptItem
key={i}
prompt={c}
update={(prompt) => updateContextPrompt(i, prompt)}
remove={() => removeContextPrompt(i)}
/>
))}
<div className={chatStyle["context-prompt-row"]}>

View File

@ -1,4 +1,3 @@
import styles from "./settings.module.scss";
import { ALL_MODELS, ModalConfigValidator, ModelConfig } from "../store";
import Locale from "../locales";

View File

@ -124,6 +124,18 @@
}
}
@media screen and (max-width: 600px) {
.modal-container {
width: 100vw;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
.modal-content {
max-height: 50vh;
}
}
}
.show {
opacity: 1;
transition: all ease 0.3s;
@ -191,13 +203,3 @@
resize: none;
min-width: 50px;
}
@media only screen and (max-width: 600px) {
.modal-container {
width: 90vw;
.modal-content {
max-height: 50vh;
}
}
}

View File

@ -33,7 +33,7 @@ export function createMessage(override: Partial<Message>): Message {
};
}
export const ROLES: Message["role"][] = ["system", "user", "assistant"];
export const ROLES: Message["role"][] = ["user", "system", "assistant"];
export interface ChatStat {
tokenCount: number;

View File

@ -248,6 +248,10 @@ div.math {
display: flex;
align-items: center;
justify-content: center;
@media screen and (max-width: 600px) {
align-items: flex-end;
}
}
.link {