webconfig: Make prompt selectable

This commit is contained in:
Fabian Boehm 2023-08-29 14:11:05 +02:00
parent 4b4cd4c45a
commit 209af84a37
2 changed files with 23 additions and 17 deletions

View file

@ -199,10 +199,12 @@
<div class="prompt_demo_choice_label" style="color: #FFF;" x-text="selectedPrompt.name"></div> <div class="prompt_demo_choice_label" style="color: #FFF;" x-text="selectedPrompt.name"></div>
<div style='display: flex'> <div style='display: flex'>
<div x-html='selectedPrompt.demo' style='flex-grow: 1' class="prompt_demo unbordered"></div> <div x-html='selectedPrompt.demo' style='flex-grow: 1' class="prompt_demo unbordered"></div>
<div x-if='selectedPrompt.right' title="right prompt for {{selectedPrompt.name }}" <template x-if="selectedPrompt.right">
x-html='selectedPrompt.right' class="prompt_demo unbordered" <div title="right prompt for {{selectedPrompt.name }}"
@click="selectPrompt(selectedPrompt)"> x-html='selectedPrompt.right' class="prompt_demo unbordered"
</div> @click="selectPrompt(selectedPrompt)">
</div>
</template>
</div> </div>
<div style="position: absolute; right: 5px; bottom: 5px;"> <div style="position: absolute; right: 5px; bottom: 5px;">
<button class="save_button" x-show="showSaveButton" style="color: #CCC" @click="setPrompt()" <button class="save_button" x-show="showSaveButton" style="color: #CCC" @click="setPrompt()"

View file

@ -231,20 +231,24 @@ document.addEventListener("alpine:init", () => {
this.savePromptButtonTitle = "Set Prompt"; this.savePromptButtonTitle = "Set Prompt";
}, },
setNewPrompt(selectedPrompt) { async setNewPrompt(selectedPrompt) {
$http let postdata = { fish_prompt: selectedPrompt.function };
.post("set_prompt/", { fish_prompt: selectedPrompt.function }) let resp = await fetch("set_prompt/", {
.then(function (arg) { method: "POST",
// Update attributes of current prompt and select it headers: { "Content-Type": "application/json" },
this.samplePrompts[0].demo = selectedPrompt.demo; body: JSON.stringify(postdata)
this.samplePrompts[0].right = selectedPrompt.right; });
this.samplePrompts[0].function = selectedPrompt.function; if (resp.ok) {
this.samplePrompts[0].font_size = selectedPrompt.font_size; // Update attributes of current prompt and select it
this.selectedPrompt = this.samplePrompts[0]; this.samplePrompts[0].demo = selectedPrompt.demo;
this.samplePrompts[0].right = selectedPrompt.right;
this.samplePrompts[0].function = selectedPrompt.function;
this.samplePrompts[0].font_size = selectedPrompt.font_size;
this.selectedPrompt = this.samplePrompts[0];
// Note that we set it // Note that we set it
this.savePromptButtonTitle = "Prompt Set!"; this.savePromptButtonTitle = "Prompt Set!";
}); };
}, },
setPrompt() { setPrompt() {