mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-11 23:54:52 +09:00
Players on the watch list are announced to every online admin on every instance when they join, and the join is posted to the Discord and JSON webhooks. The Reports page has a second table for the watch list with an Add button and a Delete button per row. Reports can be marked read or unread from the web interface. Each report row also has an Add to watch list button which opens the add form filled in with the player and reason. Setting exp_reports.watch_unread_reports treats players with unread reports as watched. Reports now store created_at_ms because marking them read changes updated_at_ms. Old reports.json files migrate on load with updated_at_ms as the creation time. The report webhook moved from the datastore update listener to the create handler so reading a report is not posted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import React, { useCallback, useSyncExternalStore } from "react";
|
|
import { WebPluginContext } from "@clusterio/web_ui";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
import * as messages from "../messages.js";
|
|
|
|
import ReportsPage from "./components/ReportsPage";
|
|
|
|
let reports: lib.MapSubscriber<messages.ReportUpdatedEvent> | undefined;
|
|
let watchList: lib.MapSubscriber<messages.WatchListUpdatedEvent> | undefined;
|
|
|
|
export function useReports() {
|
|
const subscribe = useCallback((cb: () => void) => reports!.subscribe(cb), []);
|
|
return useSyncExternalStore(subscribe, () => reports!.getSnapshot());
|
|
}
|
|
|
|
export function useWatchList() {
|
|
const subscribe = useCallback((cb: () => void) => watchList!.subscribe(cb), []);
|
|
return useSyncExternalStore(subscribe, () => watchList!.getSnapshot());
|
|
}
|
|
|
|
export default function registerPlugin(context: WebPluginContext) {
|
|
context.control.hooks.pages.attach("exp_reports", () => [
|
|
{
|
|
path: "/reports",
|
|
sidebarName: "Reports",
|
|
permission: "exp_reports.report.list",
|
|
content: <ReportsPage />,
|
|
},
|
|
]);
|
|
|
|
reports = new lib.MapSubscriber(messages.ReportUpdatedEvent, context.control);
|
|
watchList = new lib.MapSubscriber(messages.WatchListUpdatedEvent, context.control);
|
|
}
|