fix: change name and remove watch

This commit is contained in:
Nivedin
2023-05-23 21:01:57 +05:30
committed by Andrew Bastin
parent 2ea7f56c23
commit bda9ce6dd8
2 changed files with 42 additions and 44 deletions

View File

@@ -2,8 +2,8 @@ import { distinctUntilChanged, pluck } from "rxjs"
import DispatchingStore, { defineDispatchers } from "./DispatchingStore" import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
type SyncState = { type SyncState = {
initialSync: boolean isInitialSync: boolean
sync: boolean shouldSync: boolean
} }
type CurrentSyncingState = { type CurrentSyncingState = {
@@ -12,8 +12,8 @@ type CurrentSyncingState = {
const initialState: CurrentSyncingState = { const initialState: CurrentSyncingState = {
currentSyncingItem: { currentSyncingItem: {
initialSync: false, isInitialSync: false,
sync: false, shouldSync: false,
}, },
} }

View File

@@ -87,7 +87,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onMounted, onBeforeUnmount, watch, onBeforeMount } from "vue" import { ref, onMounted, onBeforeUnmount, onBeforeMount } 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"
@@ -140,8 +140,8 @@ const toast = useToast()
const tabs = getActiveTabs() const tabs = getActiveTabs()
const confirmSync = useReadonlyStream(currentSyncingStatus$, { const confirmSync = useReadonlyStream(currentSyncingStatus$, {
initialSync: false, isInitialSync: false,
sync: true, shouldSync: true,
}) })
const tabStateForSync = ref<PersistableRESTTabState | null>(null) const tabStateForSync = ref<PersistableRESTTabState | null>(null)
@@ -237,40 +237,6 @@ const onSaveModalClose = () => {
} }
} }
watch(
() => confirmSync.value.initialSync,
(newValue) => {
if (newValue) {
toast.show(t("confirm.sync"), {
duration: 0,
action: [
{
text: `${t("action.yes")}`,
onClick: (_, toastObject) => {
syncTabState()
changeCurrentSyncStatus({
initialSync: true,
sync: true,
})
toastObject.goAway(0)
},
},
{
text: `${t("action.no")}`,
onClick: (_, toastObject) => {
changeCurrentSyncStatus({
initialSync: true,
sync: false,
})
toastObject.goAway(0)
},
},
],
})
}
}
)
const syncTabState = () => { const syncTabState = () => {
if (tabStateForSync.value) loadTabsFromPersistedState(tabStateForSync.value) if (tabStateForSync.value) loadTabsFromPersistedState(tabStateForSync.value)
} }
@@ -309,6 +275,35 @@ function startTabStateSync(): Subscription {
return sub 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() { function setupTabStateSync() {
const route = useRoute() const route = useRoute()
@@ -324,11 +319,14 @@ function setupTabStateSync() {
const tabStateFromSync = const tabStateFromSync =
await platform.sync.tabState.loadTabStateFromSync() await platform.sync.tabState.loadTabStateFromSync()
if (tabStateFromSync && !confirmSync.value.initialSync) { if (tabStateFromSync && !confirmSync.value.isInitialSync) {
tabStateForSync.value = tabStateFromSync 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({ changeCurrentSyncStatus({
initialSync: true, isInitialSync: true,
sync: false, shouldSync: false,
}) })
} }
} }