Draft game upload logic (unwritten yet for Analysis mode)
[vchess.git] / client / src / components / UploadGame.vue
CommitLineData
5f918a27
BA
1<template lang="pug">
2div
3 input#upload(type="file" @change="upload")
4 button#uploadBtn(
5 @click="uploadTrigger()"
6 aria-label="store.state.tr['Upload a game']"
7 )
8 img.inline(src="/images/icons/upload.svg")
9</template>
10
11<script>
12export default {
13 name: "my-upload-game",
14 methods: {
15 uploadTrigger: function() {
16 document.getElementById("upload").click();
17 },
18 upload: function(e) {
19 const file = (e.target.files || e.dataTransfer.files)[0];
20 var reader = new FileReader();
21 reader.onloadend = ev => {
22 this.parseAndEmit(ev.currentTarget.result);
23 };
24 reader.readAsText(file);
25 },
26 parseAndEmit: function(pgn) {
27 // TODO: header gives game Info, third secton the moves
28 let game = {};
29 // mark sur ID pour dire import : I_
30 this.$emit("game-uploaded", game);
31 }
32 }
33};
34</script>
35
36<style lang="sass" scoped>
37input#upload
38 display: none
39
40img.inline
41 height: 22px
42 @media screen and (max-width: 767px)
43 height: 18px
44</style>