refactor: move persistence logic into a dedicated service (#3493)

This commit is contained in:
James George
2023-11-29 22:40:26 +05:30
committed by GitHub
parent 144d14ab5b
commit 60bfb6fe2c
18 changed files with 3179 additions and 647 deletions

View File

@@ -61,19 +61,21 @@
</template>
<script setup lang="ts">
import { computed, onBeforeMount, onMounted, ref, watch } from "vue"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css"
import { RouterView, useRouter } from "vue-router"
import { useSetting } from "@composables/settings"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { useService } from "dioc/vue"
import { Pane, Splitpanes } from "splitpanes"
import "splitpanes/dist/splitpanes.css"
import { computed, onBeforeMount, onMounted, ref, watch } from "vue"
import { RouterView, useRouter } from "vue-router"
import { defineActionHandler } from "~/helpers/actions"
import { hookKeybindingsListener } from "~/helpers/keybindings"
import { applySetting } from "~/newstore/settings"
import { getLocalConfig, setLocalConfig } from "~/newstore/localpersistence"
import { useToast } from "~/composables/toast"
import { useI18n } from "~/composables/i18n"
import { platform } from "~/platform"
import { PersistenceService } from "~/services/persistence"
const router = useRouter()
@@ -90,6 +92,8 @@ const mdAndLarger = breakpoints.greater("md")
const toast = useToast()
const t = useI18n()
const persistenceService = useService(PersistenceService)
onBeforeMount(() => {
if (!mdAndLarger.value) {
rightSidebar.value = false
@@ -98,7 +102,8 @@ onBeforeMount(() => {
})
onMounted(() => {
const cookiesAllowed = getLocalConfig("cookiesAllowed") === "yes"
const cookiesAllowed =
persistenceService.getLocalConfig("cookiesAllowed") === "yes"
const platformAllowsCookiePrompts =
platform.platformFeatureFlags.promptAsUsingCookies ?? true
@@ -109,7 +114,7 @@ onMounted(() => {
{
text: `${t("action.learn_more")}`,
onClick: (_, toastObject) => {
setLocalConfig("cookiesAllowed", "yes")
persistenceService.setLocalConfig("cookiesAllowed", "yes")
toastObject.goAway(0)
window
.open("https://docs.hoppscotch.io/support/privacy", "_blank")
@@ -119,7 +124,7 @@ onMounted(() => {
{
text: `${t("action.dismiss")}`,
onClick: (_, toastObject) => {
setLocalConfig("cookiesAllowed", "yes")
persistenceService.setLocalConfig("cookiesAllowed", "yes")
toastObject.goAway(0)
},
},