-
Notifications
You must be signed in to change notification settings - Fork 269
/
Copy pathNewMessageButtonHeader.vue
101 lines (98 loc) · 2.38 KB
/
NewMessageButtonHeader.vue
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
<!--
- SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div class="header">
<ButtonVue :aria-label="t('mail', 'New message')"
type="secondary"
button-id="mail_new_message"
role="complementary"
:wide="true"
@click="onNewMessage">
<template #icon>
<IconAdd :size="16" />
</template>
{{ t('mail', 'New message') }}
</ButtonVue>
<ButtonVue v-if="currentMailbox"
:aria-label="t('mail', 'Refresh')"
type="tertiary-no-background"
class="refresh__button"
:disabled="refreshing"
@click="refreshMailbox">
<template #icon>
<IconRefresh v-if="!refreshing"
:size="16" />
<IconLoading v-if="refreshing"
:size="16" />
</template>
</ButtonVue>
</div>
</template>
<script>
import { NcButton as ButtonVue } from '@nextcloud/vue'
import IconAdd from 'vue-material-design-icons/Plus.vue'
import IconRefresh from 'vue-material-design-icons/Refresh.vue'
import IconLoading from '@nextcloud/vue/components/NcLoadingIcon'
import logger from '../logger.js'
import { mapStores } from 'pinia'
import useMainStore from '../store/mainStore.js'
export default {
name: 'NewMessageButtonHeader',
components: {
ButtonVue,
IconAdd,
IconRefresh,
IconLoading,
},
data() {
return {
refreshing: false,
}
},
computed: {
...mapStores(useMainStore),
currentMailbox() {
if (this.$route.name === 'message' || this.$route.name === 'mailbox') {
return this.mainStore.getMailbox(this.$route.params.mailboxId)
}
return undefined
},
},
methods: {
async refreshMailbox() {
if (this.refreshing === true) {
logger.debug('already sync\'ing mailbox.. aborting')
return
}
this.refreshing = true
try {
await this.mainStore.syncEnvelopes({ mailboxId: this.currentMailbox.databaseId })
logger.debug('Current mailbox is sync\'ing ')
} catch (error) {
logger.error('could not sync current mailbox', { error })
} finally {
this.refreshing = false
}
},
async onNewMessage() {
await this.mainStore.startComposerSession({
isBlankMessage: true,
})
},
},
}
</script>
<style lang="scss" scoped>
.header {
display: flex;
align-items: center;
justify-content: space-between;
padding: calc(var(--default-grid-baseline, 4px) * 2);
gap: var(--default-grid-baseline);
}
.refresh__button {
background-color: transparent;
}
</style>