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.
This commit is contained in:
Maurice
2026-10-09 11:03:01 +02:00
parent a99b0c5b32
commit 40fa8c6fe6
8 changed files with 1820 additions and 1545 deletions
@@ -0,0 +1,31 @@
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 };
}