Skip to content

Commit

Permalink
Grab UID from storeToRefs rather than direct reference
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyel committed May 24, 2024
1 parent d8e58c2 commit 558354e
Show file tree
Hide file tree
Showing 26 changed files with 103 additions and 100 deletions.
4 changes: 2 additions & 2 deletions src/components/CardAdministration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ import { setBarChartData, setBarChartOptions } from '@/helpers/plotting';
const router = useRouter();

const authStore = useAuthStore();
const { roarfirekit, administrationQueryKeyIndex } = storeToRefs(authStore);
const { roarfirekit, administrationQueryKeyIndex, uid } = storeToRefs(authStore);

const props = defineProps({
id: { type: String, required: true },
Expand Down Expand Up @@ -390,7 +390,7 @@ const fetchTreeOrgs = async () => {
};

const { data: orgs, isLoading: loadingDsgfOrgs } = useQuery({
queryKey: ['dsgfOrgs', authStore.uid, props.id],
queryKey: ['dsgfOrgs', uid, props.id],
queryFn: () => fetchTreeOrgs(),
keepPreviousData: true,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/CreateOrgs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ const isTestData = ref(false);
const isDemoData = ref(false);
const toast = useToast();
const authStore = useAuthStore();
const { roarfirekit } = storeToRefs(authStore);
const { roarfirekit, uid } = storeToRefs(authStore);
const isLevante = import.meta.env.MODE === 'LEVANTE';
const state = reactive({
Expand Down Expand Up @@ -245,8 +245,8 @@ onMounted(() => {
});
const { isLoading: isLoadingClaims, data: userClaims } = useQuery({
queryKey: ['userClaims', authStore.uid],
queryFn: () => fetchDocById('userClaims', authStore.uid),
queryKey: ['userClaims', uid],
queryFn: () => fetchDocById('userClaims', uid.value),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
12 changes: 6 additions & 6 deletions src/components/ListOrgs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ const schoolPlaceholder = computed(() => {
// Authstore and Sidebar
const authStore = useAuthStore();
const { roarfirekit, userQueryKeyIndex } = storeToRefs(authStore);
const { roarfirekit, uid, userQueryKeyIndex } = storeToRefs(authStore);
const { isLoading: isLoadingClaims, data: userClaims } = useQuery({
queryKey: ['userClaims', authStore.uid, userQueryKeyIndex],
queryFn: () => fetchDocById('userClaims', authStore.uid),
queryKey: ['userClaims', uid, userQueryKeyIndex],
queryFn: () => fetchDocById('userClaims', uid.value),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down Expand Up @@ -149,7 +149,7 @@ const activeOrgType = computed(() => {
const claimsLoaded = computed(() => !isLoadingClaims.value);
const { isLoading: isLoadingDistricts, data: allDistricts } = useQuery({
queryKey: ['districts', authStore.uid, orgsQueryKeyIndex],
queryKey: ['districts', uid, orgsQueryKeyIndex],
queryFn: () => orgFetcher('districts', undefined, isSuperAdmin, adminOrgs),
keepPreviousData: true,
enabled: claimsLoaded,
Expand All @@ -161,7 +161,7 @@ const schoolQueryEnabled = computed(() => {
});
const { isLoading: isLoadingSchools, data: allSchools } = useQuery({
queryKey: ['schools', authStore.uid, selectedDistrict, orgsQueryKeyIndex],
queryKey: ['schools', uid, selectedDistrict, orgsQueryKeyIndex],
queryFn: () => orgFetcher('schools', selectedDistrict, isSuperAdmin, adminOrgs),
keepPreviousData: true,
enabled: schoolQueryEnabled,
Expand All @@ -173,7 +173,7 @@ const {
isFetching,
data: orgData,
} = useQuery({
queryKey: ['orgsPage', authStore.uid, activeOrgType, selectedDistrict, selectedSchool, orderBy, orgsQueryKeyIndex],
queryKey: ['orgsPage', uid, activeOrgType, selectedDistrict, selectedSchool, orderBy, orgsQueryKeyIndex],
queryFn: () =>
orgPageFetcher(
activeOrgType,
Expand Down
4 changes: 2 additions & 2 deletions src/components/ListUsers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { singularizeFirestoreCollection } from '@/helpers';
const authStore = useAuthStore();
const { roarfirekit } = storeToRefs(authStore);
const { roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
const page = ref(0);
Expand All @@ -80,7 +80,7 @@ const {
isFetching,
data: users,
} = useQuery({
queryKey: ['usersByOrgPage', authStore.uid, props.orgType, props.orgId, page, orderBy],
queryKey: ['usersByOrgPage', uid, props.orgType, props.orgId, page, orderBy],
queryFn: () => fetchUsersByOrg(props.orgType, props.orgId, ref(1000000), page, orderBy),
keepPreviousData: true,
enabled: initialized,
Expand Down
6 changes: 3 additions & 3 deletions src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import LanguageSelector from './LanguageSelector.vue';
const router = useRouter();
const authStore = useAuthStore();
const { roarfirekit } = storeToRefs(authStore);
const { roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
const menu = ref();
const screenWidth = ref(window.innerWidth);
Expand Down Expand Up @@ -88,8 +88,8 @@ onUnmounted(() => {
// ---------------------------------------------------------------
const { data: userClaims, isLoading: userClaimsLoading } = useQuery({
queryKey: ['userClaims', authStore.uid],
queryFn: () => fetchDocById('userClaims', authStore.uid),
queryKey: ['userClaims', uid],
queryFn: () => fetchDocById('userClaims', uid.value),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
7 changes: 3 additions & 4 deletions src/components/OrgPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import { fetchDocById, orderByDefault } from '@/helpers/query/utils';
const initialized = ref(false);
const authStore = useAuthStore();
const { roarfirekit, uid } = storeToRefs(authStore);
const selectedDistrict = ref(undefined);
const selectedSchool = ref(undefined);
Expand Down Expand Up @@ -141,8 +142,8 @@ watch(
);
const { isLoading: isLoadingClaims, data: userClaims } = useQuery({
queryKey: ['userClaims', authStore.uid],
queryFn: () => fetchDocById('userClaims', authStore.uid),
queryKey: ['userClaims', uid],
queryFn: () => fetchDocById('userClaims', uid.value),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down Expand Up @@ -252,8 +253,6 @@ const init = () => {
initialized.value = true;
};
const { roarfirekit } = storeToRefs(authStore);
unsubscribe = authStore.$subscribe(async (mutation, state) => {
if (state.roarfirekit.restConfig) init();
});
Expand Down
14 changes: 7 additions & 7 deletions src/components/auth/AuthEmailLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import { fetchDocById } from '@/helpers/query/utils';
const router = useRouter();
const authStore = useAuthStore();
const { roarfirekit } = storeToRefs(authStore);
const { roarfirekit, uid } = storeToRefs(authStore);
const success = ref(false);
authStore.$subscribe(async () => {
if (authStore.uid) {
const userData = await fetchDocById('users', authStore.uid);
const userClaims = await fetchDocById('userClaims', authStore.uid);
if (uid.value) {
const userData = await fetchDocById('users', uid.value);
const userClaims = await fetchDocById('userClaims', uid.value);
authStore.userData = userData;
authStore.userClaims = userClaims;
success.value = true;
Expand Down Expand Up @@ -79,9 +79,9 @@ const loginFromEmailLink = async (email) => {
}
})
.then(async () => {
if (authStore.uid) {
const userData = await fetchDocById('users', authStore.uid);
const userClaims = await fetchDocById('userClaims', authStore.uid);
if (uid) {
const userData = await fetchDocById('users', uid.value);
const userClaims = await fetchDocById('userClaims', uid.value);
authStore.userData = userData;
authStore.userClaims = userClaims;
success.value = true;
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskCrowding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskFluency.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskLetter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskLevante.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskMultichoice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskPA.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskRan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskSRE.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskSWR.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
6 changes: 3 additions & 3 deletions src/components/tasks/TaskVocab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = useRouter();
const gameStarted = ref(false);
const authStore = useAuthStore();
const gameStore = useGameStore();
const { isFirekitInit, roarfirekit } = storeToRefs(authStore);
const { isFirekitInit, roarfirekit, uid } = storeToRefs(authStore);
const initialized = ref(false);
let unsubscribe;
Expand All @@ -46,8 +46,8 @@ unsubscribe = authStore.$subscribe(async (mutation, state) => {
});
const { isLoading: isLoadingUserData, data: userData } = useQuery({
queryKey: ['userData', authStore.uid, 'studentData'],
queryFn: () => fetchDocById('users', authStore.uid, ['studentData']),
queryKey: ['userData', uid, 'studentData'],
queryFn: () => fetchDocById('users', uid.value, ['studentData']),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
4 changes: 3 additions & 1 deletion src/pages/ClassLinkLanding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
</template>
<script setup>
import { useAuthStore } from '@/store/auth.js';
import { storeToRefs } from 'pinia';
import { useRouter } from 'vue-router';
import _get from 'lodash/get';
import AppSpinner from '@/components/AppSpinner.vue';
import { fetchDocById } from '@/helpers/query/utils';
const router = useRouter();
const authStore = useAuthStore();
const { uid } = storeToRefs(authStore);
let userDataCheckInterval;
async function checkForUserType() {
try {
const userData = await fetchDocById('users', authStore.uid);
const userData = await fetchDocById('users', uid.value);
const userType = _get(userData, 'userType');
if (userType && userType !== 'guest') {
clearInterval(userDataCheckInterval);
Expand Down
Loading

0 comments on commit 558354e

Please sign in to comment.