0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-05-16 03:11:54 +00:00
nextcloud_server/apps/files_reminders/src/actions/clearReminderAction.ts
Andy Scherzinger 8d8891c5bc
chore: Add SPDX header
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
2024-05-30 15:49:33 +02:00

54 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import Vue from 'vue'
import { FileAction, type Node } from '@nextcloud/files'
import { emit } from '@nextcloud/event-bus'
import { translate as t } from '@nextcloud/l10n'
import AlarmOffSvg from '@mdi/svg/svg/alarm-off.svg?raw'
import { clearReminder } from '../services/reminderService.ts'
import { getVerboseDateString } from '../shared/utils.ts'
export const action = new FileAction({
id: 'clear-reminder',
displayName: () => t('files_reminders', 'Clear reminder'),
title: (nodes: Node[]) => {
const node = nodes.at(0)!
const dueDate = new Date(node.attributes['reminder-due-date'])
return `${t('files_reminders', 'Clear reminder')} ${getVerboseDateString(dueDate)}`
},
iconSvgInline: () => AlarmOffSvg,
enabled: (nodes: Node[]) => {
// Only allow on a single node
if (nodes.length !== 1) {
return false
}
const node = nodes.at(0)!
const dueDate = node.attributes['reminder-due-date']
return Boolean(dueDate)
},
async exec(node: Node) {
if (node.fileid) {
try {
await clearReminder(node.fileid)
Vue.set(node.attributes, 'reminder-due-date', '')
emit('files:node:updated', node)
return true
} catch (error) {
return false
}
}
return null
},
order: 19,
})