refactor(frontend): popupMenuの項目作成時に三項演算子をなるべく使わないように (#14554)
* refactor(frontend): popupMenuの項目作成時に三項演算子をなるべく使わないように * type import * fix * lint
This commit is contained in:
		| @@ -20,7 +20,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| <script lang="ts" setup> | ||||
| import { onMounted, onBeforeUnmount, shallowRef, ref } from 'vue'; | ||||
| import MkMenu from './MkMenu.vue'; | ||||
| import { MenuItem } from '@/types/menu.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
| import contains from '@/scripts/contains.js'; | ||||
| import { defaultStore } from '@/store.js'; | ||||
| import * as os from '@/os.js'; | ||||
|   | ||||
| @@ -42,7 +42,7 @@ import { i18n } from '@/i18n.js'; | ||||
| import { defaultStore } from '@/store.js'; | ||||
| import { claimAchievement } from '@/scripts/achievements.js'; | ||||
| import { copyToClipboard } from '@/scripts/copy-to-clipboard.js'; | ||||
| import { MenuItem } from '@/types/menu.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
|  | ||||
| const props = withDefaults(defineProps<{ | ||||
| 	folder: Misskey.entities.DriveFolder; | ||||
|   | ||||
| @@ -620,7 +620,9 @@ function fetchMoreFiles() { | ||||
| } | ||||
|  | ||||
| function getMenu() { | ||||
| 	const menu: MenuItem[] = [{ | ||||
| 	const menu: MenuItem[] = []; | ||||
|  | ||||
| 	menu.push({ | ||||
| 		type: 'switch', | ||||
| 		text: i18n.ts.keepOriginalUploading, | ||||
| 		ref: keepOriginal, | ||||
| @@ -638,19 +640,25 @@ function getMenu() { | ||||
| 	}, { type: 'divider' }, { | ||||
| 		text: folder.value ? folder.value.name : i18n.ts.drive, | ||||
| 		type: 'label', | ||||
| 	}, folder.value ? { | ||||
| 		text: i18n.ts.renameFolder, | ||||
| 		icon: 'ti ti-forms', | ||||
| 		action: () => { if (folder.value) renameFolder(folder.value); }, | ||||
| 	} : undefined, folder.value ? { | ||||
| 		text: i18n.ts.deleteFolder, | ||||
| 		icon: 'ti ti-trash', | ||||
| 		action: () => { deleteFolder(folder.value as Misskey.entities.DriveFolder); }, | ||||
| 	} : undefined, { | ||||
| 	}); | ||||
|  | ||||
| 	if (folder.value) { | ||||
| 		menu.push({ | ||||
| 			text: i18n.ts.renameFolder, | ||||
| 			icon: 'ti ti-forms', | ||||
| 			action: () => { if (folder.value) renameFolder(folder.value); }, | ||||
| 		}, { | ||||
| 			text: i18n.ts.deleteFolder, | ||||
| 			icon: 'ti ti-trash', | ||||
| 			action: () => { deleteFolder(folder.value as Misskey.entities.DriveFolder); }, | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	menu.push({ | ||||
| 		text: i18n.ts.createFolder, | ||||
| 		icon: 'ti ti-folder-plus', | ||||
| 		action: () => { createFolder(); }, | ||||
| 	}]; | ||||
| 	}); | ||||
|  | ||||
| 	return menu; | ||||
| } | ||||
|   | ||||
| @@ -172,9 +172,7 @@ async function show() { | ||||
| const menuShowing = ref(false); | ||||
|  | ||||
| function showMenu(ev: MouseEvent) { | ||||
| 	let menu: MenuItem[] = []; | ||||
|  | ||||
| 	menu = [ | ||||
| 	const menu: MenuItem[] = [ | ||||
| 		// TODO: 再生キューに追加 | ||||
| 		{ | ||||
| 			type: 'switch', | ||||
| @@ -222,7 +220,7 @@ function showMenu(ev: MouseEvent) { | ||||
| 		menu.push({ | ||||
| 			type: 'divider', | ||||
| 		}, { | ||||
| 			type: 'link' as const, | ||||
| 			type: 'link', | ||||
| 			text: i18n.ts._fileViewer.title, | ||||
| 			icon: 'ti ti-info-circle', | ||||
| 			to: `/my/drive/file/${props.audio.id}`, | ||||
|   | ||||
| @@ -60,6 +60,7 @@ import { defaultStore } from '@/store.js'; | ||||
| import { i18n } from '@/i18n.js'; | ||||
| import * as os from '@/os.js'; | ||||
| import { $i, iAmModerator } from '@/account.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
|  | ||||
| const props = withDefaults(defineProps<{ | ||||
| 	image: Misskey.entities.DriveFile; | ||||
| @@ -111,27 +112,39 @@ watch(() => props.image, () => { | ||||
| }); | ||||
|  | ||||
| function showMenu(ev: MouseEvent) { | ||||
| 	os.popupMenu([{ | ||||
| 	const menuItems: MenuItem[] = []; | ||||
|  | ||||
| 	menuItems.push({ | ||||
| 		text: i18n.ts.hide, | ||||
| 		icon: 'ti ti-eye-off', | ||||
| 		action: () => { | ||||
| 			hide.value = true; | ||||
| 		}, | ||||
| 	}, ...(iAmModerator ? [{ | ||||
| 		text: i18n.ts.markAsSensitive, | ||||
| 		icon: 'ti ti-eye-exclamation', | ||||
| 		danger: true, | ||||
| 		action: () => { | ||||
| 			os.apiWithDialog('drive/files/update', { fileId: props.image.id, isSensitive: true }); | ||||
| 		}, | ||||
| 	}] : []), ...($i?.id === props.image.userId ? [{ | ||||
| 		type: 'divider' as const, | ||||
| 	}, { | ||||
| 		type: 'link' as const, | ||||
| 		text: i18n.ts._fileViewer.title, | ||||
| 		icon: 'ti ti-info-circle', | ||||
| 		to: `/my/drive/file/${props.image.id}`, | ||||
| 	}] : [])], ev.currentTarget ?? ev.target); | ||||
| 	}); | ||||
|  | ||||
| 	if (iAmModerator) { | ||||
| 		menuItems.push({ | ||||
| 			text: i18n.ts.markAsSensitive, | ||||
| 			icon: 'ti ti-eye-exclamation', | ||||
| 			danger: true, | ||||
| 			action: () => { | ||||
| 				os.apiWithDialog('drive/files/update', { fileId: props.image.id, isSensitive: true }); | ||||
| 			}, | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	if ($i?.id === props.image.userId) { | ||||
| 		menuItems.push({ | ||||
| 			type: 'divider', | ||||
| 		}, { | ||||
| 			type: 'link', | ||||
| 			text: i18n.ts._fileViewer.title, | ||||
| 			icon: 'ti ti-info-circle', | ||||
| 			to: `/my/drive/file/${props.image.id}`, | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	os.popupMenu(menuItems, ev.currentTarget ?? ev.target); | ||||
| } | ||||
|  | ||||
| </script> | ||||
|   | ||||
| @@ -192,9 +192,7 @@ async function show() { | ||||
| const menuShowing = ref(false); | ||||
|  | ||||
| function showMenu(ev: MouseEvent) { | ||||
| 	let menu: MenuItem[] = []; | ||||
|  | ||||
| 	menu = [ | ||||
| 	const menu: MenuItem[] = [ | ||||
| 		// TODO: 再生キューに追加 | ||||
| 		{ | ||||
| 			type: 'switch', | ||||
| @@ -247,7 +245,7 @@ function showMenu(ev: MouseEvent) { | ||||
| 		menu.push({ | ||||
| 			type: 'divider', | ||||
| 		}, { | ||||
| 			type: 'link' as const, | ||||
| 			type: 'link', | ||||
| 			text: i18n.ts._fileViewer.title, | ||||
| 			icon: 'ti ti-info-circle', | ||||
| 			to: `/my/drive/file/${props.video.id}`, | ||||
|   | ||||
| @@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| <script lang="ts" setup> | ||||
| import { nextTick, onMounted, onUnmounted, provide, shallowRef, watch } from 'vue'; | ||||
| import MkMenu from './MkMenu.vue'; | ||||
| import { MenuItem } from '@/types/menu.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
|  | ||||
| const props = defineProps<{ | ||||
| 	items: MenuItem[]; | ||||
|   | ||||
| @@ -193,7 +193,7 @@ import { deepClone } from '@/scripts/clone.js'; | ||||
| import { useTooltip } from '@/scripts/use-tooltip.js'; | ||||
| import { claimAchievement } from '@/scripts/achievements.js'; | ||||
| import { getNoteSummary } from '@/scripts/get-note-summary.js'; | ||||
| import { MenuItem } from '@/types/menu.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
| import MkRippleEffect from '@/components/MkRippleEffect.vue'; | ||||
| import { showMovedDialog } from '@/scripts/show-moved-dialog.js'; | ||||
| import { shouldCollapsed } from '@@/js/collapsed.js'; | ||||
|   | ||||
| @@ -13,7 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| import { ref, shallowRef } from 'vue'; | ||||
| import MkModal from './MkModal.vue'; | ||||
| import MkMenu from './MkMenu.vue'; | ||||
| import { MenuItem } from '@/types/menu.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
|  | ||||
| defineProps<{ | ||||
| 	items: MenuItem[]; | ||||
|   | ||||
| @@ -26,6 +26,7 @@ import MkDriveFileThumbnail from '@/components/MkDriveFileThumbnail.vue'; | ||||
| import * as os from '@/os.js'; | ||||
| import { misskeyApi } from '@/scripts/misskey-api.js'; | ||||
| import { i18n } from '@/i18n.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
|  | ||||
| const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default)); | ||||
|  | ||||
| @@ -136,7 +137,10 @@ function showFileMenu(file: Misskey.entities.DriveFile, ev: MouseEvent): void { | ||||
| 	if (menuShowing) return; | ||||
|  | ||||
| 	const isImage = file.type.startsWith('image/'); | ||||
| 	os.popupMenu([{ | ||||
|  | ||||
| 	const menuItems: MenuItem[] = []; | ||||
|  | ||||
| 	menuItems.push({ | ||||
| 		text: i18n.ts.renameFile, | ||||
| 		icon: 'ti ti-forms', | ||||
| 		action: () => { rename(file); }, | ||||
| @@ -148,11 +152,17 @@ function showFileMenu(file: Misskey.entities.DriveFile, ev: MouseEvent): void { | ||||
| 		text: i18n.ts.describeFile, | ||||
| 		icon: 'ti ti-text-caption', | ||||
| 		action: () => { describe(file); }, | ||||
| 	}, ...isImage ? [{ | ||||
| 		text: i18n.ts.cropImage, | ||||
| 		icon: 'ti ti-crop', | ||||
| 		action: () : void => { crop(file); }, | ||||
| 	}] : [], { | ||||
| 	}); | ||||
|  | ||||
| 	if (isImage) { | ||||
| 		menuItems.push({ | ||||
| 			text: i18n.ts.cropImage, | ||||
| 			icon: 'ti ti-crop', | ||||
| 			action: () : void => { crop(file); }, | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	menuItems.push({ | ||||
| 		type: 'divider', | ||||
| 	}, { | ||||
| 		text: i18n.ts.attachCancel, | ||||
| @@ -163,7 +173,9 @@ function showFileMenu(file: Misskey.entities.DriveFile, ev: MouseEvent): void { | ||||
| 		icon: 'ti ti-trash', | ||||
| 		danger: true, | ||||
| 		action: () => { detachAndDeleteMedia(file); }, | ||||
| 	}], ev.currentTarget ?? ev.target).then(() => menuShowing = false); | ||||
| 	}); | ||||
|  | ||||
| 	os.popupMenu(menuItems, ev.currentTarget ?? ev.target).then(() => menuShowing = false); | ||||
| 	menuShowing = true; | ||||
| } | ||||
| </script> | ||||
|   | ||||
| @@ -46,7 +46,7 @@ import MkButton from '@/components/MkButton.vue'; | ||||
| import * as os from '@/os.js'; | ||||
| import { useInterval } from '@@/js/use-interval.js'; | ||||
| import { i18n } from '@/i18n.js'; | ||||
| import { MenuItem } from '@/types/menu.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
|  | ||||
| const props = defineProps<{ | ||||
| 	modelValue: string | null; | ||||
|   | ||||
| @@ -56,7 +56,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| import { onBeforeUnmount, onMounted, provide, shallowRef, ref } from 'vue'; | ||||
| import contains from '@/scripts/contains.js'; | ||||
| import * as os from '@/os.js'; | ||||
| import { MenuItem } from '@/types/menu.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
| import { i18n } from '@/i18n.js'; | ||||
| import { defaultStore } from '@/store.js'; | ||||
|  | ||||
|   | ||||
| @@ -35,6 +35,7 @@ import { copyToClipboard } from '@/scripts/copy-to-clipboard.js'; | ||||
| import * as sound from '@/scripts/sound.js'; | ||||
| import { i18n } from '@/i18n.js'; | ||||
| import MkCustomEmojiDetailedDialog from '@/components/MkCustomEmojiDetailedDialog.vue'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
|  | ||||
| const props = defineProps<{ | ||||
| 	name: string; | ||||
| @@ -85,7 +86,9 @@ const errored = ref(url.value == null); | ||||
|  | ||||
| function onClick(ev: MouseEvent) { | ||||
| 	if (props.menu) { | ||||
| 		os.popupMenu([{ | ||||
| 		const menuItems: MenuItem[] = []; | ||||
|  | ||||
| 		menuItems.push({ | ||||
| 			type: 'label', | ||||
| 			text: `:${props.name}:`, | ||||
| 		}, { | ||||
| @@ -95,14 +98,20 @@ function onClick(ev: MouseEvent) { | ||||
| 				copyToClipboard(`:${props.name}:`); | ||||
| 				os.success(); | ||||
| 			}, | ||||
| 		}, ...(props.menuReaction && react ? [{ | ||||
| 			text: i18n.ts.doReaction, | ||||
| 			icon: 'ti ti-plus', | ||||
| 			action: () => { | ||||
| 				react(`:${props.name}:`); | ||||
| 				sound.playMisskeySfx('reaction'); | ||||
| 			}, | ||||
| 		}] : []), { | ||||
| 		}); | ||||
|  | ||||
| 		if (props.menuReaction && react) { | ||||
| 			menuItems.push({ | ||||
| 				text: i18n.ts.doReaction, | ||||
| 				icon: 'ti ti-plus', | ||||
| 				action: () => { | ||||
| 					react(`:${props.name}:`); | ||||
| 					sound.playMisskeySfx('reaction'); | ||||
| 				}, | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		menuItems.push({ | ||||
| 			text: i18n.ts.info, | ||||
| 			icon: 'ti ti-info-circle', | ||||
| 			action: async () => { | ||||
| @@ -114,7 +123,9 @@ function onClick(ev: MouseEvent) { | ||||
| 					closed: () => dispose(), | ||||
| 				}); | ||||
| 			}, | ||||
| 		}], ev.currentTarget ?? ev.target); | ||||
| 		}); | ||||
|  | ||||
| 		os.popupMenu(menuItems, ev.currentTarget ?? ev.target); | ||||
| 	} | ||||
| } | ||||
| </script> | ||||
|   | ||||
| @@ -17,6 +17,7 @@ import * as os from '@/os.js'; | ||||
| import { copyToClipboard } from '@/scripts/copy-to-clipboard.js'; | ||||
| import * as sound from '@/scripts/sound.js'; | ||||
| import { i18n } from '@/i18n.js'; | ||||
| import type { MenuItem } from '@/types/menu.js'; | ||||
|  | ||||
| const props = defineProps<{ | ||||
| 	emoji: string; | ||||
| @@ -39,7 +40,9 @@ function computeTitle(event: PointerEvent): void { | ||||
|  | ||||
| function onClick(ev: MouseEvent) { | ||||
| 	if (props.menu) { | ||||
| 		os.popupMenu([{ | ||||
| 		const menuItems: MenuItem[] = []; | ||||
|  | ||||
| 		menuItems.push({ | ||||
| 			type: 'label', | ||||
| 			text: props.emoji, | ||||
| 		}, { | ||||
| @@ -49,14 +52,20 @@ function onClick(ev: MouseEvent) { | ||||
| 				copyToClipboard(props.emoji); | ||||
| 				os.success(); | ||||
| 			}, | ||||
| 		}, ...(props.menuReaction && react ? [{ | ||||
| 			text: i18n.ts.doReaction, | ||||
| 			icon: 'ti ti-plus', | ||||
| 			action: () => { | ||||
| 				react(props.emoji); | ||||
| 				sound.playMisskeySfx('reaction'); | ||||
| 			}, | ||||
| 		}] : [])], ev.currentTarget ?? ev.target); | ||||
| 		}); | ||||
|  | ||||
| 		if (props.menuReaction && react) { | ||||
| 			menuItems.push({ | ||||
| 				text: i18n.ts.doReaction, | ||||
| 				icon: 'ti ti-plus', | ||||
| 				action: () => { | ||||
| 					react(props.emoji); | ||||
| 					sound.playMisskeySfx('reaction'); | ||||
| 				}, | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		os.popupMenu(menuItems, ev.currentTarget ?? ev.target); | ||||
| 	} | ||||
| } | ||||
| </script> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 かっこかり
					かっこかり