plugin.tsx 886 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import useSWR, { SWRResponse } from 'swr';
  2. import { apiv3Get, apiv3Post } from '~/client/util/apiv3-client';
  3. // TODO: Correct types
  4. const pluginsFetcher = () => {
  5. return async() => {
  6. const reqUrl = '/plugins';
  7. try {
  8. const data = await apiv3Get(reqUrl);
  9. return data;
  10. }
  11. catch (err) {
  12. throw new Error(err);
  13. }
  14. };
  15. };
  16. export const useSWRxPlugins = (): SWRResponse<any | null, Error> => {
  17. return useSWR('/pluginsExtension', pluginsFetcher());
  18. };
  19. const pluginFetcher = (id: string) => {
  20. return async() => {
  21. const reqUrl = '/plugins/get-isenabled';
  22. try {
  23. const data = await apiv3Post(reqUrl, { _id: id });
  24. return data;
  25. }
  26. catch (err) {
  27. throw new Error(err);
  28. }
  29. };
  30. };
  31. export const useSWRxPlugin = (_id: string): SWRResponse<any | null, Error> => {
  32. return useSWR(`/plugin-${_id}`, pluginFetcher(_id));
  33. };