feat(task): save currently opened task with control/meta + s
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2023-10-11 17:44:17 +02:00
parent 40538df392
commit f0b340a9c7
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 27 additions and 4 deletions

View File

@ -5,13 +5,12 @@ import {onBeforeUnmount, onMounted} from 'vue'
import {eventToHotkeyString} from '@github/hotkey' import {eventToHotkeyString} from '@github/hotkey'
const baseStore = useBaseStore() const baseStore = useBaseStore()
const GLOBAL_HOTKEY = 'Control+k'
// See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660 // See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660
function openQuickActionsViaHotkey(event) { function openQuickActionsViaHotkey(event) {
const hotkeyString = eventToHotkeyString(event) const hotkeyString = eventToHotkeyString(event)
if (!hotkeyString) return if (!hotkeyString) return
if (hotkeyString !== GLOBAL_HOTKEY) return if (hotkeyString !== 'Control+k' && hotkeyString !== 'Meta+k') return
event.preventDefault() event.preventDefault()
openQuickActions() openQuickActions()

View File

@ -152,6 +152,10 @@ export const KEYBOARD_SHORTCUTS : ShortcutGroup[] = [
title: 'keyboardShortcuts.task.favorite', title: 'keyboardShortcuts.task.favorite',
keys: ['s'], keys: ['s'],
}, },
{
title: 'keyboardShortcuts.task.save',
keys: [ctrl, 's'],
},
], ],
}, },
] ]

View File

@ -883,7 +883,8 @@
"description": "Toggle editing of the task description", "description": "Toggle editing of the task description",
"delete": "Delete this task", "delete": "Delete this task",
"priority": "Change the priority of this task", "priority": "Change the priority of this task",
"favorite": "Mark this task as favorite / unfavorite" "favorite": "Mark this task as favorite / unfavorite",
"save": "Save the current task"
}, },
"project": { "project": {
"title": "Project Views", "title": "Project Views",

View File

@ -458,11 +458,12 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {ref, reactive, toRef, shallowReactive, computed, watch, nextTick} from 'vue' import {ref, reactive, toRef, shallowReactive, computed, watch, nextTick, onMounted, onBeforeUnmount} from 'vue'
import {useRouter, type RouteLocation} from 'vue-router' import {useRouter, type RouteLocation} from 'vue-router'
import {useI18n} from 'vue-i18n' import {useI18n} from 'vue-i18n'
import {unrefElement} from '@vueuse/core' import {unrefElement} from '@vueuse/core'
import {klona} from 'klona/lite' import {klona} from 'klona/lite'
import {eventToHotkeyString} from '@github/hotkey'
import TaskService from '@/services/task' import TaskService from '@/services/task'
import TaskModel, {TASK_DEFAULT_COLOR} from '@/models/task' import TaskModel, {TASK_DEFAULT_COLOR} from '@/models/task'
@ -533,6 +534,24 @@ const kanbanStore = useKanbanStore()
const task = ref<ITask>(new TaskModel()) const task = ref<ITask>(new TaskModel())
useTitle(toRef(task.value, 'title')) useTitle(toRef(task.value, 'title'))
// See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660
function saveTaskViaHotkey(event) {
const hotkeyString = eventToHotkeyString(event)
if (!hotkeyString) return
if (hotkeyString !== 'Control+s' && hotkeyString !== 'Meta+s') return
event.preventDefault()
saveTask()
}
onMounted(() => {
document.addEventListener('keydown', saveTaskViaHotkey)
})
onBeforeUnmount(() => {
document.removeEventListener('keydown', saveTaskViaHotkey)
})
// We doubled the task color property here because verte does not have a real change property, leading // We doubled the task color property here because verte does not have a real change property, leading
// to the color property change being triggered when the # is removed from it, leading to an update, // to the color property change being triggered when the # is removed from it, leading to an update,
// which leads in turn to a change... This creates an infinite loop in which the task is updated, changed, // which leads in turn to a change... This creates an infinite loop in which the task is updated, changed,