mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-14 00:01:03 +00:00
40fa8c6fe6
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.
32 lines
887 B
TypeScript
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 };
|
|
}
|