aboutsummaryrefslogtreecommitdiff
path: root/web.js
diff options
context:
space:
mode:
Diffstat (limited to 'web.js')
-rw-r--r--web.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/web.js b/web.js
new file mode 100644
index 0000000..61b82d5
--- /dev/null
+++ b/web.js
@@ -0,0 +1,42 @@
+const web = new Vue({
+ el: '#web',
+ data: {
+ word: '',
+ timer: undefined,
+ definitions: null,
+ is_word: null
+ },
+ methods: {
+ searchWord: function() {
+ if(!this.word) return;
+ if(this.timer) {
+ clearTimeout(this.timer);
+ this.timer = undefined;
+ }
+ console.log(this.word);
+ fetch(`/def?w=${this.word}`)
+ .then((response) => {
+ this.is_word = response.ok;
+
+ if( response.ok ) {
+ response.arrayBuffer().then(res => {
+ this.definitions = msgpack.decode(new Uint8Array(res));
+ console.log(this.definitions);
+ });
+ }
+ })
+ }
+ },
+ watch: {
+ word: function(w) {
+ if( w === '' ) {
+ this.is_word = null;
+ }
+ if(this.timer) {
+ clearTimeout(this.timer);
+ this.timer = undefined;
+ }
+ this.timer = setTimeout(this.searchWord, 800);
+ }
+ }
+});