-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(calendar): preview all upcoming events
Signed-off-by: Maksim Sukharev <[email protected]>
- Loading branch information
Showing
2 changed files
with
206 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
<script setup lang="ts"> | ||
import { computed, onBeforeMount, ref } from 'vue' | ||
|
||
import IconCalendarBlank from 'vue-material-design-icons/CalendarBlank.vue' | ||
import IconCalendarRefresh from 'vue-material-design-icons/CalendarRefresh.vue' | ||
|
||
import { t } from '@nextcloud/l10n' | ||
import moment from '@nextcloud/moment' | ||
|
||
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' | ||
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js' | ||
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js' | ||
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js' | ||
import usernameToColor from '@nextcloud/vue/dist/Functions/usernameToColor.js' | ||
|
||
import { useGroupwareStore } from '../stores/groupware.ts' | ||
|
||
const props = defineProps<{ | ||
token: string, | ||
container?: string, | ||
}>() | ||
const emit = defineEmits<{ | ||
(event: 'close'): void, | ||
}>() | ||
|
||
const groupwareStore = useGroupwareStore() | ||
|
||
const open = ref(false) | ||
const loading = ref(Object.keys(groupwareStore.calendars).length === 0) | ||
|
||
const calendars = computed(() => groupwareStore.calendars) | ||
const upcomingEvents = computed(() => { | ||
const now = moment().unix() | ||
return groupwareStore.getAllEvents(props.token) | ||
.sort((a, b) => (a.start && b.start) ? (a.start - b.start) : 0) | ||
.map(event => { | ||
const start = event.start | ||
? (event.start <= now) ? t('spreed', 'Now') : moment(event.start * 1000).calendar() | ||
: '' | ||
const color = calendars.value[event.calendarUri]?.color ?? usernameToColor(event.calendarUri).color | ||
|
||
return { ...event, start, color, href: event.calendarAppUrl ?? undefined } | ||
}) | ||
}) | ||
|
||
onBeforeMount(() => { | ||
getCalendars() | ||
}) | ||
|
||
/** | ||
* Show upcoming events dialog | ||
*/ | ||
function openDialog() { | ||
open.value = true | ||
} | ||
|
||
/** | ||
* Get user's calendars to identify belonging of known and future events | ||
*/ | ||
async function getCalendars() { | ||
await groupwareStore.getPersonalCalendars() | ||
loading.value = false | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<slot name="trigger" :on-click="openDialog"> | ||
<NcButton :title="t('spreed', 'Upcoming events')" | ||
:aria-label="t('spreed', 'Upcoming events')" | ||
@click="openDialog"> | ||
<template #icon> | ||
<IconCalendarBlank :size="20" /> | ||
</template> | ||
</NcButton> | ||
</slot> | ||
|
||
<NcDialog :open.sync="open" | ||
class="calendar-events" | ||
:name="t('spreed', 'Upcoming events')" | ||
size="normal" | ||
close-on-click-outside | ||
:container="container"> | ||
<template v-if="!loading && upcomingEvents.length"> | ||
<ul class="calendar-events__list"> | ||
<!-- Upcoming event --> | ||
<li v-for="event in upcomingEvents" :key="event.uri"> | ||
<a class="calendar-events__item" | ||
:href="event.href" | ||
:title="t('spreed', 'Open Calendar')" | ||
target="_blank"> | ||
<IconCalendarRefresh v-if="event.recurrenceId" :size="20" /> | ||
<IconCalendarBlank v-else :size="20" /> | ||
<div class="calendar-badge" :style="{ backgroundColor: event.color }" /> | ||
<div class="calendar-events__content"> | ||
<p class="calendar-events__header"> | ||
{{ event.summary }} | ||
</p> | ||
<p>{{ event.start }}</p> | ||
</div> | ||
</a> | ||
</li> | ||
</ul> | ||
</template> | ||
<NcEmptyContent v-else> | ||
<template #icon> | ||
<NcLoadingIcon v-if="loading" /> | ||
<IconCalendarBlank v-else /> | ||
</template> | ||
|
||
<template #description> | ||
<p>{{ loading ? t('spreed', 'Loading …') : t('spreed', 'No upcoming events') }}</p> | ||
</template> | ||
</NcEmptyContent> | ||
</NcDialog> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.calendar-events { | ||
margin-block-end: calc(var(--default-grid-baseline) * 2); | ||
|
||
:deep(.dialog__content) { | ||
padding-block-end: calc(var(--default-grid-baseline) * 3); | ||
} | ||
|
||
&__list { | ||
display: flex; | ||
flex-direction: column; | ||
margin: var(--default-grid-baseline); | ||
gap: calc(var(--default-grid-baseline) * 2); | ||
} | ||
|
||
&__item { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: calc(var(--default-grid-baseline) * 2); | ||
padding: 0 calc(var(--default-grid-baseline) * 2); | ||
color: var(--color-primary-element-light-text); | ||
background-color: var(--color-primary-element-light); | ||
height: 100%; | ||
border-radius: var(--border-radius); | ||
|
||
&:hover { | ||
background-color: var(--color-primary-element-light-hover); | ||
} | ||
} | ||
|
||
&__content { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
line-height: 20px; | ||
} | ||
|
||
&__header { | ||
font-weight: 500; | ||
} | ||
} | ||
|
||
.calendar-badge { | ||
display: inline-block; | ||
width: var(--default-font-size); | ||
height: var(--default-font-size); | ||
border-radius: 50%; | ||
background-color: var(--primary-color); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters