Skip to content

Commit

Permalink
fix initial value overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectronicBlueberry committed Dec 11, 2024
1 parent c55e746 commit 665de8d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 4 additions & 1 deletion client/src/composables/userLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { usePersistentRef } from "./persistentRef";
export function useUserLocalStorage<T>(key: string, initialValue: T, user?: Ref<AnyUser>) {
const { hashedUserId } = useHashedUserId(user);

let refSyncedRawValue = initialValue;

const storedRef = computed(() => {
if (hashedUserId.value) {
return usePersistentRef(`${key}-${hashedUserId.value}`, initialValue);
return usePersistentRef(`${key}-${hashedUserId.value}`, refSyncedRawValue);
} else {
return ref(initialValue);
}
Expand All @@ -28,6 +30,7 @@ export function useUserLocalStorage<T>(key: string, initialValue: T, user?: Ref<
},
set(newValue) {
storedRef.value.value = newValue;
refSyncedRawValue = newValue as T;
trigger();
},
}));
Expand Down
5 changes: 1 addition & 4 deletions client/src/stores/activityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ export const useActivityStore = defineScopedStore("activityStore", (scope) => {
}
});

// update activities stored in local cache only if changes were applied
if (JSON.stringify(activities.value) !== JSON.stringify(newActivities)) {
activities.value = newActivities;
}
activities.value = newActivities;

// if toggled side-bar does not exist, choose the first option
if (toggledSideBar.value !== "") {
Expand Down

0 comments on commit 665de8d

Please sign in to comment.