mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-25 15:43:12 +09:00
Fix following upstream plugin changes
This commit is contained in:
3 files changed
+18
-17
No files matched your search
+12
-14
@@ -1,24 +1,22 @@
|
||||
import React, { useCallback, useSyncExternalStore } from "react";
|
||||
import { BaseWebPlugin } from "@clusterio/web_ui";
|
||||
import { WebPluginContext } from "@clusterio/web_ui";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as messages from "../messages.js";
|
||||
|
||||
import RoleProperties from "./components/RoleProperties";
|
||||
|
||||
export class WebPlugin extends BaseWebPlugin {
|
||||
roles = new lib.MapSubscriber(messages.RoleUpdatedEvent, this.control);
|
||||
let roles: lib.MapSubscriber<messages.RoleUpdatedEvent> | undefined;
|
||||
|
||||
async init() {
|
||||
// The core components pass a role and the plugin, which componentExtra
|
||||
// does not carry in its type
|
||||
this.componentExtra = {
|
||||
RoleViewPage: RoleProperties as React.ComponentType,
|
||||
};
|
||||
}
|
||||
export function useRoles() {
|
||||
const subscribe = useCallback((cb: () => void) => roles!.subscribe(cb), []);
|
||||
return useSyncExternalStore(subscribe, () => roles!.getSnapshot());
|
||||
}
|
||||
|
||||
useRoles() {
|
||||
const subscribe = useCallback((cb: () => void) => this.roles.subscribe(cb), []);
|
||||
return useSyncExternalStore(subscribe, () => this.roles.getSnapshot());
|
||||
}
|
||||
export default function registerPlugin(context: WebPluginContext) {
|
||||
context.control.hooks.extensionComponents.attach("exp_roles", () => ({
|
||||
RoleViewPage: RoleProperties,
|
||||
}));
|
||||
|
||||
roles = new lib.MapSubscriber(messages.RoleUpdatedEvent, context.control);
|
||||
}
|
||||
Reference in new issue
Block a user