Skip to content

Commit

Permalink
Merge pull request #386 from bcc-code/fix/cache-currentuser-composable
Browse files Browse the repository at this point in the history
fix: cache currentuser composable
  • Loading branch information
kkuepper committed Apr 16, 2024
2 parents a43b70c + b1fb635 commit ddc603d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions components/track/TrackMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/vue";
const runtimeConfig = useRuntimeConfig();
const { t } = useI18n();
const { $appInsights } = useNuxtApp();
const { addNext, addToQueue } = useNuxtApp().$mediaPlayer;
const copyToClipboardComponent = ref<null | { copyToClipboard: () => void }>(
Expand Down Expand Up @@ -54,7 +55,10 @@ const dropdownMenuItemsForTrack = (track: TrackModel) => {
clickFunction: async () => {
const result = await download(track);
if (result === "no-permission") {
$appInsights.event("denied downloading track", { trackId: track.id });
showDownloadDialog.value = true;
} else {
$appInsights.event("track downloaded", { trackId: track.id });
}
},
});
Expand Down
14 changes: 9 additions & 5 deletions composables/user.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type { AsyncData } from "#app";
import { CurrentUserApi } from "@bcc-code/bmm-sdk-fetch";
import type { UserModel } from "@bcc-code/bmm-sdk-fetch";

export function useCurrentUser() {
return reactiveApi(
useLazyAsyncData(`current-user`, () =>
new CurrentUserApi().currentUserGet(),
),
let cachedComposable: AsyncData<UserModel, Error | null> | null = null;
export function useCurrentUser(): AsyncData<UserModel, Error | null> {
cachedComposable ??= useAsyncData(
`current-user-asyncdata`,
() => new CurrentUserApi().currentUserGet(),
{ dedupe: "defer" },
);
return cachedComposable!;
}

0 comments on commit ddc603d

Please sign in to comment.