From 87edeb41da2d1d1a4111864f92c1097e0b496dbf Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Sun, 18 Oct 2020 15:52:34 +0900
Subject: [PATCH] Fix poll editor bug

---
 src/client/components/poll-editor.vue | 43 +++++++++++++--------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/client/components/poll-editor.vue b/src/client/components/poll-editor.vue
index 5b615677d..8d7e16387 100644
--- a/src/client/components/poll-editor.vue
+++ b/src/client/components/poll-editor.vue
@@ -57,7 +57,6 @@ import MkInput from './ui/input.vue';
 import MkSelect from './ui/select.vue';
 import MkSwitch from './ui/switch.vue';
 import MkButton from './ui/button.vue';
-import * as os from '@/os';
 
 export default defineComponent({
 	components: {
@@ -78,8 +77,8 @@ export default defineComponent({
 
 	data() {
 		return {
-			choices: ['', ''],
-			multiple: false,
+			choices: this.poll.choices,
+			multiple: this.poll.multiple,
 			expiration: 'infinite',
 			atDate: formatDateTimeString(addTime(new Date(), 1, 'day'), 'yyyy-MM-dd'),
 			atTime: '00:00',
@@ -90,26 +89,6 @@ export default defineComponent({
 	},
 
 	watch: {
-		poll: {
-			handler(poll) {
-				if (poll == null) return;
-				if (poll.choices.length == 0) return;
-				this.choices = poll.choices;
-				if (poll.choices.length == 1) this.choices = this.choices.concat('');
-				this.multiple = poll.multiple;
-				if (poll.expiresAt) {
-					this.expiration = 'at';
-					this.atDate = this.atTime = poll.expiresAt;
-				} else if (typeof poll.expiredAfter === 'number') {
-					this.expiration = 'after';
-					this.after = poll.expiredAfter;
-				} else {
-					this.expiration = 'infinite';
-				}
-			},
-			deep: true,
-			immediate: true
-		},
 		choices: {
 			handler() {
 				this.$emit('updated', this.get());
@@ -136,6 +115,24 @@ export default defineComponent({
 				this.$emit('updated', this.get());
 			},
 		},
+		unit: {
+			handler() {
+				this.$emit('updated', this.get());
+			},
+		},
+	},
+
+	created() {
+		const poll = this.poll;
+		if (poll.expiresAt) {
+			this.expiration = 'at';
+			this.atDate = this.atTime = poll.expiresAt;
+		} else if (typeof poll.expiredAfter === 'number') {
+			this.expiration = 'after';
+			this.after = poll.expiredAfter / 1000;
+		} else {
+			this.expiration = 'infinite';
+		}
 	},
 
 	methods: {