Add title for prompt

Added title for prompt

The title will simplify the search in the list of prompts
This commit is contained in:
Erritis
2023-03-28 18:41:01 +03:00
committed by Sergey Shekhovtsov
parent 2374c81edb
commit cf0053a060
4 changed files with 66 additions and 28 deletions

View File

@@ -2,6 +2,7 @@
const menu = ref(false) const menu = ref(false)
const prompts = ref([]) const prompts = ref([])
const editingPrompt = ref(null) const editingPrompt = ref(null)
const newTitlePrompt = ref(null)
const newPrompt = ref('') const newPrompt = ref('')
const submittingNewPrompt = ref(false) const submittingNewPrompt = ref(false)
const promptInputErrorMessage = ref('') const promptInputErrorMessage = ref('')
@@ -24,11 +25,13 @@ const addPrompt = async () => {
const { data, error } = await useAuthFetch('/api/chat/prompts/', { const { data, error } = await useAuthFetch('/api/chat/prompts/', {
method: 'POST', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
title: newTitlePrompt.value,
prompt: newPrompt.value prompt: newPrompt.value
}) })
}) })
if (!error.value) { if (!error.value) {
prompts.value.push(data.value) prompts.value.push(data.value)
newTitlePrompt.value = null
newPrompt.value = '' newPrompt.value = ''
} }
submittingNewPrompt.value = false submittingNewPrompt.value = false
@@ -43,6 +46,7 @@ const updatePrompt = async (index) => {
const { data, error } = await useAuthFetch(`/api/chat/prompts/${editingPrompt.value.id}/`, { const { data, error } = await useAuthFetch(`/api/chat/prompts/${editingPrompt.value.id}/`, {
method: 'PUT', method: 'PUT',
body: JSON.stringify({ body: JSON.stringify({
title: editingPrompt.value.title,
prompt: editingPrompt.value.prompt prompt: editingPrompt.value.prompt
}) })
}) })
@@ -127,18 +131,30 @@ onMounted( () => {
> >
<v-list-item <v-list-item
active-color="primary" active-color="primary"
rounded="xl"
v-if="editingPrompt && editingPrompt.id === prompt.id" v-if="editingPrompt && editingPrompt.id === prompt.id"
> >
<div class="d-flex flex-row" :style="{ marginTop: '5px' }">
<div class="flex-grow-1">
<v-text-field
v-model="editingPrompt.title"
:loading="editingPrompt.updating"
:label="$t('titlePrompt')"
variant="underlined"
density="compact"
hide-details
>
</v-text-field>
<v-textarea <v-textarea
rows="2" rows="2"
v-model="editingPrompt.prompt" v-model="editingPrompt.prompt"
:loading="editingPrompt.updating" :loading="editingPrompt.updating"
variant="underlined" variant="underlined"
hide-details
density="compact" density="compact"
hide-details
> >
<template v-slot:append> </v-textarea>
</div>
<div>
<div class="d-flex flex-column"> <div class="d-flex flex-column">
<v-btn <v-btn
icon="done" icon="done"
@@ -154,8 +170,8 @@ onMounted( () => {
> >
</v-btn> </v-btn>
</div> </div>
</template> </div>
</v-textarea> </div>
</v-list-item> </v-list-item>
<v-list-item <v-list-item
v-if="!editingPrompt || editingPrompt.id !== prompt.id" v-if="!editingPrompt || editingPrompt.id !== prompt.id"
@@ -163,7 +179,7 @@ onMounted( () => {
active-color="primary" active-color="primary"
@click="selectPrompt(prompt)" @click="selectPrompt(prompt)"
> >
<v-list-item-title>{{ prompt.prompt }}</v-list-item-title> <v-list-item-title>{{ prompt.title ? prompt.title : prompt.prompt }}</v-list-item-title>
<template v-slot:append> <template v-slot:append>
<v-btn <v-btn
icon="edit" icon="edit"
@@ -184,6 +200,25 @@ onMounted( () => {
</v-list-item> </v-list-item>
</template> </template>
<v-list-item
active-color="primary"
>
<div
class="pt-3"
>
<v-text-field
rows="1"
v-model="newTitlePrompt"
:label="$t('titlePrompt')"
variant="outlined"
density="compact"
hide-details
clearable
>
</v-text-field>
</div>
</v-list-item>
<v-list-item <v-list-item
active-color="primary" active-color="primary"
> >

View File

@@ -12,6 +12,7 @@
"writeAMessage": "Write a message", "writeAMessage": "Write a message",
"frequentlyPrompts": "Frequently prompts", "frequentlyPrompts": "Frequently prompts",
"addPrompt": "Add prompt", "addPrompt": "Add prompt",
"titlePrompt": "Title",
"addNewPrompt": "Add a new prompt", "addNewPrompt": "Add a new prompt",
"pressEnterToSendYourMessageOrShiftEnterToAddANewLine": "Press Enter to send your message or Shift+Enter to add a new line", "pressEnterToSendYourMessageOrShiftEnterToAddANewLine": "Press Enter to send your message or Shift+Enter to add a new line",
"lightMode": "Light Mode", "lightMode": "Light Mode",

View File

@@ -12,6 +12,7 @@
"writeAMessage": "Напишите сообщение", "writeAMessage": "Напишите сообщение",
"frequentlyPrompts": "Список подсказок", "frequentlyPrompts": "Список подсказок",
"addPrompt": "Добавить подсказку", "addPrompt": "Добавить подсказку",
"titlePrompt": "Заголовок",
"addNewPrompt": "Добавитьте новую подсказку", "addNewPrompt": "Добавитьте новую подсказку",
"pressEnterToSendYourMessageOrShiftEnterToAddANewLine": "Нажмите Enter, чтобы отправить сообщение, или Shift+Enter, чтобы добавить новую строку.", "pressEnterToSendYourMessageOrShiftEnterToAddANewLine": "Нажмите Enter, чтобы отправить сообщение, или Shift+Enter, чтобы добавить новую строку.",
"lightMode": "Светлая", "lightMode": "Светлая",

View File

@@ -12,6 +12,7 @@
"writeAMessage": "输入信息", "writeAMessage": "输入信息",
"frequentlyPrompts": "Frequently prompts", "frequentlyPrompts": "Frequently prompts",
"addPrompt": "Add prompt", "addPrompt": "Add prompt",
"titlePrompt": "Title",
"addNewPrompt": "Add a new prompt", "addNewPrompt": "Add a new prompt",
"pressEnterToSendYourMessageOrShiftEnterToAddANewLine": "按回车键发送您的信息或按Shift+Enter键添加新行", "pressEnterToSendYourMessageOrShiftEnterToAddANewLine": "按回车键发送您的信息或按Shift+Enter键添加新行",
"lightMode": "明亮模式", "lightMode": "明亮模式",