history.ts (hoppscotch-2.2.1) | : | history.ts (hoppscotch-3.0.0) | ||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
getDocs, | getDocs, | |||
getFirestore, | getFirestore, | |||
limit, | limit, | |||
onSnapshot, | onSnapshot, | |||
orderBy, | orderBy, | |||
query, | query, | |||
updateDoc, | updateDoc, | |||
} from "firebase/firestore" | } from "firebase/firestore" | |||
import { FormDataKeyValue } from "@hoppscotch/data" | import { FormDataKeyValue } from "@hoppscotch/data" | |||
import { currentUser$ } from "./auth" | import { currentUser$ } from "./auth" | |||
import { settingsStore } from "~/newstore/settings" | import { getSettingSubject, settingsStore } from "~/newstore/settings" | |||
import { | import { | |||
GQLHistoryEntry, | GQLHistoryEntry, | |||
graphqlHistoryStore, | graphqlHistoryStore, | |||
HISTORY_LIMIT, | HISTORY_LIMIT, | |||
RESTHistoryEntry, | RESTHistoryEntry, | |||
restHistoryStore, | restHistoryStore, | |||
setGraphqlHistoryEntries, | setGraphqlHistoryEntries, | |||
setRESTHistoryEntries, | setRESTHistoryEntries, | |||
translateToNewGQLHistory, | translateToNewGQLHistory, | |||
translateToNewRESTHistory, | translateToNewRESTHistory, | |||
skipping to change at line 145 | skipping to change at line 145 | |||
doc(getFirestore(), "users", currentUser$.value.uid, col, entry.id), | doc(getFirestore(), "users", currentUser$.value.uid, col, entry.id), | |||
{ star: !entry.star } | { star: !entry.star } | |||
) | ) | |||
} catch (e) { | } catch (e) { | |||
console.error("error toggling star", entry, e) | console.error("error toggling star", entry, e) | |||
throw e | throw e | |||
} | } | |||
} | } | |||
export function initHistory() { | export function initHistory() { | |||
restHistoryStore.dispatches$.subscribe((dispatch) => { | const restHistorySub = restHistoryStore.dispatches$.subscribe((dispatch) => { | |||
if ( | if ( | |||
loadedRESTHistory && | loadedRESTHistory && | |||
currentUser$.value && | currentUser$.value && | |||
settingsStore.value.syncHistory | settingsStore.value.syncHistory | |||
) { | ) { | |||
if (dispatch.dispatcher === "addEntry") { | if (dispatch.dispatcher === "addEntry") { | |||
writeHistory(dispatch.payload.entry, "history") | writeHistory(dispatch.payload.entry, "history") | |||
} else if (dispatch.dispatcher === "deleteEntry") { | } else if (dispatch.dispatcher === "deleteEntry") { | |||
deleteHistory(dispatch.payload.entry, "history") | deleteHistory(dispatch.payload.entry, "history") | |||
} else if (dispatch.dispatcher === "clearHistory") { | } else if (dispatch.dispatcher === "clearHistory") { | |||
clearHistory("history") | clearHistory("history") | |||
} else if (dispatch.dispatcher === "toggleStar") { | } else if (dispatch.dispatcher === "toggleStar") { | |||
toggleStar(dispatch.payload.entry, "history") | toggleStar(dispatch.payload.entry, "history") | |||
} | } | |||
} | } | |||
}) | }) | |||
graphqlHistoryStore.dispatches$.subscribe((dispatch) => { | const gqlHistorySub = graphqlHistoryStore.dispatches$.subscribe( | |||
if ( | (dispatch) => { | |||
loadedGraphqlHistory && | if ( | |||
currentUser$.value && | loadedGraphqlHistory && | |||
settingsStore.value.syncHistory | currentUser$.value && | |||
) { | settingsStore.value.syncHistory | |||
if (dispatch.dispatcher === "addEntry") { | ) { | |||
writeHistory(dispatch.payload.entry, "graphqlHistory") | if (dispatch.dispatcher === "addEntry") { | |||
} else if (dispatch.dispatcher === "deleteEntry") { | writeHistory(dispatch.payload.entry, "graphqlHistory") | |||
deleteHistory(dispatch.payload.entry, "graphqlHistory") | } else if (dispatch.dispatcher === "deleteEntry") { | |||
} else if (dispatch.dispatcher === "clearHistory") { | deleteHistory(dispatch.payload.entry, "graphqlHistory") | |||
clearHistory("graphqlHistory") | } else if (dispatch.dispatcher === "clearHistory") { | |||
} else if (dispatch.dispatcher === "toggleStar") { | clearHistory("graphqlHistory") | |||
toggleStar(dispatch.payload.entry, "graphqlHistory") | } else if (dispatch.dispatcher === "toggleStar") { | |||
toggleStar(dispatch.payload.entry, "graphqlHistory") | ||||
} | ||||
} | } | |||
} | } | |||
}) | ) | |||
let restSnapshotStop: (() => void) | null = null | let restSnapshotStop: (() => void) | null = null | |||
let graphqlSnapshotStop: (() => void) | null = null | let graphqlSnapshotStop: (() => void) | null = null | |||
currentUser$.subscribe((user) => { | const currentUserSub = currentUser$.subscribe((user) => { | |||
if (!user) { | if (!user) { | |||
// Clear the snapshot listeners when the user logs out | // Clear the snapshot listeners when the user logs out | |||
if (restSnapshotStop) { | if (restSnapshotStop) { | |||
restSnapshotStop() | restSnapshotStop() | |||
restSnapshotStop = null | restSnapshotStop = null | |||
} | } | |||
if (graphqlSnapshotStop) { | if (graphqlSnapshotStop) { | |||
graphqlSnapshotStop() | graphqlSnapshotStop() | |||
graphqlSnapshotStop = null | graphqlSnapshotStop = null | |||
skipping to change at line 242 | skipping to change at line 244 | |||
history.push(translateToNewGQLHistory(entry)) | history.push(translateToNewGQLHistory(entry)) | |||
}) | }) | |||
loadedGraphqlHistory = false | loadedGraphqlHistory = false | |||
setGraphqlHistoryEntries(history) | setGraphqlHistoryEntries(history) | |||
loadedGraphqlHistory = true | loadedGraphqlHistory = true | |||
} | } | |||
) | ) | |||
} | } | |||
}) | }) | |||
let oldSyncStatus = settingsStore.value.syncHistory | ||||
const syncStop = getSettingSubject("syncHistory").subscribe((newStatus) => { | ||||
if (oldSyncStatus === true && newStatus === false) { | ||||
restSnapshotStop?.() | ||||
graphqlSnapshotStop?.() | ||||
oldSyncStatus = newStatus | ||||
} else if (oldSyncStatus === false && newStatus === true) { | ||||
syncStop.unsubscribe() | ||||
restHistorySub.unsubscribe() | ||||
gqlHistorySub.unsubscribe() | ||||
currentUserSub.unsubscribe() | ||||
initHistory() | ||||
} | ||||
}) | ||||
} | } | |||
End of changes. 6 change blocks. | ||||
18 lines changed or deleted | 38 lines changed or added |