From 29351b07af05efc496214fcaf8312afc376be9cb Mon Sep 17 00:00:00 2001
From: Furkan Sahin <furkan-dev@proton.me>
Date: Thu, 29 Apr 2021 15:47:20 -0500
Subject: Make all components use typescript

---
 src/components/ActionBar.vue | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

(limited to 'src/components/ActionBar.vue')

diff --git a/src/components/ActionBar.vue b/src/components/ActionBar.vue
index e50c791..bfe3cdb 100644
--- a/src/components/ActionBar.vue
+++ b/src/components/ActionBar.vue
@@ -11,40 +11,33 @@
   </div>
 </template>
 
-<script>
+<script lang="ts">
+import { defineComponent } from 'vue';
 import FileUpload from '@/components/FileUpload.vue';
 import { parseLabFile, parsePtSchedule } from '@/features/parser';
 import UIButton from '@/components/UIButton.vue';
+import PeerTeacher from '@/models/PeerTeacher';
 
-export default {
+export default defineComponent({
   name: 'ActionBar',
   components: {
     FileUpload,
     UIButton,
   },
   methods: {
-    handleLabChange(files) {
-      parseLabFile(files[0])
-        .then((data) => {
-          this.$store.commit('importLabs', data);
-        })
-        .catch((error) => {
-          console.error(error);
-        });
+    async handleLabChange(files: File[]) {
+      const data = await parseLabFile(files[0]);
+      this.$store.commit('importLabs', data);
     },
-    handlePtChange(files) {
-      const result = [];
-      const promises = [];
+    async handlePtChange(files: File[]) {
+      const promises: Promise<PeerTeacher>[] = [];
 
       files.forEach((file) => {
-        const p = parsePtSchedule(file).then((data) => result.push(data));
-        promises.push(p);
+        promises.push(parsePtSchedule(file));
       });
 
-      Promise.all(promises)
-        .then(() => {
-          this.$store.commit('addPeerTeachers', result);
-        });
+      const result = await Promise.all(promises);
+      this.$store.commit('addPeerTeachers', result);
     },
     save() {
       const database = {
@@ -64,7 +57,7 @@ export default {
       const url = window.URL.createObjectURL(blob);
       anchor.href = url;
       anchor.download = 'pt-db.json';
-      anchor.style = 'display: none';
+      anchor.style.display = 'none';
 
       document.body.appendChild(anchor);
       anchor.click();
@@ -72,7 +65,7 @@ export default {
       window.URL.revokeObjectURL(url);
     },
   },
-};
+});
 </script>
 
 <style>
-- 
cgit v1.2.3

