chore: cleanup

This commit is contained in:
jamesgeorge007
2024-05-23 14:05:35 +05:30
parent 8b930a6d3d
commit 4c74d0f865
10 changed files with 415 additions and 496 deletions

View File

@@ -90,7 +90,7 @@
"util": "0.12.5",
"uuid": "9.0.1",
"verzod": "0.2.2",
"vue": "3.3.9",
"vue": "3.4.27",
"vue-i18n": "9.8.0",
"vue-pdf-embed": "1.2.1",
"vue-router": "4.2.5",

View File

@@ -114,7 +114,7 @@ export function getRequestsByPath(
if (pathArray.length === 1) {
const latestVersionedRequests = currentCollection.requests.filter(
(req): req is HoppRESTRequest => req.v === "3"
(req): req is HoppRESTRequest => req.v === "4"
)
return latestVersionedRequests
@@ -125,7 +125,7 @@ export function getRequestsByPath(
}
const latestVersionedRequests = currentCollection.requests.filter(
(req): req is HoppRESTRequest => req.v === "3"
(req): req is HoppRESTRequest => req.v === "4"
)
return latestVersionedRequests

View File

@@ -26,6 +26,7 @@
@close-tab="removeTab(tab.id)"
@close-other-tabs="closeOtherTabsAction(tab.id)"
@duplicate-tab="duplicateTab(tab.id)"
@share-tab-request="shareTabRequest(tab.id)"
/>
</template>
<template #suffix>
@@ -96,37 +97,21 @@
<script lang="ts" setup>
import { useI18n } from "@composables/i18n"
import { safelyExtractRESTRequest } from "@hoppscotch/data"
import { watchDebounced } from "@vueuse/core"
import { useService } from "dioc/vue"
import { cloneDeep } from "lodash-es"
import {
BehaviorSubject,
EMPTY,
Subscription,
audit,
combineLatest,
from,
map,
} from "rxjs"
import { onBeforeUnmount, onMounted, ref } from "vue"
import { onMounted, ref } from "vue"
import { useRoute } from "vue-router"
import { onLoggedIn } from "~/composables/auth"
import { useReadonlyStream } from "~/composables/stream"
import { useToast } from "~/composables/toast"
import { translateExtURLParams } from "~/helpers/RESTExtURLParams"
import { defineActionHandler, invokeAction } from "~/helpers/actions"
import { getDefaultRESTRequest } from "~/helpers/rest/default"
import { HoppRESTDocument } from "~/helpers/rest/document"
import {
changeCurrentSyncStatus,
currentSyncingStatus$,
} from "~/newstore/syncing"
import { platform } from "~/platform"
import { InspectionService } from "~/services/inspection"
import { EnvironmentInspectorService } from "~/services/inspection/inspectors/environment.inspector"
import { HeaderInspectorService } from "~/services/inspection/inspectors/header.inspector"
import { ResponseInspectorService } from "~/services/inspection/inspectors/response.inspector"
import { HoppTab, PersistableTabState } from "~/services/tab"
import { HoppTab } from "~/services/tab"
import { RESTTabService } from "~/services/tab/rest"
const savingRequest = ref(false)
@@ -139,12 +124,16 @@ const exceptedTabID = ref<string | null>(null)
const renameTabID = ref<string | null>(null)
const t = useI18n()
const toast = useToast()
const tabs = useService(RESTTabService)
const currentTabID = tabs.currentTabID
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
type PopupDetails = {
show: boolean
position: {
@@ -165,12 +154,6 @@ const contextMenu = ref<PopupDetails>({
const activeTabs = tabs.getActiveTabs()
const confirmSync = useReadonlyStream(currentSyncingStatus$, {
isInitialSync: false,
shouldSync: true,
})
const tabStateForSync = ref<PersistableTabState<HoppRESTDocument> | null>(null)
function bindRequestToURLParams() {
const route = useRoute()
// Get URL parameters and set that as the request
@@ -319,9 +302,17 @@ const onSaveModalClose = () => {
}
}
const syncTabState = () => {
if (tabStateForSync.value)
tabs.loadTabsFromPersistedState(tabStateForSync.value)
const shareTabRequest = (tabID: string) => {
const tab = tabs.getTabRef(tabID)
if (tab.value) {
if (currentUser.value) {
invokeAction("share.request", {
request: tab.value.document.request,
})
} else {
invokeAction("modals.login.toggle")
}
}
}
const getTabDirtyStatus = (tab: HoppTab<HoppRESTDocument>) => {
@@ -335,106 +326,6 @@ const getTabDirtyStatus = (tab: HoppTab<HoppRESTDocument>) => {
)
}
/**
* 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 }) => {
if (text) {
contextMenu.value = {
@@ -451,7 +342,6 @@ defineActionHandler("contextmenu.open", ({ position, text }) => {
}
})
setupTabStateSync()
bindRequestToURLParams()
defineActionHandler("rest.request.open", ({ doc }) => {

View File

@@ -65,9 +65,7 @@ export class NewWorkspaceService extends Service {
return items
})
constructor() {
super()
override onServiceInit() {
// Watch for situations where the handle is invalidated
// so the active workspace handle definition can be invalidated
watch(

View File

@@ -91,16 +91,16 @@ export class PersonalWorkspaceProviderService
workspaceSelectorPriority: 100,
})
public restCollectionState: Ref<{ state: HoppCollection[] }>
public restCollectionState: Ref<{ state: HoppCollection[] }> = ref({
state: [],
})
// Issued handles can have collection handles when the collection runner is introduced
public issuedHandles: WritableHandleRef<
WorkspaceRequest | WorkspaceCollection
>[] = []
public constructor() {
super()
override onServiceInit() {
this.restCollectionState = useStreamStatic(
restCollectionStore.subject$,
{ state: [] },

View File

@@ -73,9 +73,7 @@ export class TestWorkspaceProviderService
private readonly workspaceService = this.bind(NewWorkspaceService)
constructor() {
super()
override onServiceInit() {
this.workspaceService.registerWorkspaceProvider(this)
}

View File

@@ -495,9 +495,9 @@ const HoppRESTSaveContextSchema = z.nullable(
z
.object({
originLocation: z.literal("workspace-user-collection"),
workspaceID: z.string(),
providerID: z.string(),
requestID: z.string(),
workspaceID: z.optional(z.string()),
providerID: z.optional(z.string()),
requestID: z.optional(z.string()),
requestHandle: z.optional(z.record(z.unknown())),
})
.strict(),

View File

@@ -37,7 +37,7 @@
"rxjs": "7.8.1",
"stream-browserify": "3.0.0",
"util": "0.12.5",
"vue": "3.3.9",
"vue": "3.4.27",
"workbox-window": "7.0.0",
"zod": "3.22.4"
},