From 01d04b3611e9e28b9e431470794c33154834b5b9 Mon Sep 17 00:00:00 2001 From: Adrien Date: Fri, 24 May 2024 19:50:42 +0200 Subject: [PATCH] Conversation menu --- Chat.go | 36 +++++++++ database.go | 17 +++-- dbschema/default.esdl | 1 + dbschema/migrations/00042-m1ospnj.edgeql | 9 +++ main.go | 2 + static/icons/.DS_Store | Bin 6148 -> 6148 bytes static/style.css | 50 ++++++++++++ views/chat.html | 2 +- views/partials/popover-conversation.html | 52 +++++++++++++ views/partials/popover-conversations.html | 27 ------- views/partials/popover-keys.html | 88 ---------------------- views/partials/popover-models.html | 54 +------------ views/partials/popover-settings.html | 12 ++- 13 files changed, 173 insertions(+), 177 deletions(-) create mode 100644 dbschema/migrations/00042-m1ospnj.edgeql create mode 100644 views/partials/popover-conversation.html delete mode 100644 views/partials/popover-conversations.html delete mode 100644 views/partials/popover-keys.html diff --git a/Chat.go b/Chat.go index 9339cea..01810cc 100644 --- a/Chat.go +++ b/Chat.go @@ -594,6 +594,42 @@ func LoadModelSelectionHandler(c *fiber.Ctx) error { return c.SendString(GenerateModelPopoverHTML(false)) } +func GenerateConversationPopoverHTML(refresh bool) string { + var conversations []Conversation + err := edgeClient.Query(edgeCtx, ` + SELECT Conversation { + name, + position + } + FILTER .user = global currentUser + ORDER BY .position + `, &conversations) + if err != nil { + panic(err) + } + + out, err := pongo2.Must(pongo2.FromFile("views/partials/popover-conversation.html")).Execute(pongo2.Context{ + "Conversations": conversations, + "IsActive": refresh, + }) + if err != nil { + panic(err) + } + return out +} + +func LoadConversationSelectionHandler(c *fiber.Ctx) error { + if !checkIfLogin() || !checkIfHaveKey() { + return c.SendString("") + } + + return c.SendString(GenerateConversationPopoverHTML(false)) +} + +func RefreshConversationSelectionHandler(c *fiber.Ctx) error { + return c.SendString(GenerateConversationPopoverHTML(true)) +} + func LoadSettingsHandler(c *fiber.Ctx) error { if !checkIfLogin() { return c.SendString("") diff --git a/database.go b/database.go index b4ea765..ca6405f 100644 --- a/database.go +++ b/database.go @@ -39,10 +39,11 @@ type Setting struct { } type Conversation struct { - ID edgedb.UUID `edgedb:"id"` - Name string `edgedb:"name"` - Date time.Time `edgedb:"date"` - User User `edgedb:"user"` + ID edgedb.UUID `edgedb:"id"` + Name string `edgedb:"name"` + Position int32 `edgedb:"position"` + Date time.Time `edgedb:"date"` + User User `edgedb:"user"` } type Area struct { @@ -155,9 +156,15 @@ func addUsage(inputCost float32, outputCost float32, inputToken int32, outputTok func insertNewConversation() edgedb.UUID { var inserted struct{ id edgedb.UUID } err := edgeClient.QuerySingle(edgeCtx, ` + WITH + C := ( + SELECT Conversation + FILTER .user = global currentUser + ) INSERT Conversation { name := 'Default', - user := global currentUser + user := global currentUser, + position := count(C) + 1 } `, &inserted) if err != nil { diff --git a/dbschema/default.esdl b/dbschema/default.esdl index bb4088a..de408ce 100644 --- a/dbschema/default.esdl +++ b/dbschema/default.esdl @@ -37,6 +37,7 @@ module default { type Conversation { required name: str; + required position: int32; required user: User { on target delete delete source; }; diff --git a/dbschema/migrations/00042-m1ospnj.edgeql b/dbschema/migrations/00042-m1ospnj.edgeql new file mode 100644 index 0000000..0470e30 --- /dev/null +++ b/dbschema/migrations/00042-m1ospnj.edgeql @@ -0,0 +1,9 @@ +CREATE MIGRATION m1ospnjzsatmkntvczm5eu65omytyezeg3lanxeogtdqz2372t6cuq + ONTO m1cmvjy3ikuh5ii6b7l7gckttjmqk554llocwqx7n4aibtzngybvoq +{ + ALTER TYPE default::Conversation { + CREATE REQUIRED PROPERTY position: std::int32 { + SET REQUIRED USING ({0}); + }; + }; +}; diff --git a/main.go b/main.go index 48111c8..f8dfedf 100644 --- a/main.go +++ b/main.go @@ -86,6 +86,8 @@ func main() { // Popovers app.Get("/loadModelSelection", LoadModelSelectionHandler) + app.Get("/loadConversationSelection", LoadConversationSelectionHandler) + app.Get("/refreshConversationSelection", RefreshConversationSelectionHandler) app.Get("/loadUsageKPI", LoadUsageKPIHandler) app.Get("/loadKeys", LoadKeysHandler) app.Get("/loadSettings", LoadSettingsHandler) diff --git a/static/icons/.DS_Store b/static/icons/.DS_Store index 91eed7f5bdd6095af2d0d02e99d18d1a6575f8af..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 100644 GIT binary patch delta 70 zcmZoMXfc=|#>AjHu~2NHo+1YW5HK<@2yEWS7{<2w0Am#6W_AvK4xj>{$am(+{342+ UKzW7)kiy9(Jj$D6L{=~Z04^gBI{*Lx delta 242 zcmZoMXfc=|#>B`mF;Q%yo}wrV0|Nsi1A_nqLoP!BLlHwNLoq|~#Kh(GAPFvpQieQ+ zWQKfX$((e<;N<+=0-!t$U{#l!@8Xh_lb-}s#L<>hbHVfHQAZ#fhuRc0wMw`Z7i2&j rurV>3ZL)y~%Vus4ZVsT2HYR>&p3E
- + +
+ + + +{% if not IsActive %} + +{% endif %} \ No newline at end of file diff --git a/views/partials/popover-conversations.html b/views/partials/popover-conversations.html deleted file mode 100644 index 2582bf8..0000000 --- a/views/partials/popover-conversations.html +++ /dev/null @@ -1,27 +0,0 @@ - \ No newline at end of file diff --git a/views/partials/popover-keys.html b/views/partials/popover-keys.html deleted file mode 100644 index f89ebca..0000000 --- a/views/partials/popover-keys.html +++ /dev/null @@ -1,88 +0,0 @@ - \ No newline at end of file diff --git a/views/partials/popover-models.html b/views/partials/popover-models.html index 9e49fc6..d03a4a1 100644 --- a/views/partials/popover-models.html +++ b/views/partials/popover-models.html @@ -163,56 +163,4 @@ event.preventDefault(); } }); - - - \ No newline at end of file + \ No newline at end of file diff --git a/views/partials/popover-settings.html b/views/partials/popover-settings.html index b528e29..21b80d0 100644 --- a/views/partials/popover-settings.html +++ b/views/partials/popover-settings.html @@ -1,11 +1,11 @@ -