mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
refactor(files_reminders): adjust for files library interfaces and remove sideeffects
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
7a60e43dd5
commit
f01d974b5c
9 changed files with 72 additions and 76 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
|
@ -9,7 +9,7 @@ import { action as clearAction } from './files_actions/clearReminderAction.ts'
|
|||
import { action as statusAction } from './files_actions/reminderStatusAction.ts'
|
||||
import { action as customAction } from './files_actions/setReminderCustomAction.ts'
|
||||
import { action as menuAction } from './files_actions/setReminderMenuAction.ts'
|
||||
import { actions as suggestionActions } from './files_actions/setReminderSuggestionActions.ts'
|
||||
import { getSetReminderSuggestionActions } from './files_actions/setReminderSuggestionActions.ts'
|
||||
|
||||
registerDavProperty('nc:reminder-due-date', { nc: 'http://nextcloud.org/ns' })
|
||||
|
||||
|
|
@ -17,4 +17,5 @@ registerFileAction(statusAction)
|
|||
registerFileAction(clearAction)
|
||||
registerFileAction(menuAction)
|
||||
registerFileAction(customAction)
|
||||
suggestionActions.forEach((action) => registerFileAction(action))
|
||||
getSetReminderSuggestionActions()
|
||||
.forEach(registerFileAction)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
/**
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { View } from '@nextcloud/files'
|
||||
import type { IView } from '@nextcloud/files'
|
||||
|
||||
import { Folder } from '@nextcloud/files'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { action } from './clearReminderAction.ts'
|
||||
|
||||
const view = {} as unknown as View
|
||||
const view = {} as unknown as IView
|
||||
|
||||
const root = new Folder({
|
||||
owner: 'user',
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
/**
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { IFileAction } from '@nextcloud/files'
|
||||
|
||||
import AlarmOffSvg from '@mdi/svg/svg/alarm-off.svg?raw'
|
||||
import { emit } from '@nextcloud/event-bus'
|
||||
import { FileAction } from '@nextcloud/files'
|
||||
import { t } from '@nextcloud/l10n'
|
||||
import { clearReminder } from '../services/reminderService.ts'
|
||||
import { getVerboseDateString } from '../shared/utils.ts'
|
||||
|
||||
export const action = new FileAction({
|
||||
export const action: IFileAction = {
|
||||
id: 'clear-reminder',
|
||||
|
||||
displayName: () => t('files_reminders', 'Clear reminder'),
|
||||
|
|
@ -48,4 +50,4 @@ export const action = new FileAction({
|
|||
},
|
||||
|
||||
order: 19,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
/**
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { View } from '@nextcloud/files'
|
||||
import type { IView } from '@nextcloud/files'
|
||||
|
||||
import { Folder } from '@nextcloud/files'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { action } from './reminderStatusAction.ts'
|
||||
|
||||
const view = {} as unknown as View
|
||||
const view = {} as unknown as IView
|
||||
|
||||
const root = new Folder({
|
||||
owner: 'user',
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
/**
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { IFileAction } from '@nextcloud/files'
|
||||
|
||||
import AlarmSvg from '@mdi/svg/svg/alarm.svg?raw'
|
||||
import { FileAction } from '@nextcloud/files'
|
||||
import { t } from '@nextcloud/l10n'
|
||||
import { pickCustomDate } from '../services/customPicker.ts'
|
||||
import { getVerboseDateString } from '../shared/utils.ts'
|
||||
|
||||
export const action = new FileAction({
|
||||
export const action: IFileAction = {
|
||||
id: 'reminder-status',
|
||||
|
||||
inline: () => true,
|
||||
|
|
@ -41,4 +43,4 @@ export const action = new FileAction({
|
|||
},
|
||||
|
||||
order: -15,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
/**
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { IFileAction } from '@nextcloud/files'
|
||||
|
||||
import CalendarClockSvg from '@mdi/svg/svg/calendar-clock.svg?raw'
|
||||
import { FileAction } from '@nextcloud/files'
|
||||
import { t } from '@nextcloud/l10n'
|
||||
import { pickCustomDate } from '../services/customPicker.ts'
|
||||
import { SET_REMINDER_MENU_ID } from './setReminderMenuAction.ts'
|
||||
|
||||
export const action = new FileAction({
|
||||
export const action: IFileAction = {
|
||||
id: 'set-reminder-custom',
|
||||
displayName: () => t('files_reminders', 'Custom reminder'),
|
||||
title: () => t('files_reminders', 'Reminder at custom date & time'),
|
||||
|
|
@ -37,4 +39,4 @@ export const action = new FileAction({
|
|||
|
||||
// After presets
|
||||
order: 22,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
/**
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { IFileAction } from '@nextcloud/files'
|
||||
|
||||
import AlarmSvg from '@mdi/svg/svg/alarm.svg?raw'
|
||||
import { FileAction } from '@nextcloud/files'
|
||||
import { translate as t } from '@nextcloud/l10n'
|
||||
|
||||
export const SET_REMINDER_MENU_ID = 'set-reminder-menu'
|
||||
|
||||
export const action = new FileAction({
|
||||
export const action: IFileAction = {
|
||||
id: SET_REMINDER_MENU_ID,
|
||||
displayName: () => t('files_reminders', 'Set reminder'),
|
||||
iconSvgInline: () => AlarmSvg,
|
||||
|
|
@ -31,4 +33,4 @@ export const action = new FileAction({
|
|||
},
|
||||
|
||||
order: 20,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
/**
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { IFileAction } from '@nextcloud/files'
|
||||
|
||||
import { showError, showSuccess } from '@nextcloud/dialogs'
|
||||
import { emit } from '@nextcloud/event-bus'
|
||||
import { FileAction } from '@nextcloud/files'
|
||||
import { t } from '@nextcloud/l10n'
|
||||
import { setReminder } from '../services/reminderService.ts'
|
||||
import { logger } from '../shared/logger.ts'
|
||||
|
|
@ -54,14 +56,45 @@ const nextWeek: ReminderOption = {
|
|||
verboseDateString: '',
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all set reminder suggestion actions from presets
|
||||
*/
|
||||
export function getSetReminderSuggestionActions() {
|
||||
[laterToday, tomorrow, thisWeekend, nextWeek].forEach((option) => {
|
||||
// Generate the initial date string
|
||||
const dateTime = getDateTime(option.dateTimePreset)
|
||||
if (!dateTime) {
|
||||
return
|
||||
}
|
||||
option.dateString = getDateString(dateTime)
|
||||
option.verboseDateString = getVerboseDateString(dateTime)
|
||||
|
||||
// Update the date string every 30 minutes
|
||||
setInterval(() => {
|
||||
const dateTime = getDateTime(option.dateTimePreset)
|
||||
if (!dateTime) {
|
||||
return
|
||||
}
|
||||
|
||||
// update the submenu remind options strings
|
||||
option.dateString = getDateString(dateTime)
|
||||
option.verboseDateString = getVerboseDateString(dateTime)
|
||||
}, 1000 * 30 * 60)
|
||||
})
|
||||
|
||||
// Generate the default preset actions
|
||||
return [laterToday, tomorrow, thisWeekend, nextWeek]
|
||||
.map(generateFileAction)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a file action for the given option
|
||||
*
|
||||
* @param option The option to generate the action for
|
||||
* @return The file action or null if the option should not be shown
|
||||
*/
|
||||
function generateFileAction(option: ReminderOption): FileAction | null {
|
||||
return new FileAction({
|
||||
function generateFileAction(option: ReminderOption): IFileAction {
|
||||
return {
|
||||
id: `set-reminder-${option.dateTimePreset}`,
|
||||
displayName: () => `${option.label} – ${option.dateString}`,
|
||||
title: () => `${option.ariaLabel} – ${option.verboseDateString}`,
|
||||
|
|
@ -109,31 +142,5 @@ function generateFileAction(option: ReminderOption): FileAction | null {
|
|||
},
|
||||
|
||||
order: 21,
|
||||
})
|
||||
}
|
||||
|
||||
[laterToday, tomorrow, thisWeekend, nextWeek].forEach((option) => {
|
||||
// Generate the initial date string
|
||||
const dateTime = getDateTime(option.dateTimePreset)
|
||||
if (!dateTime) {
|
||||
return
|
||||
}
|
||||
option.dateString = getDateString(dateTime)
|
||||
option.verboseDateString = getVerboseDateString(dateTime)
|
||||
|
||||
// Update the date string every 30 minutes
|
||||
setInterval(() => {
|
||||
const dateTime = getDateTime(option.dateTimePreset)
|
||||
if (!dateTime) {
|
||||
return
|
||||
}
|
||||
|
||||
// update the submenu remind options strings
|
||||
option.dateString = getDateString(dateTime)
|
||||
option.verboseDateString = getVerboseDateString(dateTime)
|
||||
}, 1000 * 30 * 60)
|
||||
})
|
||||
|
||||
// Generate the default preset actions
|
||||
export const actions = [laterToday, tomorrow, thisWeekend, nextWeek]
|
||||
.map(generateFileAction) as FileAction[]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { registerFileAction } from '@nextcloud/files'
|
||||
import { registerDavProperty } from '@nextcloud/files/dav'
|
||||
import { action as clearAction } from './files_actions/clearReminderAction.ts'
|
||||
import { action as statusAction } from './files_actions/reminderStatusAction.ts'
|
||||
import { action as customAction } from './files_actions/setReminderCustomAction.ts'
|
||||
import { action as menuAction } from './files_actions/setReminderMenuAction.ts'
|
||||
import { actions as suggestionActions } from './files_actions/setReminderSuggestionActions.ts'
|
||||
|
||||
registerDavProperty('nc:reminder-due-date', { nc: 'http://nextcloud.org/ns' })
|
||||
|
||||
registerFileAction(statusAction)
|
||||
registerFileAction(clearAction)
|
||||
registerFileAction(menuAction)
|
||||
registerFileAction(customAction)
|
||||
suggestionActions.forEach((action) => registerFileAction(action))
|
||||
Loading…
Reference in a new issue