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

@@ -34,7 +34,7 @@
}, },
"pnpm": { "pnpm": {
"overrides": { "overrides": {
"vue": "3.3.9" "vue": "3.4.27"
}, },
"packageExtensions": { "packageExtensions": {
"httpsnippet@3.0.1": { "httpsnippet@3.0.1": {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

731
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff