Files
discord-decomp/modules/keyboard/native/PortalKeyboardUIStore.native.tsx
T
2026-11-01 12:12:55 +02:00

86 lines
2.7 KiB
TypeScript

// Metro module 4056 (f4057).
import { createZustandStore } from "../../../lib/ZustandStore";
import { PortalKeyboardState } from "./PortalKeyboard";
import { v4 } from "../../../_bundle/Module514";
const zustandStore = (0, createZustandStore)(() => ({
keyboard: null,
state: PortalKeyboardState.EMPTY,
renderers: []
}));
const r18 = {
getField: zustandStore.getField,
useField: zustandStore.useField
};
export { r18 as PortalKeyboardUIStore };
export function isPortalKeyboardOpenForChannel(a0) {
const state = zustandStore.getState();
const state2 = state.state;
return state.keyboard?.channelId === a0 && (state2 === PortalKeyboardState.REQUEST_OPEN || state2 === PortalKeyboardState.OPENING || state2 === PortalKeyboardState.OPEN);
}
export function openPortalKeyboard(a0, a1, a2) {
const state = zustandStore.getState();
const { state: state2, keyboard } = state;
let r17 = keyboard?.type === a0 && keyboard?.channelId === a1;
const r26 = state2 === PortalKeyboardState.REQUEST_OPEN || state2 === PortalKeyboardState.OPENING || state2 === PortalKeyboardState.OPEN;
if (r17) {
r17 = r26;
}
if (!r17) {
zustandStore.setState({
keyboard: {
id: v4(),
type: a0,
channelId: a1,
chatInputRef: a2
},
state: PortalKeyboardState.REQUEST_OPEN
});
}
}
export function registerPortalKeyboardRenderer(c13814_0) {
zustandStore.setState((state) => {
const renderers = state.renderers;
return renderers.includes(c13814_0) ? state : {
renderers: [...state.renderers, c13814_0]
};
});
return () => {
zustandStore.setState((state) => ({
renderers: state.renderers.filter((renderer) => renderer !== c13814_0)
}));
};
}
export function handlePortalKeyboardOpen(handlerId) {
zustandStore.setState((a0) => a0.keyboard != null ? a0.keyboard.handlerId !== handlerId ? {
keyboard: {
...a0.keyboard,
handlerId
},
state: PortalKeyboardState.OPEN
} : a0 : a0);
}
export function closePortalKeyboard() {
zustandStore.setState({
state: PortalKeyboardState.CLOSED,
keyboard: null
});
}
export function closePortalKeyboardIfUnhandled() {
const state2 = zustandStore.getState();
const { keyboard, state } = state2;
if (!(keyboard == null && state === PortalKeyboardState.CLOSED) && keyboard?.handlerId == null) {
zustandStore.setState({
state: PortalKeyboardState.CLOSED,
keyboard: null
});
}
}
export function closePortalKeyboardRequest() {
const field = zustandStore.getField("state");
if (field !== PortalKeyboardState.CLOSED && field !== PortalKeyboardState.REQUEST_CLOSE) {
zustandStore.setState({
state: PortalKeyboardState.REQUEST_CLOSE
});
}
}