Integrate PSQL shell in quick start guide (#1333)

This commit is contained in:
victor-meng
2022-10-06 11:32:19 -07:00
committed by GitHub
parent 8433a027ad
commit e909ac43f4
13 changed files with 235 additions and 109 deletions

26
src/hooks/useTerminal.ts Normal file
View File

@@ -0,0 +1,26 @@
import postRobot from "post-robot";
import create, { UseStore } from "zustand";
interface TerminalState {
terminalWindow: Window;
setTerminal: (terminalWindow: Window) => void;
sendMessage: (message: string) => void;
}
export const useTerminal: UseStore<TerminalState> = create((set, get) => ({
terminalWindow: undefined,
setTerminal: (terminalWindow: Window) => {
set({ terminalWindow });
},
sendMessage: (message: string) => {
const terminalWindow = get().terminalWindow;
postRobot.send(
terminalWindow,
"sendMessage",
{ type: "stdin", content: [message] },
{
domain: window.location.origin,
}
);
},
}));