From f0a1fc319c364e38c150caca4642ca9b381fcaf6 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Wed, 31 May 2023 09:06:37 +0530 Subject: [PATCH] fix: sync popup firing multiple times (#3063) --- .../hoppscotch-common/src/newstore/syncing.ts | 40 ++++++++++ .../hoppscotch-common/src/pages/index.vue | 74 ++++++++++++------- 2 files changed, 87 insertions(+), 27 deletions(-) create mode 100644 packages/hoppscotch-common/src/newstore/syncing.ts diff --git a/packages/hoppscotch-common/src/newstore/syncing.ts b/packages/hoppscotch-common/src/newstore/syncing.ts new file mode 100644 index 0000000000..7d3f28ab3c --- /dev/null +++ b/packages/hoppscotch-common/src/newstore/syncing.ts @@ -0,0 +1,40 @@ +import { distinctUntilChanged, pluck } from "rxjs" +import DispatchingStore, { defineDispatchers } from "./DispatchingStore" + +type SyncState = { + isInitialSync: boolean + shouldSync: boolean +} + +type CurrentSyncingState = { + currentSyncingItem: SyncState +} + +const initialState: CurrentSyncingState = { + currentSyncingItem: { + isInitialSync: false, + shouldSync: false, + }, +} + +const dispatchers = defineDispatchers({ + changeCurrentSyncStatus(_, { syncItem }: { syncItem: SyncState }) { + return { + currentSyncingItem: syncItem, + } + }, +}) + +export const currentSyncStore = new DispatchingStore(initialState, dispatchers) + +export const currentSyncingStatus$ = currentSyncStore.subject$.pipe( + pluck("currentSyncingItem"), + distinctUntilChanged() +) + +export function changeCurrentSyncStatus(syncItem: SyncState) { + currentSyncStore.dispatch({ + dispatcher: "changeCurrentSyncStatus", + payload: { syncItem }, + }) +} diff --git a/packages/hoppscotch-common/src/pages/index.vue b/packages/hoppscotch-common/src/pages/index.vue index d783de1dfa..00b10e47a3 100644 --- a/packages/hoppscotch-common/src/pages/index.vue +++ b/packages/hoppscotch-common/src/pages/index.vue @@ -87,7 +87,7 @@