Working edit btn

This commit is contained in:
Adrien Bouvais 2024-05-23 20:26:23 +02:00
parent ccddfdc631
commit 583b93c519
4 changed files with 37 additions and 3 deletions

26
Chat.go
View File

@ -374,6 +374,32 @@ func RedoMessageHandler(c *fiber.Ctx) error {
return c.SendString(GeneratePlaceholderHTML(message.Content, selectedLLMIds, false)) return c.SendString(GeneratePlaceholderHTML(message.Content, selectedLLMIds, false))
} }
func EditMessageHandler(c *fiber.Ctx) error {
messageId := c.FormValue("id")
message := c.FormValue("message")
messageUUID, _ := edgedb.ParseUUID(messageId)
var selectedLLMIds []string
err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds)
if err != nil {
// Handle the error
panic(err)
}
// Delete messages
err = edgeClient.Execute(edgeCtx, `
WITH
messageArea := (SELECT Message FILTER .id = <uuid>$0).area
DELETE Area
FILTER .position >= messageArea.position AND .conversation = messageArea.conversation AND .conversation.user = global currentUser;
`, messageUUID)
if err != nil {
panic(err)
}
return c.SendString(GeneratePlaceholderHTML(message, selectedLLMIds, true))
}
func ClearChatHandler(c *fiber.Ctx) error { func ClearChatHandler(c *fiber.Ctx) error {
// Delete the default conversation // Delete the default conversation
err := edgeClient.Execute(edgeCtx, ` err := edgeClient.Execute(edgeCtx, `

View File

@ -75,6 +75,7 @@ func main() {
app.Post("/redoMessage", RedoMessageHandler) app.Post("/redoMessage", RedoMessageHandler)
app.Post("/clearChat", ClearChatHandler) app.Post("/clearChat", ClearChatHandler)
app.Get("/userMessage", GetUserMessageHandler) app.Get("/userMessage", GetUserMessageHandler)
app.Post("/editMessage", EditMessageHandler)
// Settings routes // Settings routes
app.Post("/addKeys", addKeys) app.Post("/addKeys", addKeys)

View File

@ -1,4 +1,4 @@
<div class="message-bot mt-3"> <div class="message-bot mt-3" id="msg-{{ ConversationAreaId }}">
<div class="columns is-mobile"> <div class="columns is-mobile">
<div class="column is-narrow" id="icon-column"> <div class="column is-narrow" id="icon-column">
<!-- Left column with the icon --> <!-- Left column with the icon -->

View File

@ -20,7 +20,8 @@
<div class="control" style="width: 100%;"> <div class="control" style="width: 100%;">
<textarea class="textarea is-small has-fixed-size mt-2" <textarea class="textarea is-small has-fixed-size mt-2"
placeholder="Enter your message here" rows="{{ Rows }}" placeholder="Enter your message here" rows="{{ Rows }}"
style="background-color: transparent; width: 100%;">{{ Content }}</textarea> style="background-color: transparent; width: 100%;"
name="message">{{ Content }}</textarea>
</div> </div>
</div> </div>
<div class="field is-grouped is-flex is-justify-content-flex-end mb-3"> <div class="field is-grouped is-flex is-justify-content-flex-end mb-3">
@ -33,7 +34,13 @@
</button> </button>
</div> </div>
<div class="control"> <div class="control">
<button hx-get="/test" class="button is-success is-outlined is-small"> <div style="display: none;" hx-trigger="click from:#edit-button-{{ ID }}"
hx-target="next .message-bot" hx-swap="outerHTML" hx-get="/empty"></div>
<button class="button is-success is-outlined is-small"
hx-post="/editMessage?id={{ ID }}" hx-target="closest .message-user"
hx-include="[name='message']"
hx-vals="js:{selectedLLMIds: getSelectedModelsIDs()}" hx-swap="outerHTML"
id="edit-button-{{ ID }}" hx-trigger="click">
<span class="icon"> <span class="icon">
<i class="fa-solid fa-check"></i> <i class="fa-solid fa-check"></i>
</span> </span>