refactor: remove restore tab popup and its functionalities (#3867)

This commit is contained in:
Nivedin
2024-03-05 18:14:41 +05:30
committed by GitHub
parent a0c6b22641
commit 4798d7bbbd
13 changed files with 21 additions and 341 deletions

View File

@@ -1,11 +0,0 @@
mutation UpdateUserSession(
$currentSession: String!
$sessionType: SessionType!
) {
updateUserSessions(
currentSession: $currentSession
sessionType: $sessionType
) {
currentRESTSession
}
}

View File

@@ -1,5 +0,0 @@
query GetCurrentRESTSession {
me {
currentRESTSession
}
}

View File

@@ -4,7 +4,6 @@ import { def as environmentsDef } from "./platform/environments/environments.pla
import { def as collectionsDef } from "./platform/collections/collections.platform"
import { def as settingsDef } from "./platform/settings/settings.platform"
import { def as historyDef } from "./platform/history/history.platform"
import { def as tabStateDef } from "./platform/tabState/tabState.platform"
import { proxyInterceptor } from "@hoppscotch/common/platform/std/interceptors/proxy"
import { ExtensionInspectorService } from "@hoppscotch/common/platform/std/inspections/extension.inspector"
import { NativeInterceptorService } from "./platform/interceptors/native"
@@ -46,7 +45,6 @@ const headerPaddingTop = ref("0px")
collections: collectionsDef,
settings: settingsDef,
history: historyDef,
tabState: tabStateDef,
},
interceptors: {
default: "native",
@@ -97,17 +95,18 @@ const headerPaddingTop = ref("0px")
}
})()
function isTextInput(target: EventTarget | null) {
if (target instanceof HTMLInputElement) {
return target.type === 'text'
|| target.type === 'email'
|| target.type === 'password'
|| target.type === 'number'
|| target.type === 'search'
|| target.type === 'tel'
|| target.type === 'url'
|| target.type === 'textarea'
return (
target.type === "text" ||
target.type === "email" ||
target.type === "password" ||
target.type === "number" ||
target.type === "search" ||
target.type === "tel" ||
target.type === "url" ||
target.type === "textarea"
)
} else if (target instanceof HTMLTextAreaElement) {
return true
} else if (target instanceof HTMLElement && target.isContentEditable) {
@@ -117,8 +116,12 @@ function isTextInput(target: EventTarget | null) {
return false
}
window.addEventListener('keydown',function(e){
if (e.key === "Backspace" && !isTextInput(e.target)) {
e.preventDefault()
}
},true);
window.addEventListener(
"keydown",
function (e) {
if (e.key === "Backspace" && !isTextInput(e.target)) {
e.preventDefault()
}
},
true
)

View File

@@ -1,36 +0,0 @@
import {
runMutation,
runGQLQuery,
} from "@hoppscotch/common/helpers/backend/GQLClient"
import {
GetCurrentRestSessionDocument,
GetCurrentRestSessionQuery,
GetCurrentRestSessionQueryVariables,
SessionType,
UpdateUserSessionDocument,
UpdateUserSessionMutation,
UpdateUserSessionMutationVariables,
} from "../../api/generated/graphql"
export const updateUserSession = (
currentSession: string,
sessionType: SessionType
) =>
runMutation<
UpdateUserSessionMutation,
UpdateUserSessionMutationVariables,
""
>(UpdateUserSessionDocument, {
sessionType,
currentSession,
})()
export const getCurrentRestSession = () =>
runGQLQuery<
GetCurrentRestSessionQuery,
GetCurrentRestSessionQueryVariables,
""
>({
query: GetCurrentRestSessionDocument,
variables: {},
})

View File

@@ -1,37 +0,0 @@
import { PersistableRESTTabState } from "@hoppscotch/common/helpers/rest/tab"
import { HoppUser } from "@hoppscotch/common/platform/auth"
import { TabStatePlatformDef } from "@hoppscotch/common/platform/tab"
import { def as platformAuth } from "@platform/auth"
import { getCurrentRestSession, updateUserSession } from "./tabState.api"
import { SessionType } from "../../api/generated/graphql"
import * as E from "fp-ts/Either"
async function writeCurrentTabState(
_: HoppUser,
persistableTabState: PersistableRESTTabState
) {
await updateUserSession(JSON.stringify(persistableTabState), SessionType.Rest)
}
async function loadTabStateFromSync(): Promise<PersistableRESTTabState | null> {
const currentUser = platformAuth.getCurrentUser()
if (!currentUser)
throw new Error("Cannot load request from sync without login")
const res = await getCurrentRestSession()
if (E.isRight(res)) {
const currentRESTSession = res.right.me.currentRESTSession
return currentRESTSession ? JSON.parse(currentRESTSession) : null
} else {
}
return null
}
export const def: TabStatePlatformDef = {
loadTabStateFromSync,
writeCurrentTabState,
}