Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch committed Oct 25, 2024
1 parent a1d166a commit 0fe2e38
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 47 deletions.
2 changes: 1 addition & 1 deletion webapp/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ string | FetchArgs,
unknown,
FetchBaseQueryError
> = async (args, api, extraOptions) => {
const baseUrl = getPluginServerRoute(api.getState())
const baseUrl = getPluginServerRoute(api.getState() as any)
const adjustedArgs =
typeof args === 'string' ? {
url: joinUrl(baseUrl, args),
Expand Down
28 changes: 0 additions & 28 deletions webapp/src/components/push_reflection/push_reflection_button.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import {useDispatch, useSelector} from 'react-redux'

import {getPost} from 'mattermost-redux/selectors/entities/posts'

import {GlobalState} from 'mattermost-redux/types/store'

import {useCreateReflectionMutation, useGetActiveMeetingsQuery} from '../../api'
import {closePushPostAsReflection} from '../../reducers'
import {getAssetsUrl, getPostURL, pushPostAsReflection} from '../../selectors'

const PostUtils = window.PostUtils
const PostUtils = (window as any).PostUtils

const PushReflectionModal = () => {
const postId = useSelector(pushPostAsReflection)
const post = useSelector((state) => getPost(state, postId))
const postUrl = useSelector((state) => getPostURL(state, postId))
const post = useSelector((state: GlobalState) => getPost(state, postId!))
const postUrl = useSelector((state: GlobalState) => getPostURL(state, postId!))

const {data, isLoading, refetch} = useGetActiveMeetingsQuery()
useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import {Store, AnyAction} from 'redux'

import {GlobalState} from '@mattermost/types/lib/store'

import {setupListeners} from '@reduxjs/toolkit/query'

import {GlobalState} from 'mattermost-redux/types/store'

import manifest from '@/manifest'

import {PluginRegistry} from '@/types/mattermost-webapp'
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
import {AnyAction, createSlice, PayloadAction} from '@reduxjs/toolkit'

import {api} from './api'

Expand Down Expand Up @@ -31,7 +31,9 @@ export const {
closePushPostAsReflection,
} = localSlice.actions

const rootReducer = (state, action) => {
export type PluginState = ReturnType<typeof localSlice.reducer> & ReturnType<typeof api.reducer>

const rootReducer = (state: PluginState, action: AnyAction) => {
const apiState = api.reducer(state, action)
const localState = localSlice.reducer(state, action)
return {
Expand Down
24 changes: 13 additions & 11 deletions webapp/src/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import {getConfig} from 'mattermost-redux/selectors/entities/general'
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'

import {GlobalState} from 'mattermost-redux/types/store'

import manifest from '@/manifest'

import {PluginState} from './reducers'

const {id} = manifest

export const getSiteURL = (state) => {
export const getSiteURL = (state: GlobalState) => {
const config = getConfig(state)
return config?.SiteURL ?? ''
}

export const getCurrentTeamURL = (state) => {
export const getCurrentTeamURL = (state: GlobalState) => {
const siteURL = getSiteURL(state)
const team = getCurrentTeam(state)
return `${siteURL}/${team?.name ?? ''}`
}

export const getPostURL = (state, postId) => {
export const getPostURL = (state: GlobalState, postId: string) => {
const teamURL = getCurrentTeamURL(state)
return `${teamURL}/pl/${postId}`
}

export const getPluginRoot = (state) => {
export const getPluginRoot = (state: GlobalState) => {
const config = getConfig(state)
const siteURL = config?.SiteURL ?? ''
return `${siteURL}/plugins/${id}`
}

export const getPluginServerRoute = (state) => {
export const getPluginServerRoute = (state: GlobalState) => {
let basePath = ''
const config = getConfig(state)
const siteURL = config?.SiteURL ?? ''
Expand All @@ -42,17 +46,15 @@ export const getPluginServerRoute = (state) => {
return `${basePath}/plugins/${id}`
}

export const getAssetsUrl = (state) => {
export const getAssetsUrl = (state: GlobalState) => {
const siteURL = getPluginRoot(state)
return `${siteURL}/public`
}

export const getPluginState = (state) => state[`plugins-${id}`] ?? {}

export const meetingTemplates = (state) => getPluginState(state).meetingTemplates
export const getPluginState = (state: GlobalState) => ((state as any)[`plugins-${id}`] ?? {}) as PluginState

export const isStartActivityModalVisible = (state) => getPluginState(state).isStartActivityModalVisible
export const isStartActivityModalVisible = (state: GlobalState) => getPluginState(state).isStartActivityModalVisible

export const pushPostAsReflection = (state) => getPluginState(state).pushPostAsReflection
export const pushPostAsReflection = (state: GlobalState) => getPluginState(state).pushPostAsReflection

//export const get

0 comments on commit 0fe2e38

Please sign in to comment.