Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/api/BbbPluginSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ export abstract class BbbPluginSdk {
* @returns The PluginApi object
*
*/
public static getPluginApi(uuid: string, pluginName?: string): PluginApi {
public static getPluginApi(
uuid: string,
pluginName?: string,
localesBaseUrl?: string,
): PluginApi {
if (!window.bbb_plugins) window.bbb_plugins = {};
if (Object.keys(window.bbb_plugins).indexOf(uuid) === -1) {
window.bbb_plugins[uuid] = {
Expand All @@ -186,6 +190,7 @@ export abstract class BbbPluginSdk {
},
getSessionToken: () => getSessionToken(),
pluginName,
localesBaseUrl,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/core/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type SetGenericContentItems = (
*/
export interface PluginApi {
pluginName?: string;
localesBaseUrl?: string;
// --- Extensible Areas Setters ---
setPresentationToolbarItems: SetPresentationToolbarItems;
setUserListDropdownItems: SetUserListDropdownItems;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ interface PluginInformationResult {
localesBaseUrl: string;
}

interface GraphqlResponseWrapper {
plugin: PluginInformationResult[];
}

interface IntlMessages {
loading: boolean;
messages: Record<string, string>;
Expand All @@ -26,7 +22,6 @@ type UseLocaleMessagesFunction = (fetchConfigs?: RequestInit) => IntlMessages;
export {
UseLocaleMessagesProps,
PluginInformationResult,
GraphqlResponseWrapper,
IntlMessages,
UseLocaleMessagesFunction,
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from 'react';
import { IntlLocaleUiDataNames } from '../../../../ui-data-hooks';
import { pluginLogger } from '../../../../utils';
import { GraphqlResponseWrapper, IntlMessages, UseLocaleMessagesProps } from './types';
import { GET_PLUGIN_INFORMATION } from './subscriptions';
import { IntlMessages, UseLocaleMessagesProps } from './types';

function useLocaleMessagesAuxiliary(
{ pluginApi, fetchConfigs }: UseLocaleMessagesProps,
Expand All @@ -15,13 +14,9 @@ function useLocaleMessagesAuxiliary(
const [loading, setLoading] = React.useState(true);
const [messages, setMessages] = React.useState<Record<string, string>>({});

const { data: pluginInformation } = pluginApi.useCustomSubscription!<GraphqlResponseWrapper>(
GET_PLUGIN_INFORMATION,
);

React.useEffect(() => {
if (pluginInformation && pluginInformation.plugin && currentLocale.locale) {
const { localesBaseUrl } = pluginInformation.plugin[0];
if (pluginApi?.localesBaseUrl && currentLocale.locale) {
const { localesBaseUrl } = pluginApi;
const { locale } = currentLocale;
const localeUrl = `${localesBaseUrl}/${locale}.json`;
fetch(localeUrl, fetchConfigs).then((result) => result.json()).then((localeMessages) => {
Expand All @@ -32,7 +27,7 @@ function useLocaleMessagesAuxiliary(
pluginLogger.error(`Something went wrong while trying to fetch ${localeUrl}: `, err);
});
}
}, [pluginInformation, currentLocale]);
}, [currentLocale]);
return {
messages,
loading,
Expand Down