refactor: remove restore tab popup and its functionalities (#3867)
This commit is contained in:
@@ -95,31 +95,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, onMounted, onBeforeUnmount } from "vue"
|
import { ref, onMounted } from "vue"
|
||||||
import { safelyExtractRESTRequest } from "@hoppscotch/data"
|
import { safelyExtractRESTRequest } from "@hoppscotch/data"
|
||||||
import { translateExtURLParams } from "~/helpers/RESTExtURLParams"
|
import { translateExtURLParams } from "~/helpers/RESTExtURLParams"
|
||||||
import { useRoute } from "vue-router"
|
import { useRoute } from "vue-router"
|
||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { getDefaultRESTRequest } from "~/helpers/rest/default"
|
import { getDefaultRESTRequest } from "~/helpers/rest/default"
|
||||||
import { defineActionHandler, invokeAction } from "~/helpers/actions"
|
import { defineActionHandler, invokeAction } from "~/helpers/actions"
|
||||||
import { onLoggedIn } from "~/composables/auth"
|
|
||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
import {
|
|
||||||
audit,
|
|
||||||
BehaviorSubject,
|
|
||||||
combineLatest,
|
|
||||||
EMPTY,
|
|
||||||
from,
|
|
||||||
map,
|
|
||||||
Subscription,
|
|
||||||
} from "rxjs"
|
|
||||||
import { useToast } from "~/composables/toast"
|
|
||||||
import { watchDebounced } from "@vueuse/core"
|
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
import { useReadonlyStream } from "~/composables/stream"
|
||||||
import {
|
|
||||||
changeCurrentSyncStatus,
|
|
||||||
currentSyncingStatus$,
|
|
||||||
} from "~/newstore/syncing"
|
|
||||||
import { useService } from "dioc/vue"
|
import { useService } from "dioc/vue"
|
||||||
import { InspectionService } from "~/services/inspection"
|
import { InspectionService } from "~/services/inspection"
|
||||||
import { HeaderInspectorService } from "~/services/inspection/inspectors/header.inspector"
|
import { HeaderInspectorService } from "~/services/inspection/inspectors/header.inspector"
|
||||||
@@ -127,7 +111,7 @@ import { EnvironmentInspectorService } from "~/services/inspection/inspectors/en
|
|||||||
import { ResponseInspectorService } from "~/services/inspection/inspectors/response.inspector"
|
import { ResponseInspectorService } from "~/services/inspection/inspectors/response.inspector"
|
||||||
import { cloneDeep } from "lodash-es"
|
import { cloneDeep } from "lodash-es"
|
||||||
import { RESTTabService } from "~/services/tab/rest"
|
import { RESTTabService } from "~/services/tab/rest"
|
||||||
import { HoppTab, PersistableTabState } from "~/services/tab"
|
import { HoppTab } from "~/services/tab"
|
||||||
import { HoppRESTDocument } from "~/helpers/rest/document"
|
import { HoppRESTDocument } from "~/helpers/rest/document"
|
||||||
|
|
||||||
const savingRequest = ref(false)
|
const savingRequest = ref(false)
|
||||||
@@ -140,7 +124,6 @@ const exceptedTabID = ref<string | null>(null)
|
|||||||
const renameTabID = ref<string | null>(null)
|
const renameTabID = ref<string | null>(null)
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
|
||||||
|
|
||||||
const tabs = useService(RESTTabService)
|
const tabs = useService(RESTTabService)
|
||||||
|
|
||||||
@@ -171,12 +154,6 @@ const contextMenu = ref<PopupDetails>({
|
|||||||
|
|
||||||
const activeTabs = tabs.getActiveTabs()
|
const activeTabs = tabs.getActiveTabs()
|
||||||
|
|
||||||
const confirmSync = useReadonlyStream(currentSyncingStatus$, {
|
|
||||||
isInitialSync: false,
|
|
||||||
shouldSync: true,
|
|
||||||
})
|
|
||||||
const tabStateForSync = ref<PersistableTabState<HoppRESTDocument> | null>(null)
|
|
||||||
|
|
||||||
function bindRequestToURLParams() {
|
function bindRequestToURLParams() {
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
// Get URL parameters and set that as the request
|
// Get URL parameters and set that as the request
|
||||||
@@ -327,111 +304,6 @@ const shareTabRequest = (tabID: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const syncTabState = () => {
|
|
||||||
if (tabStateForSync.value)
|
|
||||||
tabs.loadTabsFromPersistedState(tabStateForSync.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs sync of the REST Tab session with Firestore.
|
|
||||||
*
|
|
||||||
* @returns A subscription to the sync observable stream.
|
|
||||||
* Unsubscribe to stop syncing.
|
|
||||||
*/
|
|
||||||
function startTabStateSync(): Subscription {
|
|
||||||
const currentUser$ = platform.auth.getCurrentUserStream()
|
|
||||||
const tabState$ =
|
|
||||||
new BehaviorSubject<PersistableTabState<HoppRESTDocument> | null>(null)
|
|
||||||
|
|
||||||
watchDebounced(
|
|
||||||
tabs.persistableTabState,
|
|
||||||
(state) => {
|
|
||||||
tabState$.next(state)
|
|
||||||
},
|
|
||||||
{ debounce: 500, deep: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
const sub = combineLatest([currentUser$, tabState$])
|
|
||||||
.pipe(
|
|
||||||
map(([user, tabState]) =>
|
|
||||||
user && tabState
|
|
||||||
? from(platform.sync.tabState.writeCurrentTabState(user, tabState))
|
|
||||||
: EMPTY
|
|
||||||
),
|
|
||||||
audit((x) => x)
|
|
||||||
)
|
|
||||||
.subscribe(() => {
|
|
||||||
// NOTE: This subscription should be kept
|
|
||||||
})
|
|
||||||
|
|
||||||
return sub
|
|
||||||
}
|
|
||||||
|
|
||||||
const showSyncToast = () => {
|
|
||||||
toast.show(t("confirm.sync"), {
|
|
||||||
duration: 0,
|
|
||||||
action: [
|
|
||||||
{
|
|
||||||
text: `${t("action.yes")}`,
|
|
||||||
onClick: (_, toastObject) => {
|
|
||||||
syncTabState()
|
|
||||||
changeCurrentSyncStatus({
|
|
||||||
isInitialSync: true,
|
|
||||||
shouldSync: true,
|
|
||||||
})
|
|
||||||
toastObject.goAway(0)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: `${t("action.no")}`,
|
|
||||||
onClick: (_, toastObject) => {
|
|
||||||
changeCurrentSyncStatus({
|
|
||||||
isInitialSync: true,
|
|
||||||
shouldSync: false,
|
|
||||||
})
|
|
||||||
toastObject.goAway(0)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupTabStateSync() {
|
|
||||||
const route = useRoute()
|
|
||||||
|
|
||||||
// Subscription to request sync
|
|
||||||
let sub: Subscription | null = null
|
|
||||||
|
|
||||||
// Load request on login resolve and start sync
|
|
||||||
onLoggedIn(async () => {
|
|
||||||
if (
|
|
||||||
Object.keys(route.query).length === 0 &&
|
|
||||||
!(route.query.code || route.query.error)
|
|
||||||
) {
|
|
||||||
const tabStateFromSync =
|
|
||||||
await platform.sync.tabState.loadTabStateFromSync()
|
|
||||||
|
|
||||||
if (tabStateFromSync && !confirmSync.value.isInitialSync) {
|
|
||||||
tabStateForSync.value = tabStateFromSync
|
|
||||||
showSyncToast()
|
|
||||||
// Have to set isInitialSync to true here because the toast is shown
|
|
||||||
// and the user does not click on any of the actions
|
|
||||||
changeCurrentSyncStatus({
|
|
||||||
isInitialSync: true,
|
|
||||||
shouldSync: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub = startTabStateSync()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Stop subscription to stop syncing
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
sub?.unsubscribe()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
defineActionHandler("contextmenu.open", ({ position, text }) => {
|
defineActionHandler("contextmenu.open", ({ position, text }) => {
|
||||||
if (text) {
|
if (text) {
|
||||||
contextMenu.value = {
|
contextMenu.value = {
|
||||||
@@ -448,7 +320,6 @@ defineActionHandler("contextmenu.open", ({ position, text }) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setupTabStateSync()
|
|
||||||
bindRequestToURLParams()
|
bindRequestToURLParams()
|
||||||
|
|
||||||
defineActionHandler("rest.request.open", ({ doc }) => {
|
defineActionHandler("rest.request.open", ({ doc }) => {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { EnvironmentsPlatformDef } from "./environments"
|
|||||||
import { CollectionsPlatformDef } from "./collections"
|
import { CollectionsPlatformDef } from "./collections"
|
||||||
import { SettingsPlatformDef } from "./settings"
|
import { SettingsPlatformDef } from "./settings"
|
||||||
import { HistoryPlatformDef } from "./history"
|
import { HistoryPlatformDef } from "./history"
|
||||||
import { TabStatePlatformDef } from "./tab"
|
|
||||||
import { AnalyticsPlatformDef } from "./analytics"
|
import { AnalyticsPlatformDef } from "./analytics"
|
||||||
import { InterceptorsPlatformDef } from "./interceptors"
|
import { InterceptorsPlatformDef } from "./interceptors"
|
||||||
import { HoppModule } from "~/modules"
|
import { HoppModule } from "~/modules"
|
||||||
@@ -25,7 +24,6 @@ export type PlatformDef = {
|
|||||||
collections: CollectionsPlatformDef
|
collections: CollectionsPlatformDef
|
||||||
settings: SettingsPlatformDef
|
settings: SettingsPlatformDef
|
||||||
history: HistoryPlatformDef
|
history: HistoryPlatformDef
|
||||||
tabState: TabStatePlatformDef
|
|
||||||
}
|
}
|
||||||
interceptors: InterceptorsPlatformDef
|
interceptors: InterceptorsPlatformDef
|
||||||
additionalInspectors?: InspectorsPlatformDef
|
additionalInspectors?: InspectorsPlatformDef
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import { PersistableTabState } from "~/services/tab"
|
|
||||||
import { HoppUser } from "./auth"
|
|
||||||
import { HoppRESTDocument } from "~/helpers/rest/document"
|
|
||||||
|
|
||||||
export type TabStatePlatformDef = {
|
|
||||||
loadTabStateFromSync: () => Promise<PersistableTabState<HoppRESTDocument> | null>
|
|
||||||
writeCurrentTabState: (
|
|
||||||
user: HoppUser,
|
|
||||||
persistableTabState: PersistableTabState<HoppRESTDocument>
|
|
||||||
) => Promise<void>
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
mutation UpdateUserSession(
|
|
||||||
$currentSession: String!
|
|
||||||
$sessionType: SessionType!
|
|
||||||
) {
|
|
||||||
updateUserSessions(
|
|
||||||
currentSession: $currentSession
|
|
||||||
sessionType: $sessionType
|
|
||||||
) {
|
|
||||||
currentRESTSession
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
query GetCurrentRESTSession {
|
|
||||||
me {
|
|
||||||
currentRESTSession
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 collectionsDef } from "./platform/collections/collections.platform"
|
||||||
import { def as settingsDef } from "./platform/settings/settings.platform"
|
import { def as settingsDef } from "./platform/settings/settings.platform"
|
||||||
import { def as historyDef } from "./platform/history/history.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 { proxyInterceptor } from "@hoppscotch/common/platform/std/interceptors/proxy"
|
||||||
import { ExtensionInspectorService } from "@hoppscotch/common/platform/std/inspections/extension.inspector"
|
import { ExtensionInspectorService } from "@hoppscotch/common/platform/std/inspections/extension.inspector"
|
||||||
import { NativeInterceptorService } from "./platform/interceptors/native"
|
import { NativeInterceptorService } from "./platform/interceptors/native"
|
||||||
@@ -46,7 +45,6 @@ const headerPaddingTop = ref("0px")
|
|||||||
collections: collectionsDef,
|
collections: collectionsDef,
|
||||||
settings: settingsDef,
|
settings: settingsDef,
|
||||||
history: historyDef,
|
history: historyDef,
|
||||||
tabState: tabStateDef,
|
|
||||||
},
|
},
|
||||||
interceptors: {
|
interceptors: {
|
||||||
default: "native",
|
default: "native",
|
||||||
@@ -97,17 +95,18 @@ const headerPaddingTop = ref("0px")
|
|||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|
||||||
function isTextInput(target: EventTarget | null) {
|
function isTextInput(target: EventTarget | null) {
|
||||||
if (target instanceof HTMLInputElement) {
|
if (target instanceof HTMLInputElement) {
|
||||||
return target.type === 'text'
|
return (
|
||||||
|| target.type === 'email'
|
target.type === "text" ||
|
||||||
|| target.type === 'password'
|
target.type === "email" ||
|
||||||
|| target.type === 'number'
|
target.type === "password" ||
|
||||||
|| target.type === 'search'
|
target.type === "number" ||
|
||||||
|| target.type === 'tel'
|
target.type === "search" ||
|
||||||
|| target.type === 'url'
|
target.type === "tel" ||
|
||||||
|| target.type === 'textarea'
|
target.type === "url" ||
|
||||||
|
target.type === "textarea"
|
||||||
|
)
|
||||||
} else if (target instanceof HTMLTextAreaElement) {
|
} else if (target instanceof HTMLTextAreaElement) {
|
||||||
return true
|
return true
|
||||||
} else if (target instanceof HTMLElement && target.isContentEditable) {
|
} else if (target instanceof HTMLElement && target.isContentEditable) {
|
||||||
@@ -117,8 +116,12 @@ function isTextInput(target: EventTarget | null) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('keydown',function(e){
|
window.addEventListener(
|
||||||
if (e.key === "Backspace" && !isTextInput(e.target)) {
|
"keydown",
|
||||||
e.preventDefault()
|
function (e) {
|
||||||
}
|
if (e.key === "Backspace" && !isTextInput(e.target)) {
|
||||||
},true);
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|||||||
@@ -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: {},
|
|
||||||
})
|
|
||||||
@@ -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,
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
mutation UpdateUserSession(
|
|
||||||
$currentSession: String!
|
|
||||||
$sessionType: SessionType!
|
|
||||||
) {
|
|
||||||
updateUserSessions(
|
|
||||||
currentSession: $currentSession
|
|
||||||
sessionType: $sessionType
|
|
||||||
) {
|
|
||||||
currentRESTSession
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
query GetCurrentRESTSession {
|
|
||||||
me {
|
|
||||||
currentRESTSession
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 collectionsDef } from "./platform/collections/collections.platform"
|
||||||
import { def as settingsDef } from "./platform/settings/settings.platform"
|
import { def as settingsDef } from "./platform/settings/settings.platform"
|
||||||
import { def as historyDef } from "./platform/history/history.platform"
|
import { def as historyDef } from "./platform/history/history.platform"
|
||||||
import { def as tabStateDef } from "./platform/tabState/tabState.platform"
|
|
||||||
import { browserInterceptor } from "@hoppscotch/common/platform/std/interceptors/browser"
|
import { browserInterceptor } from "@hoppscotch/common/platform/std/interceptors/browser"
|
||||||
import { proxyInterceptor } from "@hoppscotch/common/platform/std/interceptors/proxy"
|
import { proxyInterceptor } from "@hoppscotch/common/platform/std/interceptors/proxy"
|
||||||
import { ExtensionInspectorService } from "@hoppscotch/common/platform/std/inspections/extension.inspector"
|
import { ExtensionInspectorService } from "@hoppscotch/common/platform/std/inspections/extension.inspector"
|
||||||
@@ -25,7 +24,6 @@ createHoppApp("#app", {
|
|||||||
collections: collectionsDef,
|
collections: collectionsDef,
|
||||||
settings: settingsDef,
|
settings: settingsDef,
|
||||||
history: historyDef,
|
history: historyDef,
|
||||||
tabState: tabStateDef,
|
|
||||||
},
|
},
|
||||||
interceptors: {
|
interceptors: {
|
||||||
default: "browser",
|
default: "browser",
|
||||||
|
|||||||
@@ -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: {},
|
|
||||||
})
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { PersistableTabState } from "@hoppscotch/common/services/tab"
|
|
||||||
import { HoppRESTDocument } from "@hoppscotch/common/helpers/rest/document"
|
|
||||||
import { HoppUser } from "@hoppscotch/common/platform/auth"
|
|
||||||
import { TabStatePlatformDef } from "@hoppscotch/common/platform/tab"
|
|
||||||
import { def as platformAuth } from "@platform/auth/auth.platform"
|
|
||||||
import { getCurrentRestSession, updateUserSession } from "./tabState.api"
|
|
||||||
import { SessionType } from "../../api/generated/graphql"
|
|
||||||
import * as E from "fp-ts/Either"
|
|
||||||
|
|
||||||
async function writeCurrentTabState(
|
|
||||||
_: HoppUser,
|
|
||||||
persistableTabState: PersistableTabState<HoppRESTDocument>
|
|
||||||
) {
|
|
||||||
await updateUserSession(JSON.stringify(persistableTabState), SessionType.Rest)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadTabStateFromSync(): Promise<PersistableTabState<HoppRESTDocument> | 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,
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user