From c4a83a563d940d0e0128ad327f541df23239715d Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Mon, 21 Sep 2020 10:09:17 +0900
Subject: [PATCH] wip

---
 .../notification-setting-window.vue           |  7 ++++---
 src/client/components/signin-dialog.vue       |  7 ++++---
 src/client/components/signin.vue              | 20 ++++++++++---------
 src/client/components/signup-dialog.vue       |  7 ++++---
 src/client/components/signup.vue              | 16 +++++++--------
 5 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/src/client/components/notification-setting-window.vue b/src/client/components/notification-setting-window.vue
index 9c9a5c57db..0b8a8e6f96 100644
--- a/src/client/components/notification-setting-window.vue
+++ b/src/client/components/notification-setting-window.vue
@@ -1,5 +1,5 @@
 <template>
-<x-window ref="window" :width="400" :height="450" :no-padding="true" @closed="() => { $emit('closed'); destroyDom(); }" :with-ok-button="true" :ok-button-disabled="false" @ok="ok()">
+<x-window :width="400" :height="450" :no-padding="true" @close="$emit('done')" :with-ok-button="true" :ok-button-disabled="false" @ok="ok()">
 	<template #header>{{ $t('notificationSetting') }}</template>
 	<div class="vv94n3oa">
 		<div v-if="showGlobalToggle">
@@ -49,6 +49,8 @@ export default defineComponent({
 		}
 	},
 
+	emits: ['done'],
+
 	data() {
 		return {
 			typesMap: {} as Record<typeof notificationTypes[number], boolean>,
@@ -70,8 +72,7 @@ export default defineComponent({
 			const includingTypes = this.useGlobalSetting ? null : (Object.keys(this.typesMap) as typeof notificationTypes[number][])
 				.filter(type => this.typesMap[type]);
 
-			this.$emit('ok', { includingTypes });
-			this.$refs.window.close();
+			this.$emit('done', { includingTypes });
 		},
 
 		disableAll() {
diff --git a/src/client/components/signin-dialog.vue b/src/client/components/signin-dialog.vue
index 4bf4c64778..623d2c51d9 100644
--- a/src/client/components/signin-dialog.vue
+++ b/src/client/components/signin-dialog.vue
@@ -1,5 +1,5 @@
 <template>
-<x-window ref="window" @closed="() => { $emit('closed'); destroyDom(); }">
+<x-window @close="$emit('done')">
 	<template #header>{{ $t('login') }}</template>
 	<mk-signin :auto-set="autoSet" @login="onLogin"/>
 </x-window>
@@ -25,10 +25,11 @@ export default defineComponent({
 		}
 	},
 
+	emits: ['done'],
+
 	methods: {
 		onLogin(res) {
-			this.$emit('login', res);
-			this.$refs.window.close();
+			this.$emit('done', res);
 		}
 	}
 });
diff --git a/src/client/components/signin.vue b/src/client/components/signin.vue
index 7c16d0bef4..7b92c1e56e 100755
--- a/src/client/components/signin.vue
+++ b/src/client/components/signin.vue
@@ -72,6 +72,8 @@ export default defineComponent({
 		}
 	},
 
+	emits: ['login'],
+
 	data() {
 		return {
 			signing: false,
@@ -95,15 +97,6 @@ export default defineComponent({
 		},
 	},
 
-	created() {
-		if (this.autoSet) {
-			this.$once('login', res => {
-				localStorage.setItem('i', res.i);
-				location.reload();
-			});
-		}
-	},
-
 	methods: {
 		onUsernameChange() {
 			os.api('users/show', {
@@ -115,6 +108,13 @@ export default defineComponent({
 			});
 		},
 
+		onLogin(res) {
+			if (this.autoSet) {
+				localStorage.setItem('i', res.i);
+				location.reload();
+			}
+		},
+
 		queryKey() {
 			this.queryingKey = true;
 			return navigator.credentials.get({
@@ -144,6 +144,7 @@ export default defineComponent({
 				});
 			}).then(res => {
 				this.$emit('login', res);
+				this.onLogin(res);
 			}).catch(err => {
 				if (err === null) return;
 				os.dialog({
@@ -186,6 +187,7 @@ export default defineComponent({
 					token: this.user && this.user.twoFactorEnabled ? this.token : undefined
 				}).then(res => {
 					this.$emit('login', res);
+					this.onLogin(res);
 				}).catch(() => {
 					os.dialog({
 						type: 'error',
diff --git a/src/client/components/signup-dialog.vue b/src/client/components/signup-dialog.vue
index b549003893..8f9a3fa6dd 100644
--- a/src/client/components/signup-dialog.vue
+++ b/src/client/components/signup-dialog.vue
@@ -1,5 +1,5 @@
 <template>
-<x-window ref="window" :width="366" :height="506" @closed="() => { $emit('closed'); destroyDom(); }">
+<x-window :width="366" :height="506" @close="$emit('done')">
 	<template #header>{{ $t('signup') }}</template>
 	<x-signup :auto-set="autoSet" @signup="onSignup"/>
 </x-window>
@@ -25,10 +25,11 @@ export default defineComponent({
 		}
 	},
 
+	emits: ['done'],
+
 	methods: {
 		onSignup(res) {
-			this.$emit('signup', res);
-			this.$refs.window.close();
+			this.$emit('done', res);
 		}
 	}
 });
diff --git a/src/client/components/signup.vue b/src/client/components/signup.vue
index 7649862843..892312a13e 100644
--- a/src/client/components/signup.vue
+++ b/src/client/components/signup.vue
@@ -75,6 +75,8 @@ export default defineComponent({
 		}
 	},
 
+	emits: ['signup'],
+
 	data() {
 		return {
 			host: toUnicode(host),
@@ -115,15 +117,6 @@ export default defineComponent({
 		}
 	},
 
-	created() {
-		if (this.autoSet) {
-			this.$once('signup', res => {
-				localStorage.setItem('i', res.i);
-				location.reload();
-			});
-		}
-	},
-
 	methods: {
 		onChangeUsername() {
 			if (this.username == '') {
@@ -188,6 +181,11 @@ export default defineComponent({
 					password: this.password
 				}).then(res => {
 					this.$emit('signup', res);
+
+					if (this.autoSet) {
+						localStorage.setItem('i', res.i);
+						location.reload();
+					}
 				});
 			}).catch(() => {
 				this.submitting = false;