-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathChatDrawerItem.vue
More file actions
137 lines (123 loc) · 2.97 KB
/
Copy pathChatDrawerItem.vue
File metadata and controls
137 lines (123 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<template>
<v-list-item
density="comfortable"
v-if="!isEditMode"
:key="`chat-${props.chat.index}`"
:active="props.currentChatIndex === props.chat.index"
:title="props.chat.title"
:value="props.chat.index"
class="pa-3 pr-0"
:style="{ cursor: isCursorWait ? 'wait' : 'pointer' }"
@click="onSelectChat"
> <template v-slot:prepend
> <v-icon color="primary" class="mr-4"> mdi-message-outline </v-icon>
</template
> <template #append v-if="props.currentChatIndex === props.chat.index"
> <v-btn
flat
size="x-small"
icon="mdi-pencil-outline"
@click="editChat"
style="background-color: transparent"
></v-btn
> <v-btn
flat
size="x-small"
icon="mdi-delete-outline"
@click="confirmHideChat"
@shortkey="confirmHideChat"
v-shortkey="SHORTCUT_DELETE_CHAT.key"
:id="SHORTCUT_DELETE_CHAT.elementId"
style="margin: 0; background-color: transparent"
></v-btn
> </template
> </v-list-item
> <v-text-field
autofocus
:key="`chat-${index}`"
v-if="isEditMode"
v-model="chatTitleEditModel"
color="primary"
density="compact"
@keydown="onPressEnter"
@focus="$event.target.select()"
style="padding: 6px"
class="pl-3 pr-0"
hide-details
> <template v-slot:prepend
> <v-icon color="primary"> mdi-message-outline </v-icon> </template
> <template v-slot:append
> <v-btn flat size="x-small" icon="mdi-check" @click="confirmEdit"></v-btn
> <v-btn
flat
size="x-small"
icon="mdi-close"
@click="isEditMode = false"
></v-btn
> </template
> </v-text-field
>
</template>
<script setup>
import { ref } from "vue";
import { SHORTCUT_DELETE_CHAT } from "@/components/ShortcutGuide/shortcut.const";
const emit = defineEmits([
"hideChat",
"editChatTitle",
"selectChat",
"focusTextarea",
]);
const props = defineProps({
chat: {
type: Object,
required: true,
},
currentChatIndex: {
type: String,
required: true,
},
});
const isEditMode = ref(false);
const isCursorWait = ref(false);
const chatTitleEditModel = ref("");
async function onSelectChat() {
emit("selectChat", props.chat.index);
}
async function confirmHideChat() {
emit("hideChat");
}
function editChat() {
isEditMode.value = true;
chatTitleEditModel.value = props.chat.title;
}
function confirmEdit() {
emit("editChatTitle", {
title: chatTitleEditModel.value,
isEditedByUser: true,
});
isEditMode.value = false;
}
function onPressEnter(event) {
if (event.keyCode == 13) {
confirmEdit();
}
}
</script>
<style scoped>
:deep() .v-input__append {
margin-left: 0 !important;
}
:deep() .v-input__prepend {
margin-right: 0.25rem !important;
}
:deep() .v-field__input {
padding-left: 12px;
padding-right: 0;
}
:deep() i.v-icon {
color: rgb(var(--v-theme-primary));
}
:deep() div.v-list-item__prepend {
display: block;
}
</style>