mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 06:35:24 +00:00
fix: refresh plugin settings after enabling a plugin and match select and disabled bar styling
This commit is contained in:
1 parent
27819c477c
commit
8666533162
11 files changed
+136
-56
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
getPlugins,
|
||||
PLUGINS_CHANGED_EVENT,
|
||||
type PluginSummary,
|
||||
} from "@/api/plugins-api";
|
||||
|
||||
/**
|
||||
* Every installed plugin, read again whenever one is enabled, disabled,
|
||||
* installed or removed, so what a plugin adds shows up without a reload.
|
||||
*/
|
||||
export function useInstalledPlugins(): PluginSummary[] {
|
||||
const [plugins, setPlugins] = useState<PluginSummary[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
let request = 0;
|
||||
const load = () => {
|
||||
const current = ++request;
|
||||
void getPlugins()
|
||||
.then((loaded) => {
|
||||
if (!cancelled && current === request) setPlugins(loaded);
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
load();
|
||||
window.addEventListener(PLUGINS_CHANGED_EVENT, load);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
window.removeEventListener(PLUGINS_CHANGED_EVENT, load);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return plugins;
|
||||
}
|
||||
Reference in new issue
Block a user