From 4c3d094a458e2229072cbf785115e2f7280fcae9 Mon Sep 17 00:00:00 2001
From: syuilo <Syuilotan@yahoo.co.jp>
Date: Mon, 5 Sep 2022 18:34:59 +0900
Subject: refactor(client): use setup syntax

---
 .../src/components/MkTokenGenerateWindow.vue       | 127 ++++++++-------------
 1 file changed, 50 insertions(+), 77 deletions(-)

(limited to 'packages/client/src/components/MkTokenGenerateWindow.vue')

diff --git a/packages/client/src/components/MkTokenGenerateWindow.vue b/packages/client/src/components/MkTokenGenerateWindow.vue
index bf5775d4d8..789218a8cd 100644
--- a/packages/client/src/components/MkTokenGenerateWindow.vue
+++ b/packages/client/src/components/MkTokenGenerateWindow.vue
@@ -1,11 +1,12 @@
 <template>
-<XModalWindow ref="dialog"
+<XModalWindow
+	ref="dialog"
 	:width="400"
 	:height="450"
 	:with-ok-button="true"
 	:ok-button-disabled="false"
 	:can-close="false"
-	@close="$refs.dialog.close()"
+	@close="dialog.close()"
 	@closed="$emit('closed')"
 	@ok="ok()"
 >
@@ -27,91 +28,63 @@
 </XModalWindow>
 </template>
 
-<script lang="ts">
-import { defineComponent } from 'vue';
-import { permissions } from 'misskey-js';
-import XModalWindow from '@/components/ui/modal-window.vue';
+<script lang="ts" setup>
+import { } from 'vue';
+import { permissions as kinds } from 'misskey-js';
 import MkInput from './form/input.vue';
-import MkTextarea from './form/textarea.vue';
 import MkSwitch from './form/switch.vue';
 import MkButton from './ui/button.vue';
 import MkInfo from './ui/info.vue';
+import XModalWindow from '@/components/ui/modal-window.vue';
 
-export default defineComponent({
-	components: {
-		XModalWindow,
-		MkInput,
-		MkTextarea,
-		MkSwitch,
-		MkButton,
-		MkInfo,
-	},
-
-	props: {
-		title: {
-			type: String,
-			required: false,
-			default: null
-		},
-		information: {
-			type: String,
-			required: false,
-			default: null
-		},
-		initialName: {
-			type: String,
-			required: false,
-			default: null
-		},
-		initialPermissions: {
-			type: Array,
-			required: false,
-			default: null
-		}
-	},
+const props = withDefaults(defineProps<{
+	title?: string | null;
+	information?: string | null;
+	initialName?: string | null;
+	initialPermissions?: string[] | null;
+}>(), {
+	title: null,
+	information: null,
+	initialName: null,
+	initialPermissions: null,
+});
 
-	emits: ['done', 'closed'],
+const emit = defineEmits<{
+	(ev: 'closed'): void;
+	(ev: 'done', result: { name: string | null, permissions: string[] }): void;
+}>();
 
-	data() {
-		return {
-			name: this.initialName,
-			permissions: {},
-			kinds: permissions
-		};
-	},
+const dialog = $ref<InstanceType<typeof XModalWindow>>();
+let name = $ref(props.initialName);
+let permissions = $ref({});
 
-	created() {
-		if (this.initialPermissions) {
-			for (const kind of this.initialPermissions) {
-				this.permissions[kind] = true;
-			}
-		} else {
-			for (const kind of this.kinds) {
-				this.permissions[kind] = false;
-			}
-		}
-	},
+if (props.initialPermissions) {
+	for (const kind of props.initialPermissions) {
+		permissions[kind] = true;
+	}
+} else {
+	for (const kind of kinds) {
+		permissions[kind] = false;
+	}
+}
 
-	methods: {
-		ok() {
-			this.$emit('done', {
-				name: this.name,
-				permissions: Object.keys(this.permissions).filter(p => this.permissions[p])
-			});
-			this.$refs.dialog.close();
-		},
+function ok(): void {
+	emit('done', {
+		name: name,
+		permissions: Object.keys(permissions).filter(p => permissions[p]),
+	});
+	dialog.close();
+}
 
-		disableAll() {
-			for (const p in this.permissions) {
-				this.permissions[p] = false;
-			}
-		},
+function disableAll(): void {
+	for (const p in permissions) {
+		permissions[p] = false;
+	}
+}
 
-		enableAll() {
-			for (const p in this.permissions) {
-				this.permissions[p] = true;
-			}
-		}
+function enableAll(): void {
+	for (const p in permissions) {
+		permissions[p] = true;
 	}
-});
+}
 </script>
-- 
cgit v1.2.3-freya

