Skip to content
Snippets Groups Projects
Commit f20322f7 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '277-opening-plugin-multiple-times-should-be-not-possible' into 'development'

Resolve "opening plugin multiple times should be not possible"

Closes #277

See merge request !216
parents a3e63e12 b56696f4
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!216Resolve "opening plugin multiple times should be not possible"
Pipeline #93320 passed
export const PLUGIN_LOADING_ERROR_PREFIX = 'Failed to load plugin';
export const PLUGIN_LOADING_TWICE_ERROR = 'Plugin cannot be loaded more than once';
import { PluginsManager } from '@/services/pluginsManager';
import axios from 'axios';
import { ChangeEvent, useMemo, useState, KeyboardEvent } from 'react';
import { ENTER_KEY_CODE } from '@/constants/common';
import { ENTER_KEY_CODE, ZERO } from '@/constants/common';
import { showToast } from '@/utils/showToast';
import { getErrorMessage } from '@/utils/getErrorMessage';
import { PLUGIN_LOADING_ERROR_PREFIX } from '../../AvailablePluginsDrawer.constants';
import md5 from 'crypto-js/md5';
import {
PLUGIN_LOADING_ERROR_PREFIX,
PLUGIN_LOADING_TWICE_ERROR,
} from '../../AvailablePluginsDrawer.constants';
type UseLoadPluginReturnType = {
handleChangePluginUrl: (event: ChangeEvent<HTMLInputElement>) => void;
......@@ -29,6 +33,20 @@ export const useLoadPluginFromUrl = (): UseLoadPluginReturnType => {
const response = await axios(pluginUrl);
let pluginScript = response.data;
const hash = md5(pluginScript).toString();
if (
Array.isArray(PluginsManager.activePlugins[hash]) &&
PluginsManager.activePlugins[hash].length > ZERO
) {
setIsLoading(false);
showToast({
type: 'error',
message: PLUGIN_LOADING_TWICE_ERROR,
});
return;
}
PluginsManager.setHashedPlugin({
pluginUrl,
pluginScript,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment