From c05de5d3258c521f3e362691f1e6911cda2edcf4 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 25 May 2024 10:56:15 +0200 Subject: [PATCH] fix --- Chat.go | 39 +++++++++++++++++++----- LLM.go | 1 + login.go | 2 ++ main.go | 1 + views/partials/modal-llm-setting.html | 11 ------- views/partials/popover-conversation.html | 24 ++++++++------- 6 files changed, 48 insertions(+), 30 deletions(-) delete mode 100644 views/partials/modal-llm-setting.html diff --git a/Chat.go b/Chat.go index 32c27ec..5b79b67 100644 --- a/Chat.go +++ b/Chat.go @@ -86,10 +86,19 @@ type TemplateMessage struct { } func generateChatHTML() string { + // Print the name of the current conversation + var currentConv Conversation + err := edgeClient.QuerySingle(edgeCtx, ` + SELECT global currentConversation { name }`, ¤tConv) + if err != nil { + panic(err) + } + fmt.Println("Current conversation: ", currentConv.Name) + // Maybe redo that to be area by area because look like shit rn. It come from early stage of dev. It work tho soooo... var Messages []Message - err := edgeClient.Query(edgeCtx, ` + err = edgeClient.Query(edgeCtx, ` SELECT Message { id, selected, @@ -700,10 +709,6 @@ func LoadSettingsHandler(c *fiber.Ctx) error { } func CreateConversationHandler(c *fiber.Ctx) error { - if !checkIfLogin() || !checkIfHaveKey() { - return c.SendString("") - } - name := c.FormValue("conversation-name-input") if name == "" { name = "New Conversation" @@ -728,11 +733,27 @@ func CreateConversationHandler(c *fiber.Ctx) error { return c.SendString(GenerateConversationPopoverHTML(true)) } -func SelectConversationHandler(c *fiber.Ctx) error { - if !checkIfLogin() || !checkIfHaveKey() { - return c.SendString("") +func DeleteConversationHandler(c *fiber.Ctx) error { + conversationId := c.FormValue("conversationId") + + conversationUUID, err := edgedb.ParseUUID(conversationId) + if err != nil { + // Handle the error + panic(err) } + err = edgeClient.Execute(edgeCtx, ` + DELETE Conversation + FILTER .user = global currentUser AND .id = $0; + `, conversationUUID) + if err != nil { + panic(err) + } + + return c.SendString(GenerateConversationPopoverHTML(true)) +} + +func SelectConversationHandler(c *fiber.Ctx) error { conversationId := c.FormValue("conversation-id") conversationUUID, err := edgedb.ParseUUID(conversationId) if err != nil { @@ -740,6 +761,8 @@ func SelectConversationHandler(c *fiber.Ctx) error { panic(err) } + fmt.Println("conversationUUID", conversationUUID.String()) + err = edgeClient.Execute(edgeCtx, ` SET global currentConversation := ( SELECT Conversation diff --git a/LLM.go b/LLM.go index b6eb990..70d16d4 100644 --- a/LLM.go +++ b/LLM.go @@ -141,6 +141,7 @@ func updateLLMPositionBatch(c *fiber.Ctx) error { return nil } +// When we reorder the LLM list func updateConversationPositionBatch(c *fiber.Ctx) error { var positionUpdates []PositionUpdate if err := c.BodyParser(&positionUpdates); err != nil { diff --git a/login.go b/login.go index 0b98306..e8b4450 100644 --- a/login.go +++ b/login.go @@ -1,3 +1,5 @@ +// Hohohoho. Bienvenue mes amis. +// I think you gonna be interested by this part. package main import ( diff --git a/main.go b/main.go index 09f2061..1d337ba 100644 --- a/main.go +++ b/main.go @@ -121,6 +121,7 @@ func main() { app.Get("/loadSettings", LoadSettingsHandler) app.Post("/updateLLMPositionBatch", updateLLMPositionBatch) app.Get("/createConversation", CreateConversationHandler) + app.Get("/deleteConversation", DeleteConversationHandler) app.Get("/selectConversation", SelectConversationHandler) app.Post("/updateConversationPositionBatch", updateConversationPositionBatch) diff --git a/views/partials/modal-llm-setting.html b/views/partials/modal-llm-setting.html deleted file mode 100644 index 6963af8..0000000 --- a/views/partials/modal-llm-setting.html +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/views/partials/popover-conversation.html b/views/partials/popover-conversation.html index ef90678..a66a052 100644 --- a/views/partials/popover-conversation.html +++ b/views/partials/popover-conversation.html @@ -13,9 +13,11 @@