mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 02:35:14 +00:00
Added plugins store
This commit is contained in:
parent
f97399de07
commit
26d9dbd246
1 changed files with 41 additions and 0 deletions
41
frontend/src/store/plugins.jsx
Normal file
41
frontend/src/store/plugins.jsx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { create } from 'zustand';
|
||||
import API from '../api';
|
||||
|
||||
export const usePluginStore = create((set, get) => ({
|
||||
plugins: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
fetchPlugins: async () => {
|
||||
set({ loading: true, error: null });
|
||||
try {
|
||||
const response = await API.getPlugins();
|
||||
set({ plugins: response || [], loading: false });
|
||||
} catch (error) {
|
||||
set({ error, loading: false });
|
||||
}
|
||||
},
|
||||
|
||||
updatePlugin: (key, updates) => {
|
||||
set((state) => ({
|
||||
plugins: state.plugins.map((p) =>
|
||||
p.key === key ? { ...p, ...updates } : p
|
||||
),
|
||||
}));
|
||||
},
|
||||
|
||||
addPlugin: (plugin) => {
|
||||
set((state) => ({ plugins: [...state.plugins, plugin] }));
|
||||
},
|
||||
|
||||
removePlugin: (key) => {
|
||||
set((state) => ({
|
||||
plugins: state.plugins.filter((p) => p.key !== key),
|
||||
}));
|
||||
},
|
||||
|
||||
invalidatePlugins: () => {
|
||||
set({ plugins: [] });
|
||||
get().fetchPlugins();
|
||||
},
|
||||
}));
|
||||
Loading…
Add table
Add a link
Reference in a new issue