11<script setup lang="ts">
2+ import { useKeyboardShurtcuts } from " ~/lib/settings" ;
3+ import { onDocumentEvent , shouldHandleKeypress } from " ~/lib/util" ;
4+
25defineProps <{
36 name: string ;
47}>();
5- defineEmits <{
8+ const $emit = defineEmits <{
69 (event : " reject" , reason : string ): void ;
710 (event : " cancel" ): void ;
811}>();
@@ -33,6 +36,28 @@ function handleCheck(reason: string, value: boolean) {
3336 selectedReasons .value .delete (reason );
3437 }
3538}
39+
40+ onDocumentEvent (" keydown" , (e : KeyboardEvent ) => {
41+ if (! shouldHandleKeypress (e )) return ;
42+ if (e .key === " Enter" ) {
43+ (document .querySelector (" #reject" ) as HTMLButtonElement )?.click ();
44+ return ;
45+ }
46+ if (e .key === " Escape" ) {
47+ $emit (" cancel" );
48+ return ;
49+ }
50+ if (! e .key .match (/ ^ [0-9 ] $ / )) return ;
51+ const index = parseInt (e .key ) - 1 ;
52+ const reason = reasons [index ];
53+ console .log (reason );
54+ if (index === reasons .length ) {
55+ showOther .value = true ;
56+ (document .querySelector (" #other" ) as HTMLInputElement )?.focus ();
57+ } else if (reason ) {
58+ handleCheck (reason , ! selectedReasons .value .has (reason ));
59+ }
60+ });
3661 </script >
3762
3863<template >
@@ -52,14 +77,16 @@ function handleCheck(reason: string, value: boolean) {
5277 <input
5378 :id =" `reason-${idx}`"
5479 type =" checkbox"
80+ :checked =" selectedReasons.has(reason)"
5581 @input ="
5682 handleCheck(reason, ($event.target as HTMLInputElement).checked)
5783 "
5884 />
5985 <label
60- class =" w-full h-full cursor-pointer py-1.5"
86+ class =" w-full h-full cursor-pointer py-1.5 flex items-center gap-1 "
6187 :for =" `reason-${idx}`"
6288 >
89+ <kbd v-if =" useKeyboardShurtcuts" class =" text-xs" >{{ idx + 1 }}</kbd >
6390 {{ reason }}
6491 </label >
6592 </li >
@@ -69,15 +96,19 @@ function handleCheck(reason: string, value: boolean) {
6996 <input id =" reason-other" v-model =" showOther" type =" checkbox" />
7097 <label
7198 id =" other-label"
72- class =" w-full h-full cursor-pointer py-1.5"
99+ class =" w-full h-full cursor-pointer py-1.5 flex items-center gap-1 "
73100 for =" reason-other"
74101 >
102+ <kbd v-if =" useKeyboardShurtcuts" class =" text-xs" >{{
103+ reasons.length + 1
104+ }}</kbd >
75105 Other
76106 </label >
77107 </li >
78108 <li v-if =" showOther" >
79109 <input
80110 v-model =" other"
111+ id =" other"
81112 type =" text"
82113 aria-labelledby =" other-label"
83114 placeholder =" Type a reason..."
@@ -95,6 +126,7 @@ function handleCheck(reason: string, value: boolean) {
95126 </button >
96127
97128 <button
129+ id =" reject"
98130 class =" py-1 px-2 mr-1 bg-red-500 dark:bg-red-600 hover:bg-red-600 dark:hover:bg-red-700 disabled:bg-red-400 disabled:dark:bg-red-500 rounded-lg disabled:cursor-not-allowed"
99131 :disabled =" !selectedReasonsText"
100132 @click =" $emit('reject', selectedReasonsText)"
0 commit comments