feat(web): W3-2 library, subscriptions and rules, preferences, decisions inbox, identity and metadata
- library list (kind/status/search, cursor paging) and detail: paths and roots, external identity mapping with lock, field-level metadata sources and locks, slot cards with rejection reasons, content units (provisional flag), downloads with verification; remap/lock/refresh/merge actions - subscriptions: list/create/update, slot rules editor (hard/soft/upgrade/completion), policy revision draft -> preview -> publish (grant warning) -> rollback - preferences: tag CRUD, disable/enable, suppression records and lift, history timeline - inbox: grouped by entity and kind, evidence/suggestion/impact/preview, resolve options, SSE refresh - identity: pool assign/dismiss/retry, external identity revisions and lock, title alias management - all responses validated against contracts zod schemas Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e5e42b1f0d
commit
ef73abe3df
25 files changed
+6670
-19
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
AcquisitionSlot,
|
||||
type AcquisitionSlotCreate,
|
||||
type AcquisitionSlotUpdate,
|
||||
cursorPage,
|
||||
type SlotStatus,
|
||||
} from "@umt/contracts";
|
||||
import { api } from "~/lib/api.ts";
|
||||
import { getParsed, parseOrThrow } from "./library.ts";
|
||||
|
||||
// 收录目标 Slot:硬条件 / 软偏好 / 回退 / 升级阈值 / 完成条件(REQ §6.1)
|
||||
|
||||
export const slotKeys = {
|
||||
all: ["slots"] as const,
|
||||
list: (f: SlotFilters) => ["slots", "list", f] as const,
|
||||
};
|
||||
|
||||
export type SlotFilters = { mediaEntityId?: string; status?: SlotStatus };
|
||||
|
||||
const Page = cursorPage(AcquisitionSlot);
|
||||
|
||||
export function useSlots(filters: SlotFilters, enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: slotKeys.list(filters),
|
||||
enabled,
|
||||
queryFn: ({ signal }) => getParsed(Page, "/acquisition-slots", { ...filters, limit: 200 }, signal),
|
||||
});
|
||||
}
|
||||
|
||||
function useInvalidate() {
|
||||
const qc = useQueryClient();
|
||||
return () => {
|
||||
void qc.invalidateQueries({ queryKey: slotKeys.all });
|
||||
void qc.invalidateQueries({ queryKey: ["library"] });
|
||||
};
|
||||
}
|
||||
|
||||
export function useCreateSlot() {
|
||||
const done = useInvalidate();
|
||||
return useMutation({
|
||||
mutationFn: (body: AcquisitionSlotCreate) =>
|
||||
api.post<unknown>("/acquisition-slots", body).then((d) => parseOrThrow(AcquisitionSlot, d, "/acquisition-slots")),
|
||||
onSuccess: done,
|
||||
});
|
||||
}
|
||||
|
||||
/** 规则修改带 expectedRevision(乐观并发);status 只由状态机推进 */
|
||||
export function useUpdateSlot() {
|
||||
const done = useInvalidate();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...body }: AcquisitionSlotUpdate & { id: string }) =>
|
||||
api
|
||||
.patch<unknown>(`/acquisition-slots/${id}`, body)
|
||||
.then((d) => parseOrThrow(AcquisitionSlot, d, "/acquisition-slots")),
|
||||
onSuccess: done,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user