()
| 47 | } |
| 48 | |
| 49 | export async function hydrate(): Promise<void> { |
| 50 | const stores = useStores(); |
| 51 | |
| 52 | const appStore = useAppStore(); |
| 53 | const userStore = useUserStore(); |
| 54 | const permissionsStore = usePermissionsStore(); |
| 55 | const fieldsStore = useFieldsStore(); |
| 56 | |
| 57 | if (appStore.hydrated) return; |
| 58 | if (appStore.hydrating) return; |
| 59 | |
| 60 | appStore.hydrating = true; |
| 61 | |
| 62 | try { |
| 63 | /** |
| 64 | * @NOTE |
| 65 | * Multiple stores rely on the userStore to be set, so they can fetch user specific data. The |
| 66 | * following makes sure that the user store is always fetched first, before we hydrate anything |
| 67 | * else. |
| 68 | */ |
| 69 | await userStore.hydrate(); |
| 70 | |
| 71 | const currentUser = userStore.currentUser; |
| 72 | |
| 73 | if (currentUser?.app_access) { |
| 74 | await Promise.all([permissionsStore.hydrate(), fieldsStore.hydrate({ skipTranslation: true })]); |
| 75 | |
| 76 | const hydratedStores = ['userStore', 'permissionsStore', 'fieldsStore', 'serverStore']; |
| 77 | await Promise.all(stores.filter(({ $id }) => !hydratedStores.includes($id)).map((store) => store.hydrate?.())); |
| 78 | |
| 79 | await onHydrateExtensions(); |
| 80 | } |
| 81 | |
| 82 | await setLanguage(userStore.language); |
| 83 | |
| 84 | appStore.basemap = getBasemapSources()[0].name; |
| 85 | } catch (error: any) { |
| 86 | appStore.error = error; |
| 87 | } finally { |
| 88 | appStore.hydrating = false; |
| 89 | } |
| 90 | |
| 91 | appStore.hydrated = true; |
| 92 | } |
| 93 | |
| 94 | export async function dehydrate(stores = useStores()): Promise<void> { |
| 95 | const appStore = useAppStore(); |
no test coverage detected