This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quickfix: fix 'getState' error after insomnia update
- Loading branch information
Loïc Damet
committed
Aug 25, 2023
1 parent
dbb2afc
commit c6a7a3d
Showing
2 changed files
with
31 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,30 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import { BaseDoc } from './insomnia.types' | ||
|
||
let store: any = null | ||
let router: any = null | ||
|
||
export const getStore = (): any => { | ||
if (!store) { | ||
const root = document.querySelector('#root') as Record<string, any> | ||
const parameter = Object.getOwnPropertyNames(root).findLast(x => x.startsWith('__reactContainer')) as string | ||
store = root[parameter].memoizedState.element.props.store | ||
var getRouter = (): any => { | ||
if (!router) { | ||
const root = document.querySelector("#root") as Record<string, any>; | ||
Check failure on line 8 in src/insomnia/state.ts GitHub Actions / build (16.x)
|
||
if (!root) { | ||
return; | ||
} | ||
const parameter = Object.getOwnPropertyNames(root).findLast((x) => x.startsWith("__reactContainer")); | ||
Check failure on line 12 in src/insomnia/state.ts GitHub Actions / build (16.x)
|
||
router = root[parameter as string]?.memoizedState?.element?.props?.router; | ||
} | ||
return router; | ||
}; | ||
|
||
return store | ||
} | ||
|
||
export const getState = (): any => { | ||
const store = getStore() | ||
return store.getState() | ||
} | ||
export const getState = () => { | ||
const router = getRouter(); | ||
return router?.state; | ||
}; | ||
|
||
export const getActiveWorkspace = (): BaseDoc => { | ||
const state = getState() | ||
const workspaceId = state.global.activeWorkspaceId | ||
const workspace = state.entities.workspaces[workspaceId] | ||
return workspace | ||
export const getActiveWorkspaceId = (): string => { | ||
const state = getState(); | ||
return state?.loaderData[":workspaceId"].activeWorkspace._id | ||
} | ||
|
||
export const getActiveEnvironment = (): BaseDoc | null => { | ||
const state = getState() | ||
const activeWorkspaceId = getActiveWorkspace()._id | ||
const activeWorkspaceMeta = (Object.values(state.entities.workspaceMetas) as any[]).find(x => x.parentId === activeWorkspaceId) as BaseDoc | ||
const activeEnvironmentId = activeWorkspaceMeta.activeEnvironmentId | ||
const activeEnvironment = state.entities.environments[activeEnvironmentId] ?? null as (BaseDoc | null) | ||
|
||
return activeEnvironment | ||
export const getActiveEnvironmentId = (): string => { | ||
const state = getState(); | ||
return state?.loaderData[":workspaceId"].activeEnvironment._id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters