feat: pre-warn user of any enka error
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
"use client";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
icc: IccMutator;
|
||||
}
|
||||
}
|
||||
|
||||
import {
|
||||
createContext,
|
||||
use,
|
||||
@@ -17,12 +23,17 @@ type SharedStates = Partial<{
|
||||
"rubgram.services": string[];
|
||||
"tl.deleteMode": boolean;
|
||||
inspect: Record<string, string>;
|
||||
// nf(Not Found) and showcase(Not In Showcase) is error dialog that opens guide
|
||||
warning: "showcase" | "nf" | "guide" | "private";
|
||||
"warning.uid": string;
|
||||
"warning.src": "submit" | "input";
|
||||
_raw: Record<string, unknown>;
|
||||
}>;
|
||||
|
||||
type SharedSignals = {
|
||||
beforeSubmit?: undefined;
|
||||
sync?: undefined;
|
||||
warningSolved?: undefined;
|
||||
} & SharedStates;
|
||||
|
||||
type IccMutator = {
|
||||
@@ -105,6 +116,9 @@ export default function IccProvider({
|
||||
active: true,
|
||||
});
|
||||
|
||||
if (typeof window !== "undefined" && location.hostname === "localhost")
|
||||
window.icc = contextValue.current;
|
||||
|
||||
return <IccContext value={contextValue.current}>{children}</IccContext>;
|
||||
}
|
||||
|
||||
@@ -185,4 +199,12 @@ export const shared = {
|
||||
});
|
||||
}, [v]);
|
||||
},
|
||||
emit<K extends keyof SharedSignals>(
|
||||
key: K,
|
||||
...data: SharedSignals[K] extends undefined ? [] : [SharedSignals[K]]
|
||||
) {
|
||||
const comms = use(IccContext);
|
||||
|
||||
comms.emit(key, ...data);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user