BuildingView.vue 1.72 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 BuildingPicker from '@/components/BuildingPicker.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 BuildingForm from '@/components/forms/BuildingForm.vue'
import { useApartmentStore } from '@/stores/apartments'
import { useBuildingStore } from '@/stores/buildings'
import { useUserStore } from '@/stores/users'

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

const apartments = useApartmentStore()
const buildings = useBuildingStore()
const users = useUserStore()

function handleModal() {
  showModal.value = !showModal.value
}

onMounted(() => {
  Promise.all([
    apartments.fetchApartments(),
    buildings.fetchBuildings(),
    users.fetchUsers()
  ])
    .then(() => {
      isLoading.value = false
    })
})
</script>

<template>
  <PageContainer v-if="!isLoading">
    <AppBar>
      <BuildingPicker />
      <button v-if="buildings.firstBuilding?.setupCompleted" class="button secondary" type="button" @click="handleModal">
        <div class="button-content">
          <span>Neues Gebäude</span>
        </div>
        <div class="button-icon">
          <font-awesome-icon icon="fa-solid fa-plus" />
        </div>
      </button>
    </AppBar>
    <PageContent>
      <router-view></router-view>
    </PageContent>
  </PageContainer>
  <ContentLoading v-else />
  <ModalContainer v-if="showModal" label="Gebäude anlegen" @close-modal="handleModal">
    <BuildingForm @close-modal="handleModal" />
  </ModalContainer>
</template>