Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@nextcloud/initial-state": "^2.2.0",
"@nextcloud/l10n": "^3.3.0",
"@nextcloud/logger": "^3.0.2",
"@nextcloud/moment": "^1.3.4",
"@nextcloud/router": "^3.0.1",
"@nextcloud/vue": "^9.0.0-rc.3",
"@vueuse/core": "^13.4.0",
Expand Down
28 changes: 13 additions & 15 deletions src/components/Calendar/CalendarInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
-->

<script setup lang="ts">
import moment from '@nextcloud/moment'
import { computed } from 'vue'
import { DateTime } from 'luxon'
import { CalendarEvent } from '../../components/Calendar/CalendarPeek.vue'

import type { Option } from '../../stores/options.types'
Expand Down Expand Up @@ -37,31 +37,29 @@ const fontColor = computed(() => {
return l > 0.5 ? '#222' : '#ddd'
})

const dayStart = computed(() => moment.unix(calendarEvent.start).format('ddd'))

const dayEnd = computed(() => moment.unix(calendarEvent.end - 1).format('ddd'))
const eventStart = computed(() => DateTime.fromSeconds(calendarEvent.start))
const eventEnd = computed(() => DateTime.fromSeconds(calendarEvent.end))

const dayDisplay = computed(() => {
if (dayEnd.value === dayStart.value) {
return dayStart.value
if (eventEnd.value.hasSame(eventStart.value.minus({ second: 1 }), 'day')) {
return eventStart.value.toLocaleString({ weekday: 'short' })
}

return `${dayStart.value} - ${dayEnd.value}`
return `${eventStart.value.toLocaleString({ weekday: 'short' })} - ${eventEnd.value.toLocaleString({ weekday: 'short' })}`
})

const timeStart = computed(() => moment.unix(calendarEvent.start).format('LT'))

const timeEnd = computed(() => moment.unix(calendarEvent.end).format('LT'))

const timeDisplay = computed(() => {
if (timeEnd.value === timeStart.value) {
return timeStart.value
if (eventStart.value.hasSame(eventEnd.value, 'minute')) {
return eventStart.value.toLocaleString(DateTime.TIME_SIMPLE)
}
return `${timeStart.value} - ${timeEnd.value}`

return `${eventStart.value.toLocaleString(DateTime.TIME_SIMPLE)} - ${eventEnd.value.toLocaleString(DateTime.TIME_SIMPLE)}`
})

const showJustDays = computed(
() => dayStart.value !== dayEnd.value || calendarEvent.allDay,
() =>
!eventEnd.value.hasSame(eventStart.value.minus({ second: 1 }), 'day')
|| calendarEvent.allDay,
)

const statusClass = computed(() => calendarEvent.status.toLowerCase())
Expand Down
13 changes: 7 additions & 6 deletions src/components/Calendar/CalendarPeek.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { computed, onMounted, ref } from 'vue'
import { t } from '@nextcloud/l10n'
import orderBy from 'lodash/orderBy'
import moment from '@nextcloud/moment'
import { DateTime } from 'luxon'

import NcPopover from '@nextcloud/vue/components/NcPopover'
import NcButton from '@nextcloud/vue/components/NcButton'
Expand Down Expand Up @@ -48,12 +48,13 @@ const events = ref<CalendarEvent[]>([])
const pollStore = usePollStore()

const detectAllDay = computed(() => {
const from = moment.unix(option.timestamp)
const to = moment.unix(option.timestamp + Math.max(0, option.duration))
const from = DateTime.fromSeconds(option.timestamp)

const dayLongEvent =
from.unix() === moment(from).startOf('day').unix()
&& to.unix() === moment(to).startOf('day').unix()
&& from.unix() !== to.unix()
from.startOf('day')
&& from.plus({ seconds: option.duration }).startOf('day')
&& option.duration > 0

return {
allDay: dayLongEvent,
type: dayLongEvent ? 'date' : 'dateTime',
Expand Down
4 changes: 2 additions & 2 deletions src/components/Comments/CommentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { computed } from 'vue'

import linkifyStr from 'linkify-string'
import { DateTime } from 'luxon'
import { t } from '@nextcloud/l10n'
import moment from '@nextcloud/moment'
import { showError } from '@nextcloud/dialogs'

import ActionDelete from '../Actions/modules/ActionDelete.vue'
Expand All @@ -30,7 +30,7 @@ const preferencesStore = usePreferencesStore()
const { comment } = defineProps<{ comment: CommentsGrouped }>()

const dateCommentedRelative = computed(() =>
moment.unix(comment.timestamp).fromNow(),
DateTime.fromSeconds(comment.timestamp).toRelative(),
)

const isCurrentUser = computed(
Expand Down
13 changes: 6 additions & 7 deletions src/components/Configuration/ConfigClosing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<script setup lang="ts">
import { computed } from 'vue'
import moment from '@nextcloud/moment'
import { DateTime } from 'luxon'
import { t } from '@nextcloud/l10n'

import NcButton from '@nextcloud/vue/components/NcButton'
Expand All @@ -20,9 +20,9 @@ import { usePollStore } from '../../stores/poll'
const pollStore = usePollStore()

const expire = computed({
get: () => moment.unix(pollStore.configuration.expire)._d,
get: () => pollStore.getExpirationDateTime.toJSDate(),
set: (value) => {
pollStore.configuration.expire = moment(value).unix()
pollStore.configuration.expire = DateTime.fromJSDate(value).toSeconds()
pollStore.write()
},
})
Expand All @@ -31,17 +31,16 @@ const useExpire = computed({
get: () => !!pollStore.configuration.expire,
set: (value) => {
if (value) {
pollStore.configuration.expire = moment().add(1, 'week').unix()
pollStore.configuration.expire = DateTime.now()
.plus({ week: 1 })
.toSeconds()
} else {
pollStore.configuration.expire = 0
}
pollStore.write()
},
})

/**
*
*/
function clickToggleClosed() {
if (pollStore.isClosed) {
pollStore.reopen()
Expand Down
11 changes: 7 additions & 4 deletions src/components/Configuration/ConfigProposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<script setup lang="ts">
import { computed } from 'vue'
import moment from '@nextcloud/moment'
import { DateTime } from 'luxon'
import { t } from '@nextcloud/l10n'

import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
Expand All @@ -24,9 +24,10 @@ const allowProposals = computed({
})

const pollExpire = computed({
get: () => moment.unix(pollStore.configuration.proposalsExpire)._d,
get: () => pollStore.getProposalExpirationDateTime.toJSDate(),
set: (value) => {
pollStore.configuration.proposalsExpire = moment(value).unix()
pollStore.configuration.proposalsExpire =
DateTime.fromJSDate(value).toSeconds()
pollStore.write()
},
})
Expand All @@ -35,7 +36,9 @@ const proposalExpiration = computed({
get: () => !!pollStore.configuration.proposalsExpire,
set: (value) => {
if (value) {
pollStore.configuration.proposalsExpire = moment().add(1, 'week').unix()
pollStore.configuration.proposalsExpire = DateTime.now()
.plus({ week: 1 })
.toSeconds()
} else {
pollStore.configuration.proposalsExpire = 0
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Options/OptionCloneDate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<script setup lang="ts">
import { computed, ref } from 'vue'
import moment from '@nextcloud/moment'
import { DateTime } from 'luxon'
import { t } from '@nextcloud/l10n'

import NcSelect from '@nextcloud/vue/components/NcSelect'
Expand Down Expand Up @@ -36,7 +36,7 @@ const sequence = ref<Sequence>({
})

const dateBaseOptionString = computed(() =>
moment.unix(option.timestamp).format('LLLL'),
DateTime.fromSeconds(option.timestamp).toLocaleString(DateTime.DATETIME_FULL),
)

/**
Expand Down
7 changes: 3 additions & 4 deletions src/components/Poll/PollInfoLine.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<script setup lang="ts">
import { computed } from 'vue'
import moment from '@nextcloud/moment'
import { t } from '@nextcloud/l10n'

import { usePollStore } from '../../stores/poll'
Expand Down Expand Up @@ -129,19 +128,19 @@ const subTexts = computed(() => {
})

const dateCreatedRelative = computed(() =>
moment.unix(pollStore.status.created).fromNow(),
pollStore.getExpirationDateTime.toRelative(),
)

const closeToClosing = computed(
() =>
!pollStore.isClosed
&& pollStore.configuration.expire
&& moment.unix(pollStore.configuration.expire).diff() < 86400000,
&& pollStore.getExpirationDateTime.diffNow().as('days') < 1,
)

const timeExpirationRelative = computed(() => {
if (pollStore.configuration.expire) {
return moment.unix(pollStore.configuration.expire).fromNow()
return pollStore.getExpirationDateTime.toRelative() as string
}
return t('polls', 'never')
})
Expand Down
9 changes: 4 additions & 5 deletions src/components/Poll/PollInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<script setup lang="ts">
import { computed } from 'vue'
import moment from '@nextcloud/moment'
import { t, n } from '@nextcloud/l10n'

import OwnerIcon from 'vue-material-design-icons/Crown.vue'
Expand Down Expand Up @@ -77,11 +76,11 @@ const accessCaption = computed(() =>
? t('polls', 'Private poll')
: t('polls', 'Openly accessible poll'),
)
const dateCreatedRelative = computed(() =>
moment.unix(pollStore.status.created).fromNow(),
const dateCreatedRelative = computed(
() => pollStore.getCreationDateTime.toRelative() as string,
)
const dateExpiryRelative = computed(() =>
moment.unix(pollStore.configuration.expire).fromNow(),
const dateExpiryRelative = computed(
() => pollStore.getCreationDateTime.toRelative() as string,
)
const currentTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
const countAllYesVotes = computed(() => votesStore.countAllVotesByAnswer('yes'))
Expand Down
48 changes: 26 additions & 22 deletions src/stores/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { defineStore } from 'pinia'
import DOMPurify from 'dompurify'
import { marked } from 'marked'
import { gfmHeadingId } from 'marked-gfm-heading-id'
import { DateTime } from 'luxon'

import { t } from '@nextcloud/l10n'
import moment from '@nextcloud/moment'
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'

Expand Down Expand Up @@ -171,7 +171,12 @@ export const usePollStore = defineStore('poll', {
},

isProposalOpen(): boolean {
return this.isProposalAllowed && !this.isProposalExpired
return (
(this.isProposalExpirySet
&& this.getProposalExpirationDateTime.diffNow().as('seconds')
> 0)
|| (!this.isProposalExpirySet && this.isProposalAllowed)
)
},

isProposalAllowed(state): boolean {
Expand All @@ -181,6 +186,14 @@ export const usePollStore = defineStore('poll', {
)
},

getExpirationDateTime(state): DateTime {
return DateTime.fromSeconds(state.configuration.expire)
},

getCreationDateTime(state): DateTime {
return DateTime.fromSeconds(state.status.created)
},

isConfirmationAllowed(state): boolean {
return state.permissions.confirmOptions || !this.isClosed
},
Expand All @@ -189,31 +202,32 @@ export const usePollStore = defineStore('poll', {
return !this.isClosed && state.permissions.edit
},

isProposalExpired(state): boolean {
isProposalExpired(): boolean {
return (
this.isProposalAllowed
&& state.configuration.proposalsExpire > 0
&& moment.unix(state.configuration.proposalsExpire).diff() < 0
this.isProposalExpirySet
&& this.getProposalExpirationDateTime.diffNow().as('seconds') < 0
)
},

getProposalExpirationDateTime(state): DateTime {
return DateTime.fromSeconds(state.configuration.proposalsExpire)
},

isProposalExpirySet(state): boolean {
return this.isProposalAllowed && state.configuration.proposalsExpire > 0
},

proposalsExpireRelative(state): string {
return moment.unix(state.configuration.proposalsExpire).fromNow()
},

proposalsExpire_d(state): Date {
return moment.unix(state.configuration.proposalsExpire)._d
return DateTime.fromSeconds(
state.configuration.proposalsExpire,
).toRelative()
},

isClosed(state): boolean {
return (
state.status.isExpired
|| (state.configuration.expire > 0
&& moment.unix(state.configuration.expire).diff() < 1000)
&& this.getExpirationDateTime.diffNow().as('seconds') < 0)
)
},

Expand All @@ -235,16 +249,6 @@ export const usePollStore = defineStore('poll', {
sessionStore.setViewMode(this.type, viewMode)
},

setProposalExpiration(payload: { expire: number }): void {
this.configuration.proposalsExpire = moment(payload.expire).unix()
this.write()
},

setExpiration(payload: { expire: number }): void {
this.configuration.proposalsExpire = moment(payload.expire).unix()
this.write()
},

async load(isChanging: boolean = false): Promise<void> {
const sessionStore = useSessionStore()

Expand Down