66<script setup lang="ts">
77import NcUserBubble from ' @nextcloud/vue/components/NcUserBubble'
88import { PollsAppIcon } from ' ../components/AppIcons'
9+ import ExpirationIcon from ' vue-material-design-icons/CalendarEnd.vue'
10+ import BadgeSmallDiv from ' ../components/Base/modules/BadgeSmallDiv.vue'
11+ import { t } from ' @nextcloud/l10n'
12+ import { DateTime } from ' luxon'
13+ import { StatusResults } from ' ../Types'
914
1015type RichObject = {
1116 id: number
@@ -16,32 +21,71 @@ type RichObject = {
1621 ownerDisplayName: string
1722 ownerId: string
1823 url: string
24+ participated: boolean
25+ expiry: number
26+ expired: boolean
1927 }
2028}
2129
2230interface Props {
2331 richObject? : RichObject
2432}
25- const { richObject = null } = defineProps <Props >()
33+
34+ const { richObject } = defineProps <Props >()
35+ // const expiryClass2 = (() => {
36+ // if (!richObject?.poll?.expiry) {
37+ // return ''
38+ // }
39+ // if (DateTime.fromMillis(richObject.poll.expiry * 1000).diffNow('hours').hours < 36) {
40+ // return StatusResults.Warning
41+ // }
42+ // return StatusResults.Success
43+ // })
44+ const expiryClass = richObject ?.poll ?.expiry
45+ ? DateTime .fromMillis (richObject .poll .expiry * 1000 ).diffNow (' hours' ).hours < 36
46+ ? StatusResults .Warning
47+ : StatusResults .Success
48+ : ' '
2649 </script >
2750
2851<template >
2952 <div v-if =" richObject" class =" polls_widget" >
3053 <div class =" widget_header" >
3154 <PollsAppIcon :size =" 20 " class="title-icon" />
32- <span class =" title" >
55+ <a class =" title" :href = " richObject.poll.url " target = " _blank " >
3356 {{ richObject.poll.title }}
34- </span >
57+ </a >
58+ <BadgeSmallDiv v-if =" richObject .poll .participated " class="success">
59+ {{ t('polls', 'participated') }}
60+ </BadgeSmallDiv >
61+ <BadgeSmallDiv v-else-if =" richObject .poll .expired " class="error">
62+ {{ t('polls', 'closed') }}
63+ </BadgeSmallDiv >
64+ <BadgeSmallDiv
65+ v-else-if =" richObject .poll .expiry > 0 "
66+ :class =" expiryClass " >
67+ <template #icon >
68+ <ExpirationIcon :size =" 16 " />
69+ </template >
70+ {{ DateTime.fromMillis(richObject.poll.expiry * 1000).toRelative() }}
71+ </BadgeSmallDiv >
3572 </div >
3673 <div class =" description" >
3774 <span class =" clamped" >
3875 {{ richObject.poll.description }}
3976 </span >
4077 </div >
41- <div class =" owner" >
78+ <div class =" widget_footer" >
79+ <span >{{ t('polls', 'By:') }}</span >
4280 <NcUserBubble
4381 :user =" richObject .poll .ownerId "
4482 :display-name =" richObject .poll .ownerDisplayName " />
83+ <span
84+ v-if =" richObject.poll.expiry > 0 && !richObject.poll.expired"
85+ class =" expiration" >
86+ {{ t('polls', 'Ends in') }}
87+ {{ DateTime.fromMillis(richObject.poll.expiry * 1000).toRelative() }}
88+ </span >
4589 </div >
4690 </div >
4791</template >
@@ -50,17 +94,25 @@ const { richObject = null } = defineProps<Props>()
5094.polls_widget {
5195 padding : 0.6rem ;
5296}
53- .widget_header {
97+ .widget_header ,
98+ .widget_footer {
5499 display : flex ;
100+ column-gap : 0.3rem ;
55101}
56102
103+ .badge-small {
104+ flex : 0 ;
105+ }
57106.polls_app_icon {
58107 flex : 0 0 1.4rem ;
59108}
60109.title {
61110 flex : 1 ;
62111 font-weight : bold ;
63112 padding-left : 0.6rem ;
113+ text-wrap : nowrap ;
114+ overflow : hidden ;
115+ text-overflow : ellipsis ;
64116}
65117.description {
66118 margin-left : 1.4rem ;
0 commit comments