Skip to content

Commit

Permalink
chore(Mattermost Plugin): Push command list from the client
Browse files Browse the repository at this point in the history
This way the client does not need to expose additional files and if the
client is refreshed, it can push the updated command help list.
  • Loading branch information
Dschoordsch committed Feb 7, 2025
1 parent 77eac0f commit 9446dc4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/mattermost-plugin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SidePanelRoot from './components/Sidepanel'
import PanelTitle from './components/Sidepanel/PanelTitle'
import manifest from './manifest'
import rootReducer, {
connect,
openCreateTaskModal,
openInviteToMeetingModal,
openInviteToTeamModal,
Expand All @@ -19,6 +20,7 @@ import AtmosphereProvider from './AtmosphereProvider'
import AutoLogin from './components/AutoLogin'
import ModalRoot from './components/ModalRoot'
import './index.css'
import commands from './public/mattermost-plugin-commands.json'

export const init = async (registry: PluginRegistry, store: Store<GlobalState, AnyAction>) => {
const serverUrl = getPluginServerRoute(store.getState())
Expand Down Expand Up @@ -73,6 +75,8 @@ export const init = async (registry: PluginRegistry, store: Store<GlobalState, A
store.dispatch(openInviteToMeetingModal())
})

store.dispatch(connect({commands}) as any)

registry.registerPostDropdownMenuAction(
<div>
<span className='MenuItem__icon'>
Expand Down
24 changes: 24 additions & 0 deletions packages/mattermost-plugin/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ export const removeTeamFromChannel = createAsyncThunk(
}
)

export type Command = {
trigger: string
description: string
}

export type ClientConfig = {
commands: Command[]
}

export const connect = createAsyncThunk('connect', async (config: ClientConfig, thunkApi) => {
const serverUrl = getPluginServerRoute(thunkApi.getState() as any)
const res = await fetch(
`${serverUrl}/connect`,
Client4.getOptions({
method: 'POST',
body: JSON.stringify(config)
})
)
if (!res.ok) {
throw new Error(`Failed to initialize commands: ${res.statusText}`)
}
return
})

const localSlice = createSlice({
name: 'local',
initialState: {
Expand Down

0 comments on commit 9446dc4

Please sign in to comment.