From 9beecbb21adef6fdd66fbcb4b9bd35020c8af45d Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Thu, 16 Nov 2023 11:01:25 -0800 Subject: [PATCH] Calls integration (#86) --- webapp/src/calls_button.tsx | 5 +++++ webapp/src/index.tsx | 3 +++ webapp/src/redux.tsx | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 webapp/src/calls_button.tsx create mode 100644 webapp/src/redux.tsx diff --git a/webapp/src/calls_button.tsx b/webapp/src/calls_button.tsx new file mode 100644 index 00000000..7eea29bc --- /dev/null +++ b/webapp/src/calls_button.tsx @@ -0,0 +1,5 @@ +import {doTranscribe} from './client'; + +export function callsPostButtonClickedHandler(post: any) { + doTranscribe(post.id); +} diff --git a/webapp/src/index.tsx b/webapp/src/index.tsx index 61fc0c05..ccdd60e8 100644 --- a/webapp/src/index.tsx +++ b/webapp/src/index.tsx @@ -15,6 +15,7 @@ import Config from './components/config/config'; import {doReaction, doSummarize, doTranscribe} from './client'; import {BotUsername} from './constants'; import PostEventListener from './websocket'; +import {setupRedux} from './redux'; type WebappStore = Store>> @@ -25,6 +26,8 @@ export default class Plugin { // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function public async initialize(registry: any, store: WebappStore) { + setupRedux(registry, store); + registry.registerWebSocketEventHandler(StreamingPostWebsocketEvent, this.postEventListener.handlePostUpdateWebsockets); const LLMBotPostWithWebsockets = (props: any) => { return ( diff --git a/webapp/src/redux.tsx b/webapp/src/redux.tsx new file mode 100644 index 00000000..940b15c2 --- /dev/null +++ b/webapp/src/redux.tsx @@ -0,0 +1,29 @@ +import {combineReducers, Store, Action} from 'redux'; +import {GlobalState} from '@mattermost/types/lib/store'; + +import {callsPostButtonClickedHandler} from './calls_button'; + +type WebappStore = Store>> + +const CallsClickHandler = 'calls_post_button_clicked_handler'; + +export async function setupRedux(registry: any, store: WebappStore) { + const reducer = combineReducers({ + callsPostButtonClicked, + }); + + registry.registerReducer(reducer); + store.dispatch({ + type: CallsClickHandler as any, + handler: callsPostButtonClickedHandler, + }); +} + +function callsPostButtonClicked(state = false, action: any) { + switch (action.type) { + case CallsClickHandler: + return action.handler || false; + default: + return state; + } +}