Skip to content

Commit

Permalink
fix: re-connect on details changed
Browse files Browse the repository at this point in the history
fixes #217
  • Loading branch information
macjuul committed Apr 25, 2024
1 parent e9c31b4 commit 8a6dab3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/components/Scaffold/modals/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ConnectionDetails } from "../../ConnectionDetails";
import { useSetting } from "~/hooks/config";
import { useIntent } from "~/hooks/url";
import { useDatabaseStore } from "~/stores/database";
import { openConnection } from "~/connection";

function buildName(n: number) {
return `New connection ${n ? n + 1 : ""}`.trim();
Expand Down Expand Up @@ -59,6 +60,7 @@ export function ConnectionEditor() {
}

updateTitle();
openConnection();
});

const generateName = useStable(() => {
Expand Down
7 changes: 4 additions & 3 deletions src/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ConnectedEvent, DisconnectedEvent } from './util/global-events';
import { useInterfaceStore } from "./stores/interface";
import { useConfigStore } from "./stores/config";
import { compare } from "semver";
import { objectify } from "radash";
import { objectify, sleep } from "radash";
import { getLiveQueries } from "./util/surrealql";

const printMsg = (...args: any[]) => printLog("Conn", "#1cccfc", ...args);
Expand Down Expand Up @@ -150,11 +150,12 @@ export async function openConnection(options?: ConnectOptions) {
/**
* Close the active surreal connection
*/
export function closeConnection() {
export async function closeConnection() {
const status = SURREAL.status;

if (status === "connected" || status === "connecting") {
return SURREAL.close();
await SURREAL.close();
await sleep(100);
}
}

Expand Down

0 comments on commit 8a6dab3

Please sign in to comment.