~cypheon/nextcloud-chores-app

ref: d19a6603c01e63c7545582e5ff313ef4aec0bf9f nextcloud-chores-app/src/App.vue -rw-r--r-- 5.4 KiB
d19a6603 — Johann Rudloff Make overdue sidebar badge dynamic, switch badges to `CounterBubble` component 3 months ago
                                                                                
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<template>
  <Content app-name="chores">
    <AppNavigation v-if="store.haveTeamInfo && userHasTeam">
      <template #list>
        <AppNavigationNew text="Add new Chore" button-class="icon-add" @click="addNewChore" />
        <AppNavigationItem :title="`Team - ${store.team.name}`" :pinned="false"
        icon="icon-contacts-dark" :open="false" :allow-collapse="true"
        to="/" />
        <AppNavigationItem title="All Chores" :pinned="false"
        icon="icon-menu" :open="false" :allow-collapse="true"
        to="/all" />
        <AppNavigationItem title="Overdue" :pinned="false"
        icon="icon-error" :open="false" :allow-collapse="true"
        to="/overdue" >
          <CounterBubble slot="counter" :highlighted="true" v-show="overdueChoresCount > 0">
            {{overdueChoresCount}}
          </CounterBubble>
        </AppNavigationItem>
        <AppNavigationItem title="Upcoming" :pinned="false"
        icon="icon-calendar-dark" :open="false" :allow-collapse="true"
        to="/upcoming" />
        <AppNavigationItem title="History" :pinned="false"
        icon="icon-history" :open="false" :allow-collapse="true"
        to="/history" />
      </template>
      <template #footer>
        <AppNavigationItem title="Settings" icon="icon-settings" />
      </template>
    </AppNavigation>
    <AppContent v-if="store.haveTeamInfo && userHasTeam">
      <div class="app-body">
        <router-view></router-view>
      </div>
    </AppContent>

    <AppNavigation v-if="store.haveTeamInfo && !userHasTeam">
      <template #list>
        <AppNavigationNew text="Create new team" button-class="icon-add" />
        <AppNavigationItem title="Invitations" class="active">
          <CounterBubble slot="counter" :highlighted="false">
            {{store.invites.length}}
          </CounterBubble>
        </AppNavigationItem>
      </template>
      <template #footer>
        <AppNavigationItem title="Settings" icon="icon-settings" />
      </template>
    </AppNavigation>
    <AppContent v-if="store.haveTeamInfo && !userHasTeam">
      <div class="app-body no-team-info">
        <div class="icon-no-team" role="img"></div>
        <div class="create-team-area">
        <strong>
        You're not part of any team yet
        </strong>

        <div v-if="store.invites.length >= 1">
          <ul>
            <li v-for="(invite) in store.invites" :key="invite.teamId">
              <h2>
                Join team "{{invite.teamName}}"
              </h2>
              <p>
                Join this team by accepting the invitation:
              </p>
              <button class="primary" @click="acceptInvite(invite)">
                Accept invitation from team "{{invite.teamName}}"
              </button>
            </li>
          </ul>
        </div>

        <h2>
          Create new team
        </h2>
        <p>
          Create a new team to get started or ask someone for an invitation.
        </p>
        <div>
          <form>
            <input class="no-close" type="text" placeholder="Team name"
            v-model="newTeamName" required />
            <input type="submit" class="icon-confirm" value=" "
            @click="createTeam" />
          </form>
        </div>

        <div v-if="store.invites.length === 0">
          <h3>
            Join an existing Team
          </h3>
          <p>
            There are no pending invitations.
          </p>
        </div>


        </div>
      </div>
    </AppContent>
    <router-view name="sidebar" :visible="true" />
  </Content>
</template>

<script>
import { Content } from '@nextcloud/vue'
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
import CounterBubble from '@nextcloud/vue/dist/Components/CounterBubble'
import { AppNavigation, AppNavigationItem, AppNavigationNew } from '@nextcloud/vue'
import { isOverdue } from './logic';

export default {
  name: 'App',
  components: {
    AppContent,
    AppNavigation,
    AppNavigationItem,
    AppNavigationNew,
    Content,
    CounterBubble,
  },
  data() {
    return {
      store: this.$root.$data.globalStore,
      newTeamName: "",
      now: new Date(),
    }
  },
  methods: {
    createTeam() {
      if (!this.newTeamName || this.newTeamName === '') {
        return false;
      }
      this.store.createNewTeam({
        name: this.newTeamName,
      });
      return false;
    },
    acceptInvite(invite) {
      this.store.acceptInvitation(invite);
    },
    addNewChore() {
      this.$router.push("/all/chore/new");
    },
  },
  mounted: async function() {
    await this.store.loadTeamData();
    await this.store.loadChoresData();
  },
  computed: {
    userHasTeam() {
      return this.store.team !== null;
    },
    overdueChoresCount() {
      return this.store.chores.filter(c => isOverdue(c, this.now)).length;
    },
  },
}
</script>

<style>
.app-body {
  /*font-family: Avenir, Helvetica, Arial, sans-serif;*/
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /*text-align: center;*/
  color: #2c3e50;
  margin-top: 60px;
  padding: 15px;
}
.icon-no-team {
  background-image: url(../img/app_grey.svg);
  background-size: 64px;
  width: 64px;
  height: 64px;
}
.no-team-info {
  padding: 1rem;
  height: 60%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.create-team-area {
  margin: 0 auto;
  text-align: center;
}
.no-team-info h2, .no-team-info h3 {
  margin-top: 2rem;
}
</style>