refactor(frontend): popupMenuの項目作成時に三項演算子をなるべく使わないように (#14554)

* refactor(frontend): popupMenuの項目作成時に三項演算子をなるべく使わないように

* type import

* fix

* lint
This commit is contained in:
かっこかり
2024-09-23 21:50:30 +09:00
committed by GitHub
parent e673c143a9
commit 0c6d1ec524
36 changed files with 851 additions and 614 deletions

View File

@@ -46,7 +46,7 @@ import { onBeforeUnmount, onMounted, provide, watch, shallowRef, ref, computed }
import { updateColumn, swapLeftColumn, swapRightColumn, swapUpColumn, swapDownColumn, stackLeftColumn, popRightColumn, removeColumn, swapColumn, Column } from './deck-store.js';
import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { MenuItem } from '@/types/menu.js';
import type { MenuItem } from '@/types/menu.js';
provide('shouldHeaderThin', true);
provide('shouldOmitHeaderTitle', true);
@@ -104,7 +104,27 @@ function toggleActive() {
}
function getMenu() {
let items: MenuItem[] = [{
const menuItems: MenuItem[] = [];
if (props.menu) {
menuItems.push(...props.menu, {
type: 'divider',
});
}
if (props.refresher) {
menuItems.push({
icon: 'ti ti-refresh',
text: i18n.ts.reload,
action: () => {
if (props.refresher) {
props.refresher();
}
},
});
}
menuItems.push({
icon: 'ti ti-settings',
text: i18n.ts._deck.configureColumn,
action: async () => {
@@ -129,74 +149,73 @@ function getMenu() {
if (canceled) return;
updateColumn(props.column.id, result);
},
});
const moveToMenuItems: MenuItem[] = [];
moveToMenuItems.push({
icon: 'ti ti-arrow-left',
text: i18n.ts._deck.swapLeft,
action: () => {
swapLeftColumn(props.column.id);
},
}, {
type: 'parent',
text: i18n.ts.move + '...',
icon: 'ti ti-arrows-move',
children: [{
icon: 'ti ti-arrow-left',
text: i18n.ts._deck.swapLeft,
action: () => {
swapLeftColumn(props.column.id);
},
}, {
icon: 'ti ti-arrow-right',
text: i18n.ts._deck.swapRight,
action: () => {
swapRightColumn(props.column.id);
},
}, props.isStacked ? {
icon: 'ti ti-arrow-right',
text: i18n.ts._deck.swapRight,
action: () => {
swapRightColumn(props.column.id);
},
});
if (props.isStacked) {
moveToMenuItems.push({
icon: 'ti ti-arrow-up',
text: i18n.ts._deck.swapUp,
action: () => {
swapUpColumn(props.column.id);
},
} : undefined, props.isStacked ? {
}, {
icon: 'ti ti-arrow-down',
text: i18n.ts._deck.swapDown,
action: () => {
swapDownColumn(props.column.id);
},
} : undefined],
});
}
menuItems.push({
type: 'parent',
text: i18n.ts.move + '...',
icon: 'ti ti-arrows-move',
children: moveToMenuItems,
}, {
icon: 'ti ti-stack-2',
text: i18n.ts._deck.stackLeft,
action: () => {
stackLeftColumn(props.column.id);
},
}, props.isStacked ? {
icon: 'ti ti-window-maximize',
text: i18n.ts._deck.popRight,
action: () => {
popRightColumn(props.column.id);
},
} : undefined, { type: 'divider' }, {
});
if (props.isStacked) {
menuItems.push({
icon: 'ti ti-window-maximize',
text: i18n.ts._deck.popRight,
action: () => {
popRightColumn(props.column.id);
},
});
}
menuItems.push({ type: 'divider' }, {
icon: 'ti ti-trash',
text: i18n.ts.remove,
danger: true,
action: () => {
removeColumn(props.column.id);
},
}];
});
if (props.menu) {
items.unshift({ type: 'divider' });
items = props.menu.concat(items);
}
if (props.refresher) {
items = [{
icon: 'ti ti-refresh',
text: i18n.ts.reload,
action: () => {
if (props.refresher) {
props.refresher();
}
},
}, ...items];
}
return items;
return menuItems;
}
function showSettingsMenu(ev: MouseEvent) {