Skip to content

Commit f0fa975

Browse files
Merge pull request #19859 from jmchilton/clean_circular_2
Remove circular dependency around user store.
2 parents 53f9e21 + 2da308e commit f0fa975

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

client/src/composables/hashedUserId.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { storeToRefs } from "pinia";
21
import { computed, type Ref, ref, watch } from "vue";
32

43
import { type AnyUser } from "@/api";
5-
import { useUserStore } from "@/stores/userStore";
64

75
import { usePersistentRef } from "./persistentRef";
86

@@ -33,15 +31,8 @@ let unhashedId: string | null = null;
3331
/**
3432
* One way hashed ID of the current User
3533
*/
36-
export function useHashedUserId(user?: Ref<AnyUser>) {
37-
let currentUser: Ref<AnyUser>;
38-
39-
if (user) {
40-
currentUser = user;
41-
} else {
42-
const { currentUser: currentUserRef } = storeToRefs(useUserStore());
43-
currentUser = currentUserRef;
44-
}
34+
export function useHashedUserId(user: Ref<AnyUser>) {
35+
const currentUser: Ref<AnyUser> = user;
4536

4637
// salt the local store, to make a user untraceable by id across different clients
4738
const localStorageSalt = usePersistentRef("local-storage-salt", createSalt());
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { storeToRefs } from "pinia";
2+
3+
import { useUserStore } from "@/stores/userStore";
4+
5+
import { useHashedUserId as parentUseHashedUserId } from "./hashedUserId";
6+
7+
/**
8+
* One way hashed ID of the current User
9+
*/
10+
export function useHashedUserId() {
11+
const { currentUser: currentUserRef } = storeToRefs(useUserStore());
12+
return parentUseHashedUserId(currentUserRef);
13+
}

client/src/composables/userLocalStorage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type Ref, ref } from "vue";
44
import { type AnyUser } from "@/api";
55

66
import { useHashedUserId } from "./hashedUserId";
7+
import { useHashedUserId as useHashedUserIdFromStore } from "./hashedUserIdFromUserStore";
78
import { syncRefToLocalStorage } from "./persistentRef";
89

910
/**
@@ -12,7 +13,12 @@ import { syncRefToLocalStorage } from "./persistentRef";
1213
* @param initialValue
1314
*/
1415
export function useUserLocalStorage<T>(key: string, initialValue: T, user?: Ref<AnyUser>) {
15-
const { hashedUserId } = useHashedUserId(user);
16+
let hashedUserId;
17+
if (user) {
18+
hashedUserId = useHashedUserId(user).hashedUserId;
19+
} else {
20+
hashedUserId = useHashedUserIdFromStore().hashedUserId;
21+
}
1622

1723
const refToSync = ref(initialValue);
1824
let hasSynced = false;

client/src/stores/activityStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { useDebounceFn, watchImmediate } from "@vueuse/core";
55
import { computed, type Ref, ref, set } from "vue";
66

7-
import { useHashedUserId } from "@/composables/hashedUserId";
7+
import { useHashedUserId } from "@/composables/hashedUserIdFromUserStore";
88
import { useUserLocalStorage } from "@/composables/userLocalStorage";
99
import { ensureDefined } from "@/utils/assertions";
1010

0 commit comments

Comments
 (0)