feat: tab service added (#3367)
This commit is contained in:
@@ -7,8 +7,9 @@ import {
|
||||
} from "@hoppscotch/data"
|
||||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
|
||||
import { cloneDeep } from "lodash-es"
|
||||
import { getTabRefWithSaveContext } from "~/helpers/rest/tab"
|
||||
import { resolveSaveContextOnRequestReorder } from "~/helpers/collection/request"
|
||||
import { getService } from "~/modules/dioc"
|
||||
import { RESTTabService } from "~/services/tab/rest"
|
||||
|
||||
const defaultRESTCollectionState = {
|
||||
state: [
|
||||
@@ -454,7 +455,10 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
|
||||
// Deal with situations where a tab with the given thing is deleted
|
||||
// We are just going to dissociate the save context of the tab and mark it dirty
|
||||
const tab = getTabRefWithSaveContext({
|
||||
|
||||
const tabService = getService(RESTTabService)
|
||||
|
||||
const tab = tabService.getTabRefWithSaveContext({
|
||||
originLocation: "user-collection",
|
||||
folderPath: path,
|
||||
requestIndex: requestIndex,
|
||||
@@ -512,7 +516,8 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
destLocation.requests.push(req)
|
||||
targetLocation.requests.splice(requestIndex, 1)
|
||||
|
||||
const possibleTab = getTabRefWithSaveContext({
|
||||
const tabService = getService(RESTTabService)
|
||||
const possibleTab = tabService.getTabRefWithSaveContext({
|
||||
originLocation: "user-collection",
|
||||
folderPath: path,
|
||||
requestIndex,
|
||||
|
||||
@@ -44,14 +44,9 @@ import { SSERequest$, setSSERequest } from "./SSESession"
|
||||
import { MQTTRequest$, setMQTTRequest } from "./MQTTSession"
|
||||
import { bulkApplyLocalState, localStateStore } from "./localstate"
|
||||
import { StorageLike, watchDebounced } from "@vueuse/core"
|
||||
import {
|
||||
loadTabsFromPersistedState,
|
||||
persistableTabState,
|
||||
} from "~/helpers/rest/tab"
|
||||
import {
|
||||
loadTabsFromPersistedState as loadGQLTabsFromPersistedState,
|
||||
persistableTabState as persistableGQLTabState,
|
||||
} from "~/helpers/graphql/tab"
|
||||
import { getService } from "~/modules/dioc"
|
||||
import { RESTTabService } from "~/services/tab/rest"
|
||||
import { GQLTabService } from "~/services/tab/graphql"
|
||||
|
||||
function checkAndMigrateOldSettings() {
|
||||
if (window.localStorage.getItem("selectedEnvIndex")) {
|
||||
@@ -320,11 +315,13 @@ function setupGlobalEnvsPersistence() {
|
||||
|
||||
// TODO: Graceful error handling ?
|
||||
export function setupRESTTabsPersistence() {
|
||||
const tabService = getService(RESTTabService)
|
||||
|
||||
try {
|
||||
const state = window.localStorage.getItem("restTabState")
|
||||
if (state) {
|
||||
const data = JSON.parse(state)
|
||||
loadTabsFromPersistedState(data)
|
||||
tabService.loadTabsFromPersistedState(data)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(
|
||||
@@ -334,7 +331,7 @@ export function setupRESTTabsPersistence() {
|
||||
}
|
||||
|
||||
watchDebounced(
|
||||
persistableTabState,
|
||||
tabService.persistableTabState,
|
||||
(state) => {
|
||||
window.localStorage.setItem("restTabState", JSON.stringify(state))
|
||||
},
|
||||
@@ -343,11 +340,13 @@ export function setupRESTTabsPersistence() {
|
||||
}
|
||||
|
||||
function setupGQLTabsPersistence() {
|
||||
const tabService = getService(GQLTabService)
|
||||
|
||||
try {
|
||||
const state = window.localStorage.getItem("gqlTabState")
|
||||
if (state) {
|
||||
const data = JSON.parse(state)
|
||||
loadGQLTabsFromPersistedState(data)
|
||||
tabService.loadTabsFromPersistedState(data)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(
|
||||
@@ -357,7 +356,7 @@ function setupGQLTabsPersistence() {
|
||||
}
|
||||
|
||||
watchDebounced(
|
||||
persistableGQLTabState,
|
||||
tabService.persistableTabState,
|
||||
(state) => {
|
||||
window.localStorage.setItem("gqlTabState", JSON.stringify(state))
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user