aboutsummaryrefslogtreecommitdiff
path: root/front-end/src/store/userProfile.ts
diff options
context:
space:
mode:
authorLibravatar Vaughn Nugent <public@vaughnnugent.com>2024-01-31 14:31:45 -0500
committerLibravatar Vaughn Nugent <public@vaughnnugent.com>2024-01-31 14:31:45 -0500
commite4000144e6236f8afc3e2b7d6d11ff50248be1bd (patch)
tree77853294b3dcced363ea65791a3baeb3fbafb1eb /front-end/src/store/userProfile.ts
parent2889b3dd10de9a5df42f3f8ab2171b52893ac3f4 (diff)
parentf3661776f679a517f2b4fce0a8f583d1a2b0f854 (diff)
Merges pull request #1 cmnext-cli
Master changes to cli branch
Diffstat (limited to 'front-end/src/store/userProfile.ts')
-rw-r--r--front-end/src/store/userProfile.ts30
1 files changed, 16 insertions, 14 deletions
diff --git a/front-end/src/store/userProfile.ts b/front-end/src/store/userProfile.ts
index a4ea469..0320ace 100644
--- a/front-end/src/store/userProfile.ts
+++ b/front-end/src/store/userProfile.ts
@@ -3,7 +3,8 @@ import { MaybeRef, watch } from 'vue';
import { ServerDataBuffer, ServerObjectBuffer, UserProfile, WebMessage, apiCall, useAxios, useDataBuffer, useUser } from '@vnuge/vnlib.browser';
import { get, useToggle } from '@vueuse/core';
import { PiniaPlugin, PiniaPluginContext, storeToRefs } from 'pinia'
-import { defer } from 'lodash-es';
+import { defer, noop } from 'lodash-es';
+import { storeExport } from './index';
export interface OAuth2Application {
readonly Id: string,
@@ -24,17 +25,21 @@ interface ExUserProfile extends UserProfile {
created: string | Date
}
+export interface UserProfileStore{
+ userProfile: ServerDataBuffer<ExUserProfile, WebMessage<string>>
+ userName: string | undefined
+ refreshProfile(): void;
+}
+
declare module 'pinia' {
- export interface PiniaCustomProperties {
- userProfile: ServerDataBuffer<ExUserProfile, WebMessage<string>>
- userName: string | undefined
- refreshProfile(): void;
+ export interface PiniaCustomProperties extends UserProfileStore {
+
}
}
export const profilePlugin = (accountsUrl:MaybeRef<string>) :PiniaPlugin => {
- return ({ store }: PiniaPluginContext) => {
+ return ({ store }: PiniaPluginContext): UserProfileStore => {
const { loggedIn } = storeToRefs(store)
const { getProfile, userName } = useUser()
@@ -64,19 +69,16 @@ export const profilePlugin = (accountsUrl:MaybeRef<string>) :PiniaPlugin => {
userProfile.apply(profile)
}
- watch([loggedIn, onRefresh], ([li]) => {
- //If the user is logged in, load the profile buffer
- if (li) {
- apiCall(loadProfile)
- }
- })
+ //If the user is logged in, load the profile buffer
+ watch([loggedIn, onRefresh], ([li]) => li ? apiCall(loadProfile) : noop())
+ //Defer intiial profile load
defer(refreshProfile);
- return {
+ return storeExport({
userProfile,
refreshProfile,
userName
- }
+ })
}
} \ No newline at end of file