Skip to content

Commit a375a72

Browse files
committed
feat(store): store data in indexedDB
1 parent b8e900f commit a375a72

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@vueuse/integrations": "^13.9.0",
2626
"dayjs": "^1.11.18",
2727
"http-status-codes": "^2.3.0",
28+
"idb-keyval": "^6.2.2",
2829
"semver": "^7.7.2",
2930
"sortablejs": "^1.15.6",
3031
"vite": "^7.1.6",

pnpm-lock.yaml

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/store/events.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { computed } from "vue";
22
import { createGlobalState, useLocalStorage, whenever } from "@vueuse/core";
3+
import { useIDBKeyval } from "@vueuse/integrations/useIDBKeyval";
34
import dayjs from "dayjs";
45
import { fetchRepositoryEvents } from "@/service/octokit";
56
import { useSettingsStore } from "@/store/settings";
@@ -46,7 +47,8 @@ const DEFAULT_STORE: EventsStore = {
4647
};
4748

4849
export const useEventsStore = createGlobalState(() => {
49-
const storage = useLocalStorage<EventsStore>("events", DEFAULT_STORE, { mergeDefaults: true });
50+
const local = useLocalStorage("events", DEFAULT_STORE);
51+
const { data: storage } = useIDBKeyval("events", local.value ?? DEFAULT_STORE, { deep: true, writeDefaults: true });
5052
const events = computed<FeedEvent[]>({
5153
get: () => storage.value.data,
5254
set: (value) => { storage.value.data = value; }

src/store/excluded-dependencies.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { createGlobalState, useLocalStorage } from "@vueuse/core";
2+
import { useIDBKeyval } from "@vueuse/integrations/useIDBKeyval";
23

34
type ExcludedDependenciesStore = Set<string>;
45
const DEFAULT_STORE: ExcludedDependenciesStore = new Set();
56

67
export const useExcludedDependenciesStore = createGlobalState(() => {
7-
const excludedDependencies = useLocalStorage("excludedDependencies", DEFAULT_STORE, { mergeDefaults: true });
8+
const local = useLocalStorage("excludedDependencies", DEFAULT_STORE);
9+
const { data: excludedDependencies } = useIDBKeyval("excludedDependencies", local.value ?? DEFAULT_STORE, { deep: true, writeDefaults: true });
810

911
function hideDependency(dep: string): void {
1012
excludedDependencies.value.add(dep);

src/store/latest-versions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { computed } from "vue";
22
import { createGlobalState, useLocalStorage, whenever } from "@vueuse/core";
3+
import { useIDBKeyval } from "@vueuse/integrations/useIDBKeyval";
34
import dayjs from "dayjs";
45
import type { PackageJson } from "type-fest";
56
import { useDependencyTable } from "@/composable/useDependencyTable";
@@ -20,7 +21,8 @@ async function fetchLatestVersion(dependency: string): Promise<string | null> {
2021
};
2122

2223
export const useLatestVersionsStore = createGlobalState(() => {
23-
const storage = useLocalStorage<LatestVersionsStore>("latestVersions", DEFAULT_STORE, { mergeDefaults: true });
24+
const local = useLocalStorage("latestVersions", DEFAULT_STORE);
25+
const { data: storage } = useIDBKeyval("latestVersions", local.value ?? DEFAULT_STORE, { deep: true, writeDefaults: true });
2426
const latestVersions = computed({
2527
get: () => storage.value.data,
2628
set: (value) => { storage.value.data = value; }

src/store/repositories.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { computed } from "vue";
22
import { createGlobalState, useLocalStorage, whenever } from "@vueuse/core";
3+
import { useIDBKeyval } from "@vueuse/integrations/useIDBKeyval";
34
import dayjs from "dayjs";
45
import { isExportedRepository, type ExportedRepository } from "@/helpers/export";
56
import { fetchRepo, fetchRepositoryFiles, fetchRepositoryPackages, fetchRepositoryWorkflows } from "@/service/octokit";
@@ -30,7 +31,8 @@ async function parsePackageManager(fullName: Repository["full_name"]): Promise<"
3031
}
3132

3233
export const useRepositoriesStore = createGlobalState(() => {
33-
const storage = useLocalStorage<RepositoriesStore>("repositories", DEFAULT_STORE, { mergeDefaults: true });
34+
const local = useLocalStorage("repositories", DEFAULT_STORE);
35+
const { data: storage } = useIDBKeyval<RepositoriesStore>("repositories", local.value ?? DEFAULT_STORE, { deep: true, writeDefaults: true });
3436
const repositories = computed({
3537
get: () => storage.value.data,
3638
set: (data) => { storage.value.data = data; }

src/store/settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createGlobalState, useLocalStorage } from "@vueuse/core";
2+
import { useIDBKeyval } from "@vueuse/integrations/useIDBKeyval";
23
import { useRegisterSW } from "virtual:pwa-register/vue";
34

45
type Theme = "github" | "aqua" | "cream" | "mint" | "rose" | "departure";
@@ -19,7 +20,8 @@ const DEFAULT_STORE: SettingsStore = {
1920
};
2021

2122
export const useSettingsStore = createGlobalState(() => {
22-
const settings = useLocalStorage<SettingsStore>("settings", DEFAULT_STORE, { mergeDefaults: true });
23+
const local = useLocalStorage("settings", DEFAULT_STORE);
24+
const { data: settings } = useIDBKeyval<SettingsStore>("settings", local.value ?? DEFAULT_STORE, { deep: true, writeDefaults: true });
2325

2426
const { needRefresh, updateServiceWorker } = useRegisterSW({ immediate: true });
2527

src/store/summary.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { computed } from "vue";
22
import { createGlobalState, useEventListener, useLocalStorage } from "@vueuse/core";
3+
import { useIDBKeyval } from "@vueuse/integrations/useIDBKeyval";
34
import { useRepositoriesStore } from "./repositories";
45
import type { Repository } from "@/composable/useRepo";
56

@@ -32,7 +33,8 @@ function summarize(repos: RepoSummary[]): Delta & { repos: number } {
3233
}
3334

3435
export const useSummaryStorage = createGlobalState(() => {
35-
const storage = useLocalStorage<SummaryStore>("summary", DEFAULT_STORE, { mergeDefaults: true });
36+
const local = useLocalStorage("summary", DEFAULT_STORE);
37+
const { data: storage } = useIDBKeyval<SummaryStore>("summary", local.value ?? DEFAULT_STORE, { deep: true, writeDefaults: true });
3638
const { repositories } = useRepositoriesStore();
3739

3840
const currentRepos = computed<RepoSummary[]>(() =>

0 commit comments

Comments
 (0)