mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-05 23:27:55 +02:00
BUGFIX: Fix unresolved promise in ns.prompt API (#1257)
This commit is contained in:
@@ -18,19 +18,31 @@ interface Prompt {
|
||||
|
||||
export function PromptManager({ hidden }: { hidden: boolean }): React.ReactElement {
|
||||
const [prompt, setPrompt] = useState<Prompt | null>(null);
|
||||
|
||||
const resolveCurrentPromptWithDefaultValue = (currentPrompt: Prompt) => {
|
||||
if (["text", "select"].includes(currentPrompt.options?.type ?? "")) {
|
||||
currentPrompt.resolve("");
|
||||
} else {
|
||||
currentPrompt.resolve(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return PromptEvent.subscribe((p: Prompt) => {
|
||||
setPrompt(p);
|
||||
return PromptEvent.subscribe((newPrompt: Prompt) => {
|
||||
setPrompt((currentPrompt) => {
|
||||
if (currentPrompt) {
|
||||
resolveCurrentPromptWithDefaultValue(currentPrompt);
|
||||
}
|
||||
return newPrompt;
|
||||
});
|
||||
});
|
||||
}, []);
|
||||
|
||||
function close(): void {
|
||||
if (prompt === null) return;
|
||||
if (["text", "select"].includes(prompt.options?.type ?? "")) {
|
||||
prompt.resolve("");
|
||||
} else {
|
||||
prompt.resolve(false);
|
||||
if (prompt === null) {
|
||||
return;
|
||||
}
|
||||
resolveCurrentPromptWithDefaultValue(prompt);
|
||||
setPrompt(null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user