Fixed bug when deleting pages; fixed UI bug when updating chat bot

This commit is contained in:
tyler 2024-06-01 12:58:38 -04:00
parent f9a5ae7c01
commit 04424b4abb
3 changed files with 69 additions and 20 deletions

View file

@ -12,15 +12,14 @@ v1.N:
- OBS integration - OBS integration
Rum Goggles Service: Rum Goggles Service:
- Chat polls
- Monitor all live stream chats - Monitor all live stream chats
- Channel points - Channel points
- Spam/Troll tracking - Spam/Troll tracking
# Bugs # Bugs
Updating chat bot URL does not show up in UI until app is restarted Windows 10: white screen of death when deleting accounts/channels
Sign in with email does not work
Chat bot rule menu back button does not work in macOS Chat bot rule menu back button does not work in macOS

View file

@ -835,10 +835,6 @@ func (a *App) activatePage(pi PageInfo) error {
if name == nil { if name == nil {
return fmt.Errorf("page name is 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() a.pagesMu.Lock()
page, exists := a.pages[*name] page, exists := a.pages[*name]
@ -873,6 +869,11 @@ func (a *App) activatePage(pi PageInfo) error {
} }
page.active = true 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) err := a.producers.ApiP.Start(*name, *url, 10*time.Second)
if err != nil { if err != nil {
return fmt.Errorf("error starting api: %v", err) return fmt.Errorf("error starting api: %v", err)
@ -888,6 +889,43 @@ func (a *App) activatePage(pi PageInfo) error {
return nil 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 { func (a *App) DeleteAccount(id int64) error {
acct, err := a.services.AccountS.ByID(id) acct, err := a.services.AccountS.ByID(id)
if err != nil { if err != nil {
@ -913,10 +951,9 @@ func (a *App) DeleteAccount(id int64) error {
return fmt.Errorf("Error deleting account. Try again.") return fmt.Errorf("Error deleting account. Try again.")
} }
// Assumes page is active when delete is called. err = a.deletePage(acct)
err = a.activatePage(acct)
if err != nil { 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.") 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.") return fmt.Errorf("Error deleting channel. Try again.")
} }
// Assumes page is active when delete is called. err = a.deletePage(channel)
err = a.activatePage(channel)
if err != nil { 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.") return fmt.Errorf("Error deleting channel. Try again.")
} }
err = a.services.ChannelS.Delete(channel) 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.") return fmt.Errorf("Error updating chatbot. Try again.")
} }
list, err := a.chatbotList() // list, err := a.chatbotList()
if err != nil { // if err != nil {
a.logError.Println("error getting chatbot list:", err) // a.logError.Println("error getting chatbot list:", err)
return fmt.Errorf("Error updating chatbot. Try again.") // return fmt.Errorf("Error updating chatbot. Try again.")
} // }
runtime.EventsEmit(a.wails, "ChatbotList", list) runtime.EventsEmit(a.wails, "ChatbotInfo", chatbot)
// runtime.EventsEmit(a.wails, "ChatbotList", list)
return nil return nil
} }

View file

@ -42,8 +42,19 @@ function ChatBot(props) {
const [openNewRule, setOpenNewRule] = useState(false); const [openNewRule, setOpenNewRule] = useState(false);
const [chatbotRules, setChatbotRules] = useState([]); const [chatbotRules, setChatbotRules] = useState([]);
const [chatbotSettings, setChatbotSettings] = useState(true); const [chatbotSettings, setChatbotSettings] = useState(true);
const [refresh, setRefresh] = useState(false);
useEffect(() => { 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) => { EventsOn('ChatbotList', (event) => {
setChatbots(event); setChatbots(event);
if (openChatbot !== null) { if (openChatbot !== null) {
@ -54,7 +65,9 @@ function ChatBot(props) {
} }
} }
}); });
}, [openChatbot]);
useEffect(() => {
EventsOn('ChatbotRules', (event) => { EventsOn('ChatbotRules', (event) => {
setChatbotRules(event); setChatbotRules(event);
}); });