Skip to content

Commit

Permalink
#72 introduced useFirestoreUser() hook and using it to show private/p…
Browse files Browse the repository at this point in the history
…ublic tokens on user dashboard page, thus allowing to remove those fields from user-tokens-wallet collection
  • Loading branch information
fcamblor committed May 15, 2024
1 parent b61404d commit 4321722
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
10 changes: 10 additions & 0 deletions mobile/src/models/VoxxrinUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ import {
} from "../../../shared/user-tokens-wallet.localstorage";
import {TalkId} from "@/models/VoxxrinTalk";
import {Replace} from "../../../shared/type-utils";
import {User} from "../../../shared/user.firestore";


export class UserLocale extends ValueObject<string>{ _userLocaleClassDiscriminator!: never; }

export type VoxxrinUser = Replace<User, {}>

export function toVoxxrinUser(firestoreUser: User): VoxxrinUser {
return { ...firestoreUser };
}
export function toFirestoreUser(voxxrinUser: VoxxrinUser): User {
return { ...voxxrinUser };
}

export type VoxxrinUserPreferences = Replace<UserPreferences, {
pinnedEventIds: Array<EventId>
}>
Expand Down
31 changes: 30 additions & 1 deletion mobile/src/state/useCurrentUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {UserLocale} from "@/models/VoxxrinUser";
import {toVoxxrinUser, UserLocale} from "@/models/VoxxrinUser";
import {useCurrentUser as vueFireUseCurrentUser} from "vuefire";
import {computed, toValue} from "vue";
import {db} from "@/state/firebase";
import {deferredVuefireUseDocument} from "@/views/vue-utils";
import {doc, DocumentReference} from "firebase/firestore";
import {User} from "../../../shared/user.firestore";


export function useCurrentUserLocale() {
Expand All @@ -9,3 +14,27 @@ export function useCurrentUserLocale() {
}

export const useCurrentUser = vueFireUseCurrentUser;

export function useFirestoreUser() {
const userRef = useCurrentUser()

const firestoreUserRef = deferredVuefireUseDocument([userRef],
([user]) => {
if(!user) {
return undefined;
}

return doc(db, `users/${user.uid}`) as DocumentReference<User>
})

return {
userRef: computed(() => {
const firestoreUser = toValue(firestoreUserRef);
if(!firestoreUser) {
return undefined;
}

return toVoxxrinUser(firestoreUser);
})
}
}
8 changes: 4 additions & 4 deletions mobile/src/views/user/UserDashboardPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
</div>
<div class="userDashboard-user-infos">
<strong>{{ LL.Anonymous_private_user_id() }}:</strong><br/>
<span class="userUid">{{currentUserRef?.uid}}</span><br/>
<span class="userUid">{{userRef?.privateUserId}}</span><br/>
<small>{{LL.Please_keep_this_token_private()}}</small><br/>
<hr/>
<strong>{{ LL.Public_user_id() }}:</strong><br/>
<span class="userUid">{{userTokensWalletRef?.publicUserToken}}</span><br/>
<span class="userUid">{{ userRef?.publicUserToken }}</span><br/>
<small>{{LL.This_token_will_be_used_to_reference_you_in_APIs()}}</small><br/>
</div>
</div>
Expand Down Expand Up @@ -97,7 +97,7 @@
<script setup lang="ts">
import {useIonRouter} from "@ionic/vue";
import {useCurrentUser} from "@/state/useCurrentUser";
import {useFirestoreUser} from "@/state/useCurrentUser";
import Callout from "@/components/ui/Callout.vue";
import {typesafeI18n} from "@/i18n/i18n-vue";
import {computed, toValue} from "vue";
Expand All @@ -107,7 +107,7 @@ import {helpCircle} from "ionicons/icons";
const ionRouter = useIonRouter();
const currentUserRef = useCurrentUser();
const { userRef } = useFirestoreUser();
const { LL } = typesafeI18n()
const { userTokensWalletRef } = useUserTokensWallet();
Expand Down
2 changes: 0 additions & 2 deletions shared/user-tokens-wallet.localstorage.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

export type UserTokensWallet = {
privateUserId: string;
publicUserToken: string;
secretTokens: {
eventOrganizerTokens: UserWalletEventOrganizerSecretToken[],
talkFeedbacksViewerTokens: UserWalletTalkFeedbacksViewerSecretToken[]
Expand Down

0 comments on commit 4321722

Please sign in to comment.