From 04424b4abb7f8ad9f3318d0919fe8a33c3417cb6 Mon Sep 17 00:00:00 2001 From: tyler Date: Sat, 1 Jun 2024 12:58:38 -0400 Subject: [PATCH] Fixed bug when deleting pages; fixed UI bug when updating chat bot --- NOTES.md | 5 +- v1/app.go | 71 ++++++++++++++++++++------ v1/frontend/src/components/ChatBot.jsx | 13 +++++ 3 files changed, 69 insertions(+), 20 deletions(-) diff --git a/NOTES.md b/NOTES.md index e4a8788..a4e18db 100644 --- a/NOTES.md +++ b/NOTES.md @@ -12,15 +12,14 @@ v1.N: - OBS integration Rum Goggles Service: +- Chat polls - Monitor all live stream chats - Channel points - Spam/Troll tracking # Bugs -Updating chat bot URL does not show up in UI until app is restarted - -Sign in with email does not work +Windows 10: white screen of death when deleting accounts/channels Chat bot rule menu back button does not work in macOS diff --git a/v1/app.go b/v1/app.go index 26c78ce..9da88f6 100644 --- a/v1/app.go +++ b/v1/app.go @@ -835,10 +835,6 @@ func (a *App) activatePage(pi PageInfo) error { if name == nil { return fmt.Errorf("page name is nil") } - url := pi.KeyUrl() - if url == nil { - return fmt.Errorf("page key url is nil") - } a.pagesMu.Lock() page, exists := a.pages[*name] @@ -873,6 +869,11 @@ func (a *App) activatePage(pi PageInfo) error { } page.active = true + url := pi.KeyUrl() + if url == nil { + return fmt.Errorf("page key url is nil") + } + err := a.producers.ApiP.Start(*name, *url, 10*time.Second) if err != nil { return fmt.Errorf("error starting api: %v", err) @@ -888,6 +889,43 @@ func (a *App) activatePage(pi PageInfo) error { return nil } +func (a *App) deletePage(pi PageInfo) error { + name := pi.String() + if name == nil { + return fmt.Errorf("page name is nil") + } + + a.pagesMu.Lock() + defer a.pagesMu.Unlock() + page, exists := a.pages[*name] + if !exists { + return fmt.Errorf("page does not exist") + } + + page.activeMu.Lock() + defer page.activeMu.Unlock() + if page.active { + if a.producers.ApiP.Active(*name) { + err := a.producers.ApiP.Stop(*name) + if err != nil { + return fmt.Errorf("error stopping api: %v", err) + } + } + + page.displayingMu.Lock() + if page.displaying { + runtime.EventsEmit(a.wails, "PageActive", false) + } + page.displayingMu.Unlock() + + page.active = false + } + + delete(a.pages, *name) + + return nil +} + func (a *App) DeleteAccount(id int64) error { acct, err := a.services.AccountS.ByID(id) if err != nil { @@ -913,10 +951,9 @@ func (a *App) DeleteAccount(id int64) error { return fmt.Errorf("Error deleting account. Try again.") } - // Assumes page is active when delete is called. - err = a.activatePage(acct) + err = a.deletePage(acct) if err != nil { - a.logError.Println("error de-activating page:", err) + a.logError.Println("error deleting page:", err) return fmt.Errorf("Error deleting account. Try again.") } @@ -954,11 +991,10 @@ func (a *App) DeleteChannel(id int64) error { return fmt.Errorf("Error deleting channel. Try again.") } - // Assumes page is active when delete is called. - err = a.activatePage(channel) + err = a.deletePage(channel) if err != nil { - a.logError.Println("error de-activating page:", err) - return fmt.Errorf("Error deleting account. Try again.") + a.logError.Println("error deleting page:", err) + return fmt.Errorf("Error deleting channel. Try again.") } err = a.services.ChannelS.Delete(channel) @@ -1273,12 +1309,13 @@ func (a *App) UpdateChatbot(chatbot *models.Chatbot) error { return fmt.Errorf("Error updating chatbot. Try again.") } - list, err := a.chatbotList() - if err != nil { - a.logError.Println("error getting chatbot list:", err) - return fmt.Errorf("Error updating chatbot. Try again.") - } - runtime.EventsEmit(a.wails, "ChatbotList", list) + // list, err := a.chatbotList() + // if err != nil { + // a.logError.Println("error getting chatbot list:", err) + // return fmt.Errorf("Error updating chatbot. Try again.") + // } + runtime.EventsEmit(a.wails, "ChatbotInfo", chatbot) + // runtime.EventsEmit(a.wails, "ChatbotList", list) return nil } diff --git a/v1/frontend/src/components/ChatBot.jsx b/v1/frontend/src/components/ChatBot.jsx index e1752f1..08b7b92 100644 --- a/v1/frontend/src/components/ChatBot.jsx +++ b/v1/frontend/src/components/ChatBot.jsx @@ -42,8 +42,19 @@ function ChatBot(props) { const [openNewRule, setOpenNewRule] = useState(false); const [chatbotRules, setChatbotRules] = useState([]); const [chatbotSettings, setChatbotSettings] = useState(true); + const [refresh, setRefresh] = useState(false); useEffect(() => { + EventsOff('ChatbotInfo'); + EventsOn('ChatbotInfo', (event) => { + if (openChatbot !== null && openChatbot.id === event.id) { + openChatbot.name = event.name; + openChatbot.url = event.url; + setRefresh(!refresh); + } + }); + + EventsOff('ChatbotList'); EventsOn('ChatbotList', (event) => { setChatbots(event); if (openChatbot !== null) { @@ -54,7 +65,9 @@ function ChatBot(props) { } } }); + }, [openChatbot]); + useEffect(() => { EventsOn('ChatbotRules', (event) => { setChatbotRules(event); });