Skip to content

Commit

Permalink
fix bug with study selector navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattis committed Mar 27, 2024
1 parent 065af0e commit c007b8a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 31 deletions.
4 changes: 3 additions & 1 deletion src/helpers/user.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export async function loadUser () {
loading.value = true
try {
user.value = await UserService.loadCurrentUser()
userPermissions.value = await PermissionService.fetchUserPermissions(user.value)
if (user.value) {
userPermissions.value = await PermissionService.fetchUserPermissions(user.value)
}
} finally {
loading.value = false
}
Expand Down
6 changes: 3 additions & 3 deletions src/router/guards/StudyGuard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Route } from 'vue-router'
import SingletonService from '../../services/SingletonService'
import SingletonService, { StorageKey } from '../../services/SingletonService'
import StudyService from '../../services/study'
import StorageService from '../../services/StorageService'
import { GuardConfig } from '../GuardQueue'

export default {
name: 'StudyGuard',
async condition (to: Route) {
const studyId = StorageService.get('current-study')
const studyId = StorageService.get(StorageKey.study)
if (!studyId) {
return false
}
Expand All @@ -18,7 +18,7 @@ export default {
}
return !!study
} catch (err) {
StorageService.delete('current-study')
StorageService.delete(StorageKey.study)
}
try {
const study = to.params.studyId
Expand Down
21 changes: 0 additions & 21 deletions src/services/SingletonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,6 @@ class SingletonService extends Emitter {
singleton.darkTheme = storage.get(StorageKey.theme)
theme.dark = singleton.darkTheme
}
/* Moved to ValidateStudy Guard
if (storage.get(StorageKey.study)) {
const studyId = storage.get(StorageKey.study)
if (!studyId) return
singleton.study = await StudyService.getStudy(studyId)
this.dispatch('study', singleton.study)
}
*/
/* Moved to ValidateLocale Guard
if (storage.get(StorageKey.locale)) {
const localeId = storage.get(StorageKey.locale)
if (!localeId) return
const locale = await LocaleService.getLocaleById(localeId)
if (locale) {
this.setCurrentLocale(locale)
}
console.log('loaded locale', singleton.locale)
}
*/
singleton.deviceId = await DeviceService.getUUID()
if (config.appEnv === APP_ENV.CORDOVA && config.sentry) {
const server = await DatabaseService.getServerIPAddress()
Expand All @@ -81,8 +62,6 @@ class SingletonService extends Emitter {
const tag = locale.languageTag
setLocale(tag)
loadLanguageAsync(tag)
// i18n.locale = i18n.messages[locale.languageTag] ? locale.languageTag : 'en'
singleton
singleton.locale = locale
storage.set(StorageKey.locale, locale.id)
this.dispatch(SingletonEvent.locale, locale)
Expand Down
1 change: 0 additions & 1 deletion src/services/locale/LocaleService.mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class LocaleService extends LocaleServiceAbstract {

async getStudyLocales (studyId: string): Promise<Locale[]> {
const study = await StudyService.getStudy(studyId)
console.log('study', study)
return study ? await study.locales : []
}

Expand Down
4 changes: 1 addition & 3 deletions src/services/permission/PermissionServiceAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ export default abstract class PermissionServiceAbstract {
* @param user
*/
public async getUserPermissions (user: User): Promise<PermissionMap> {

this.resetUserPermissions()

// Get permissions for this user only if they've logged in
if (user) {
let updatedPermissions = await this.fetchUserPermissions(user)
const updatedPermissions = await this.fetchUserPermissions(user)
for (const p of updatedPermissions) {
this.userPermissions[TrellisPermission[p]] = true
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/study/StudyServiceAbstract.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import User from '../../entities/trellis/User'
import Study from '../../entities/trellis/Study'
import SingletonService from '../SingletonService'
import SingletonService, { StorageKey } from '../SingletonService'

export abstract class StudyServiceAbstract {
getCurrentStudy (): Study | undefined {
const study = SingletonService.get('study')
const study = SingletonService.get(StorageKey.study)
return (study instanceof Study) ? study : undefined
}

Expand Down

0 comments on commit c007b8a

Please sign in to comment.