Skip to content

Commit

Permalink
fix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mivasconcelos committed Oct 7, 2022
1 parent 28174b5 commit 4d44491
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
3 changes: 2 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"prettier":"prettier --write 'src/**/*.{tsx,ts}'"
"prettier":"prettier --write 'src/**/*.{tsx,ts}'",
"lint": "eslint --ext .ts,.tsx src/"
},
"dependencies": {
"@chakra-ui/icons": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/theme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extendTheme } from "@chakra-ui/react";
import "@fontsource/inter/variable-full.css";
// import "@fontsource/inter/variable-full.css";
import "@fontsource/source-code-pro/variable.css";

export const chakraTheme = extendTheme({
Expand Down
17 changes: 2 additions & 15 deletions web/src/data/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { SQLError } from "@/data/client";
import { isConnected, resetSchema, schemaObjects } from "@/data/queries";
import {
configScaleFactor,
connectionConfig,
portalConnectionConfig,
resettingSchema,
simulatorEnabled,
tickDurationMs,
Expand Down Expand Up @@ -49,22 +47,13 @@ export const useConnectionState = () => {
// we are using ES6 spread syntax to remove database from config
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { database, ...config } = useRecoilValue(connectionConfig);
let portalConfig;
let vaporConfig;

if (portalConnectionConfig) {
portalConfig = useRecoilValue(portalConnectionConfig);
} else if (vaporConnectionConfig) {
vaporConfig = useRecoilValue(vaporConnectionConfig);
}

const vaporConfig = useRecoilValue(vaporConnectionConfig);

const connected = useSWR(["isConnected", config], () => isConnected(config));
const schemaObjs = useSchemaObjects(!connected.data);

return {
isVapor: !!vaporConfig,
// if the connection is automatically done to Portal UI
isPortalUser: !!portalConfig,
connected: !!connected.data,
initialized:
!!connected.data && Object.values(schemaObjs.data || []).every(Boolean),
Expand Down Expand Up @@ -183,7 +172,6 @@ export const useResetSchema = ({
resetDataOnly: boolean;
}) => {
const config = useRecoilValue(connectionConfig);
const scaleFactor = useRecoilValue(configScaleFactor);
const [isSimulatorEnabled, setSimulatorEnabled] =
useRecoilState(simulatorEnabled);
const toast = useToast();
Expand Down Expand Up @@ -232,7 +220,6 @@ export const useResetSchema = ({
setResettingSchema,
before,
config,
scaleFactor,
includeSeedData,
resetDataOnly,
after,
Expand Down
7 changes: 4 additions & 3 deletions web/src/data/recoil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ConnectionConfig } from "@/data/client";
import { atom, AtomEffect, atomFamily, DefaultValue, selector } from "recoil";
import { ScaleFactor, ScaleFactors } from "../scalefactors";
import { useLocation } from "react-router-dom";

type LocalStorageEffectConfig<T> = {
encode: (v: T) => string;
Expand Down Expand Up @@ -114,9 +113,8 @@ export const vaporConnectionConfig = selector<ConnectionConfig | undefined>({
export const portalConnectionConfig = selector<ConnectionConfig | undefined>({
key: "portalConnectionConfig",
get: async ({ get }) => {
const { search } = useLocation();
const {search} = window.location;
if (search) {
console.log({ search });
const queryParams = new URLSearchParams(search);
const portalHostname = queryParams.get("hostname");
const portalCredentials = queryParams.get("credentials");
Expand All @@ -139,8 +137,11 @@ export const connectionConfig = selector<ConnectionConfig>({
key: "connectionConfig",
get: ({ get }) => {
const vaporConfig = get(vaporConnectionConfig);
const portalConfig = get(portalConnectionConfig);
if (vaporConfig) {
return vaporConfig;
} else if(portalConfig){
return portalConfig;
}

const host = get(connectionHost);
Expand Down

0 comments on commit 4d44491

Please sign in to comment.