-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(files_reminders): upgrade to 28 APIs
Signed-off-by: John Molakvoæ <[email protected]>
- Loading branch information
Showing
14 changed files
with
522 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
apps/files_reminders/src/actions/setReminderCustomAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
import { FileAction, Node } from '@nextcloud/files' | ||
import { translate as t } from '@nextcloud/l10n' | ||
import CalendarClockSvg from '@mdi/svg/svg/calendar-clock.svg?raw' | ||
|
||
import { SET_REMINDER_MENU_ID } from './setReminderMenuAction' | ||
import { pickCustomDate } from '../services/customPicker' | ||
|
||
export const action = new FileAction({ | ||
id: 'set-reminder-custom', | ||
displayName: () => t('files', 'Set custom reminder'), | ||
title: () => t('files_reminders', 'Set reminder at custom date & time'), | ||
iconSvgInline: () => CalendarClockSvg, | ||
|
||
enabled: () => true, | ||
parent: SET_REMINDER_MENU_ID, | ||
|
||
async exec(file: Node) { | ||
pickCustomDate(file) | ||
return null | ||
}, | ||
|
||
// After presets | ||
order: 22, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
import { FileAction } from '@nextcloud/files' | ||
import { translate as t } from '@nextcloud/l10n' | ||
import AlarmSvg from '@mdi/svg/svg/alarm.svg?raw' | ||
|
||
export const SET_REMINDER_MENU_ID = 'set-reminder-menu' | ||
|
||
export const action = new FileAction({ | ||
id: SET_REMINDER_MENU_ID, | ||
displayName: () => t('files', 'Set reminder'), | ||
iconSvgInline: () => AlarmSvg, | ||
|
||
enabled: () => true, | ||
|
||
async exec() { | ||
return null | ||
}, | ||
|
||
order: 20, | ||
}) |
38 changes: 38 additions & 0 deletions
38
apps/files_reminders/src/actions/setReminderSuggestionActions.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
// TODO: remove when/if the actions API supports a separator | ||
// This the last preset action, so we need to add a separator | ||
.files-list__row-action-set-reminder-3 { | ||
margin-bottom: 13px; | ||
|
||
&::after { | ||
content: ""; | ||
margin: 3px 10px 3px 15px; | ||
border-bottom: 1px solid var(--color-border-dark); | ||
cursor: default; | ||
display: flex; | ||
height: 0; | ||
position: absolute; | ||
left: 0; | ||
right: 0; | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
apps/files_reminders/src/actions/setReminderSuggestionActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
import type { Node } from '@nextcloud/files' | ||
|
||
import { FileAction } from '@nextcloud/files' | ||
import { showError, showSuccess } from '@nextcloud/dialogs' | ||
import { translate as t } from '@nextcloud/l10n' | ||
|
||
import { DateTimePreset, getDateString, getDateTime, getVerboseDateString } from '../shared/utils' | ||
import { logger } from '../shared/logger' | ||
import { SET_REMINDER_MENU_ID } from './setReminderMenuAction' | ||
import { setReminder } from '../services/reminderService' | ||
import './setReminderSuggestionActions.scss' | ||
|
||
interface ReminderOption { | ||
dateTimePreset: DateTimePreset | ||
label: string | ||
ariaLabel: string | ||
dateString?: string | ||
action?: () => Promise<void> | ||
} | ||
|
||
const laterToday: ReminderOption = { | ||
dateTimePreset: DateTimePreset.LaterToday, | ||
label: t('files_reminders', 'Later today'), | ||
ariaLabel: t('files_reminders', 'Set reminder for later today'), | ||
} | ||
|
||
const tomorrow: ReminderOption = { | ||
dateTimePreset: DateTimePreset.Tomorrow, | ||
label: t('files_reminders', 'Tomorrow'), | ||
ariaLabel: t('files_reminders', 'Set reminder for tomorrow'), | ||
} | ||
|
||
const thisWeekend: ReminderOption = { | ||
dateTimePreset: DateTimePreset.ThisWeekend, | ||
label: t('files_reminders', 'This weekend'), | ||
ariaLabel: t('files_reminders', 'Set reminder for this weekend'), | ||
} | ||
|
||
const nextWeek: ReminderOption = { | ||
dateTimePreset: DateTimePreset.NextWeek, | ||
label: t('files_reminders', 'Next week'), | ||
ariaLabel: t('files_reminders', 'Set reminder for next week'), | ||
} | ||
|
||
// Generate the default preset actions | ||
export const actions = [laterToday, tomorrow, thisWeekend, nextWeek].map((option): FileAction|null => { | ||
const dateTime = getDateTime(option.dateTimePreset) | ||
if (!dateTime) { | ||
return null | ||
} | ||
|
||
return new FileAction({ | ||
id: `set-reminder-${option.dateTimePreset}`, | ||
displayName: () => `${option.label} - ${getDateString(dateTime)}`, | ||
title: () => `${option.ariaLabel} – ${getVerboseDateString(dateTime)}`, | ||
|
||
// Empty svg to hide the icon | ||
iconSvgInline: () => '<svg></svg>', | ||
|
||
enabled: () => true, | ||
parent: SET_REMINDER_MENU_ID, | ||
|
||
async exec(node: Node) { | ||
// Can't really happen, but just in case™ | ||
if (!node.fileid) { | ||
logger.error('Failed to set reminder, missing file id') | ||
showError(t('files_reminders', 'Failed to set reminder')) | ||
return null | ||
} | ||
|
||
// Set the reminder | ||
try { | ||
await setReminder(node.fileid, dateTime) | ||
showSuccess(t('files_reminders', 'Reminder set for "{fileName}"', { fileName: node.basename })) | ||
} catch (error) { | ||
logger.error('Failed to set reminder', { error }) | ||
showError(t('files_reminders', 'Failed to set reminder')) | ||
} | ||
// Silent success as we display our own notification | ||
return null | ||
}, | ||
|
||
order: 21, | ||
}) | ||
}).filter(Boolean) as FileAction[] |
Oops, something went wrong.