Files
TREK/client/src/components/Admin/plugins/usePluginDetail.ts
T
Maurice 40fa8c6fe6 refactor(plugins): share the plugin admin logic between desktop and phone
Both panels carried the same types, helpers and a four hundred line block of state and handlers. pluginModel now holds the types and pure helpers, usePluginsAdmin the state, loading and every action, and usePluginDetail the registry detail fetch. The phone keeps starting all updates at once from Update all and reads the detail manifest under its stricter shape; both panels keep their own markup, dialogs and sheets.
2026-10-09 15:19:45 +02:00

32 lines
887 B
TypeScript

import { useEffect, useState } from 'react';
import { adminApi } from '../../../api/client';
import type { RegistryDetail } from './pluginModel';
/**
* The registry detail of one plugin, behind both shells' detail views (the desktop modal
* and the phone sheet). Fetched once per id; a response for an id the view has moved off
* is dropped. `D` lets a shell read the detail under its own stricter shape.
*/
export function usePluginDetail<D = RegistryDetail>(id: string) {
const [detail, setDetail] = useState<D | null>(null);
const [failed, setFailed] = useState(false);
useEffect(() => {
let alive = true;
adminApi
.pluginDetail(id)
.then((d: D) => {
if (alive) setDetail(d);
})
.catch(() => {
if (alive) setFailed(true);
});
return () => {
alive = false;
};
}, [id]);
return { detail, failed };
}