mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
Merge pull request #16504 from nextcloud/fix/noid/extract-date-options
This commit is contained in:
commit
bf8ab8ab4f
2 changed files with 82 additions and 61 deletions
|
|
@ -260,7 +260,7 @@
|
|||
<NcActionSeparator />
|
||||
|
||||
<NcActionButton
|
||||
v-for="option in reminderOptions"
|
||||
v-for="option in getCustomDateOptions()"
|
||||
:key="option.key"
|
||||
:aria-label="option.ariaLabel"
|
||||
close-after-click
|
||||
|
|
@ -385,6 +385,7 @@ import { useIntegrationsStore } from '../../../../../stores/integrations.js'
|
|||
import { useReactionsStore } from '../../../../../stores/reactions.js'
|
||||
import { generatePublicShareDownloadUrl, generateUserFileUrl } from '../../../../../utils/davUtils.ts'
|
||||
import { convertToUnix, formatDateTime } from '../../../../../utils/formattedTime.ts'
|
||||
import { getCustomDateOptions } from '../../../../../utils/getCustomDateOptions.ts'
|
||||
import { copyConversationLinkToClipboard } from '../../../../../utils/handleUrl.ts'
|
||||
import { parseMentions } from '../../../../../utils/textParse.ts'
|
||||
|
||||
|
|
@ -521,6 +522,7 @@ export default {
|
|||
actorStore,
|
||||
chatExtrasStore,
|
||||
threadId,
|
||||
getCustomDateOptions,
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -606,66 +608,6 @@ export default {
|
|||
},
|
||||
},
|
||||
|
||||
reminderOptions() {
|
||||
const currentDate = new Date()
|
||||
const currentDayOfWeek = currentDate.getDay()
|
||||
|
||||
const nextDay = new Date()
|
||||
nextDay.setDate(currentDate.getDate() + 1)
|
||||
|
||||
const nextSaturday = new Date()
|
||||
nextSaturday.setDate(currentDate.getDate() + ((6 + 7 - currentDayOfWeek) % 7 || 7))
|
||||
|
||||
const nextMonday = new Date()
|
||||
nextMonday.setDate(currentDate.getDate() + ((1 + 7 - currentDayOfWeek) % 7 || 7))
|
||||
|
||||
// Same day 18:00 PM (hidden if after 17:00 PM now)
|
||||
const laterTodayTime = (currentDate.getHours() < 17)
|
||||
? new Date().setHours(18, 0, 0, 0)
|
||||
: null
|
||||
|
||||
// Tomorrow 08:00 AM
|
||||
const tomorrowTime = nextDay.setHours(8, 0, 0, 0)
|
||||
|
||||
// Saturday 08:00 AM (hidden if Friday, Saturday or Sunday now)
|
||||
const thisWeekendTime = (![0, 5, 6].includes(currentDayOfWeek))
|
||||
? nextSaturday.setHours(8, 0, 0, 0)
|
||||
: null
|
||||
|
||||
// Next Monday 08:00 AM (hidden if Sunday now)
|
||||
// TODO: use getFirstDay from nextcloud/l10n
|
||||
const nextWeekTime = (currentDayOfWeek !== 0)
|
||||
? nextMonday.setHours(8, 0, 0, 0)
|
||||
: null
|
||||
|
||||
return [
|
||||
{
|
||||
key: 'laterToday',
|
||||
timestamp: laterTodayTime,
|
||||
label: t('spreed', 'Later today – {timeLocale}', { timeLocale: formatDateTime(laterTodayTime, 'shortTime') }),
|
||||
ariaLabel: t('spreed', 'Set reminder for later today'),
|
||||
},
|
||||
{
|
||||
key: 'tomorrow',
|
||||
timestamp: tomorrowTime,
|
||||
label: t('spreed', 'Tomorrow – {timeLocale}', { timeLocale: formatDateTime(tomorrowTime, 'shortWeekdayWithTime') }),
|
||||
ariaLabel: t('spreed', 'Set reminder for tomorrow'),
|
||||
},
|
||||
{
|
||||
key: 'thisWeekend',
|
||||
timestamp: thisWeekendTime,
|
||||
label: t('spreed', 'This weekend – {timeLocale}', { timeLocale: formatDateTime(thisWeekendTime, 'shortWeekdayWithTime') }),
|
||||
ariaLabel: t('spreed', 'Set reminder for this weekend'),
|
||||
},
|
||||
{
|
||||
key: 'nextWeek',
|
||||
timestamp: nextWeekTime,
|
||||
label: t('spreed', 'Next week – {timeLocale}', { timeLocale: formatDateTime(nextWeekTime, 'shortWeekdayWithTime') }),
|
||||
ariaLabel: t('spreed', 'Set reminder for next week'),
|
||||
},
|
||||
].filter((option) => option.timestamp !== null)
|
||||
},
|
||||
|
||||
clearReminderLabel() {
|
||||
if (!this.currentReminder) {
|
||||
return ''
|
||||
|
|
|
|||
79
src/utils/getCustomDateOptions.ts
Normal file
79
src/utils/getCustomDateOptions.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { t } from '@nextcloud/l10n'
|
||||
import { formatDateTime } from './formattedTime.ts'
|
||||
|
||||
type CustomDateOption = {
|
||||
key: string
|
||||
timestamp: number
|
||||
label: string
|
||||
ariaLabel: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of custom date options for reminders / schedulers
|
||||
*/
|
||||
export function getCustomDateOptions() {
|
||||
const currentDate = new Date()
|
||||
const currentDayOfWeek = currentDate.getDay()
|
||||
|
||||
const options: CustomDateOption[] = []
|
||||
|
||||
// Same day 18:00 PM (hidden if after 17:00 PM now)
|
||||
if (currentDate.getHours() < 17) {
|
||||
const laterTodayTime = new Date().setHours(18, 0, 0, 0)
|
||||
|
||||
options.push({
|
||||
key: 'laterToday',
|
||||
timestamp: laterTodayTime,
|
||||
label: t('spreed', 'Later today – {timeLocale}', { timeLocale: formatDateTime(laterTodayTime, 'shortTime') }),
|
||||
ariaLabel: t('spreed', 'Set time for later today'),
|
||||
})
|
||||
}
|
||||
|
||||
// Tomorrow 08:00 AM
|
||||
const nextDay = new Date()
|
||||
nextDay.setDate(currentDate.getDate() + 1)
|
||||
const tomorrowTime = nextDay.setHours(8, 0, 0, 0)
|
||||
|
||||
options.push({
|
||||
key: 'tomorrow',
|
||||
timestamp: tomorrowTime,
|
||||
label: t('spreed', 'Tomorrow – {timeLocale}', { timeLocale: formatDateTime(tomorrowTime, 'shortWeekdayWithTime') }),
|
||||
ariaLabel: t('spreed', 'Set time for tomorrow'),
|
||||
})
|
||||
|
||||
// Saturday 08:00 AM (hidden if Friday, Saturday or Sunday now)
|
||||
if (![0, 5, 6].includes(currentDayOfWeek)) {
|
||||
const nextSaturday = new Date()
|
||||
nextSaturday.setDate(currentDate.getDate() + ((6 + 7 - currentDayOfWeek) % 7 || 7))
|
||||
const thisWeekendTime = nextSaturday.setHours(8, 0, 0, 0)
|
||||
|
||||
options.push({
|
||||
key: 'thisWeekend',
|
||||
timestamp: thisWeekendTime,
|
||||
label: t('spreed', 'This weekend – {timeLocale}', { timeLocale: formatDateTime(thisWeekendTime, 'shortWeekdayWithTime') }),
|
||||
ariaLabel: t('spreed', 'Set time for this weekend'),
|
||||
})
|
||||
}
|
||||
|
||||
// Next Monday 08:00 AM (hidden if Sunday now)
|
||||
// TODO: use getFirstDay from nextcloud/l10n
|
||||
if (currentDayOfWeek !== 0) {
|
||||
const nextMonday = new Date()
|
||||
nextMonday.setDate(currentDate.getDate() + ((1 + 7 - currentDayOfWeek) % 7 || 7))
|
||||
const nextWeekTime = nextMonday.setHours(8, 0, 0, 0)
|
||||
|
||||
options.push({
|
||||
key: 'nextWeek',
|
||||
timestamp: nextWeekTime,
|
||||
label: t('spreed', 'Next week – {timeLocale}', { timeLocale: formatDateTime(nextWeekTime, 'shortWeekdayWithTime') }),
|
||||
ariaLabel: t('spreed', 'Set time for next week'),
|
||||
})
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue