ApartmentView.vue 1.56 KB
Newer Older
abergavenny's avatar
abergavenny committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<script setup>
import { onMounted, ref } from 'vue'

import AppBar from '@/components/AppBar.vue'
import ContentLoading from '@/components/ContentLoading.vue'
import ModalContainer from '@/components/ModalContainer.vue'
import PageContainer from '@/components/PageContainer.vue'
import PageContent from '@/components/PageContent.vue'
import TermsRequest from '@/components/TermsRequest.vue'
import { useApartmentStore } from '@/stores/apartments'
import { useBuildingStore } from '@/stores/buildings'
import { useSessionStore } from '@/stores/session'

const isLoading = ref(true)
const showModal = ref(false)

const apartments = useApartmentStore()
const buildings = useBuildingStore()
const session = useSessionStore()

function handleModal() {
  showModal.value = false
}

onMounted(() => {
  Promise.all([
    session.fetchSelf(),
    apartments.fetchApartments()
  ])
    .then(async () => {
      let buildingId, apartmentId

      if (apartments.data.length > 0) {
        buildingId = apartments.data[0].linkedTo
        apartmentId = apartments.data[0]._id

        apartments.setActiveApartment(apartmentId)
      }

      await buildings.fetchBuildingById(buildingId)
    })
    .finally(() => {
      isLoading.value = false
    })
})
</script>

<template>
  <PageContainer v-if="!isLoading">
    <AppBar />
    <PageContent>
      <router-view></router-view>
    </PageContent>
  </PageContainer>
  <ContentLoading v-else />
  <ModalContainer v-if="!session.self?.sharingAllowed" :permanent="true">
    <TermsRequest @on-close-modal="handleModal" />
  </ModalContainer>
</template>