Skip to content

Commit 8f34380

Browse files
committed
rename some functions/variables and replace dropdown with button if not needed
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
1 parent 3669ca7 commit 8f34380

File tree

1 file changed

+59
-40
lines changed

1 file changed

+59
-40
lines changed

src/components/TaskTypeSelect.vue

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@
55
<template>
66
<div ref="taskTypeSelect"
77
class="task-type-select">
8-
<NcActions v-for="variants in buttonTypesByInlineStatus.inline"
9-
:key="variants.id"
10-
:force-menu="true"
11-
:menu-name="variants.text"
12-
:container="$refs.taskTypeSelect"
13-
:primary="selectedCategory(variants)"
14-
@click="onMenuCategorySelected(variants.id, variants.tasks)">
15-
<NcActionButton v-for="t in variants.tasks"
16-
:key="t.id"
17-
:disabled="selectedTask(t)"
18-
:title="t.description"
19-
:close-after-click="true"
20-
@click="onTaskSelected(t)">
8+
<template v-for="variants in buttonTypesByInlineStatus.inline">
9+
<NcActions v-if="hasSubMenu(variants)"
10+
:key="variants.id"
11+
:force-menu="true"
12+
:menu-name="variants.text"
13+
:container="$refs.taskTypeSelect"
14+
:primary="isCategorySelected(variants)"
15+
@click="onMenuCategorySelected(variants)">
16+
<NcActionButton v-for="t in variants.tasks"
17+
:key="t.id"
18+
:disabled="selectedTask(t)"
19+
:title="t.description"
20+
:close-after-click="true"
21+
@click="onTaskSelected(t)">
22+
<template #icon>
23+
<div style="width: 16px" />
24+
</template>
25+
{{ t.name }}
26+
</NcActionButton>
2127
<template #icon>
22-
<div style="width: 16px" />
28+
<component :is="variants.icon" />
2329
</template>
24-
{{ t.name }}
25-
</NcActionButton>
26-
<template #icon>
27-
<component :is="variants.icon" />
28-
</template>
29-
</NcActions>
30+
</NcActions>
31+
<NcButton v-else
32+
:key="variants.id + '-button'"
33+
:variant="isCategorySelected(variants) ? 'primary' : 'secondary'"
34+
:title="variants.text"
35+
@click="onMenuCategorySelected(variants)">
36+
<template #icon>
37+
<component :is="variants.icon" />
38+
</template>
39+
{{ variants.text }}
40+
</NcButton>
41+
</template>
3042
<NcActions
3143
:force-menu="true"
3244
:container="$refs.taskTypeSelect"
@@ -36,7 +48,7 @@
3648
:key="variant.id"
3749
:is-menu="variant.tasks.length > 1 || variant.id === 'other'"
3850
:title="variant.text"
39-
@click="onMenuCategorySelected(variant.id, variant.tasks)">
51+
@click="onMenuCategorySelected(variant)">
4052
<template #icon>
4153
<component :is="variant.icon" />
4254
</template>
@@ -62,6 +74,7 @@
6274

6375
<script>
6476
import NcActions from '@nextcloud/vue/components/NcActions'
77+
import NcButton from '@nextcloud/vue/components/NcButton'
6578
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
6679
import MessageOutlineIcon from 'vue-material-design-icons/MessageOutline.vue'
6780
import DotsHorizontalIcon from 'vue-material-design-icons/DotsHorizontal.vue'
@@ -79,6 +92,7 @@ export default {
7992
NcActions,
8093
NcActionButton,
8194
MessageOutlineIcon,
95+
NcButton,
8296
},
8397
8498
props: {
@@ -124,15 +138,15 @@ export default {
124138
taskTypes[type].push(task)
125139
}
126140
const result = []
127-
for (const part of Object.entries(taskTypes)) {
128-
if (part[0] === 'other') {
141+
for (const entry of Object.entries(taskTypes)) {
142+
if (entry[0] === 'other') {
129143
continue
130144
}
131145
result.push({
132-
id: part[0],
133-
text: this.getTextForCategory(part[0]),
134-
icon: this.getCategoryIcon(part[0]),
135-
tasks: part[1],
146+
id: entry[0],
147+
text: this.getTextForCategory(entry[0]),
148+
icon: this.getCategoryIcon(entry[0]),
149+
tasks: entry[1],
136150
})
137151
}
138152
// Ensure the "other" category is always last
@@ -150,20 +164,20 @@ export default {
150164
if (this.onlyInline) {
151165
return { inline: this.buttonTypes, overflow: [] }
152166
}
153-
const inline = this.buttonTypes.slice(0, this.inline)
154-
let overflow = this.buttonTypes.slice(this.inline)
167+
const inlineButtonTypes = this.buttonTypes.slice(0, this.inline)
168+
let overflowButtonTypes = this.buttonTypes.slice(this.inline)
155169
156170
// Ensure that the selection is never inline otherwise swap with the last uninlined category
157-
const selection = overflow.find(t => this.selectedCategory(t))
171+
const selection = overflowButtonTypes.find(t => this.isCategorySelected(t))
158172
if (selection) {
159-
const removal = inline.pop()
160-
inline.push(selection)
161-
overflow = overflow.filter(t => t.id !== selection.id)
173+
const removal = inlineButtonTypes.pop()
174+
inlineButtonTypes.push(selection)
175+
overflowButtonTypes = overflowButtonTypes.filter(t => t.id !== selection.id)
162176
if (removal) {
163-
overflow.unshift(removal)
177+
overflowButtonTypes.unshift(removal)
164178
}
165179
}
166-
return { overflow, inline }
180+
return { overflow: overflowButtonTypes, inline: inlineButtonTypes }
167181
},
168182
categorySubMenuTaskType() {
169183
return this.buttonTypesByInlineStatus.overflow.find(t => t.id === this.categorySubmenu)
@@ -177,17 +191,22 @@ export default {
177191
selectedTask(taskType) {
178192
return taskType.id === this.modelValue
179193
},
180-
selectedCategory(category) {
194+
isCategorySelected(category) {
181195
return category.id === this.getTaskCategory(this.modelValue || '')
182196
},
183197
onTaskSelected(taskType) {
184198
this.$emit('update:model-value', taskType.id)
185199
},
186-
onMenuCategorySelected(category, tasks) {
187-
if (tasks.length === 1 && category !== 'other') {
188-
this.onTaskSelected(tasks[0])
200+
hasSubMenu(taskType) {
201+
return taskType.tasks.length > 1 || taskType.id === 'other'
202+
},
203+
onMenuCategorySelected(taskType) {
204+
if (this.hasSubMenu(taskType)) {
205+
this.categorySubmenu = taskType.id
206+
} else {
207+
this.onTaskSelected(taskType.tasks[0])
208+
this.categorySubmenu = null
189209
}
190-
this.categorySubmenu = category
191210
},
192211
getTaskCategory(id) {
193212
if (id.startsWith('chatty')) {

0 commit comments

Comments
 (0)