Now using proper emit/props for dataflow

This commit is contained in:
hak8or 2018-03-06 15:58:02 -05:00
parent a50956539a
commit dc1937d2f8
6 changed files with 57 additions and 62 deletions

View File

@ -20,20 +20,16 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from "vue"; import Vue, {PropOptions} from "vue";
import * as Dyt from "../dumbyt"; import * as Dyt from "../dumbyt";
// Vue class for keeping state of the videos. // Vue class for keeping state of the videos.
export default Vue.extend({ export default Vue.extend({
data() { props: {
return { Channels: {
Channels: Array<Dyt.Channel>() type: Array,
} } as PropOptions<Dyt.Channel[]>,
}, }
mounted(){
Dyt.search_channels("").then(v => this.Channels = v);
},
}); });
</script> </script>

View File

@ -7,7 +7,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from "vue"; import Vue, {PropOptions} from "vue";
import * as _ from "lodash"; import * as _ from "lodash";
import * as Dyt from "../dumbyt"; import * as Dyt from "../dumbyt";
@ -16,16 +16,17 @@ export default Vue.extend({
data() { data() {
return { return {
searchbox_str: "", searchbox_str: "",
Videos: Array<Dyt.Video>()
} }
}, },
// Manually attaching functions to watchers of data. // Manually attaching functions to watchers of data.
watch: { watch: {
// Searchbox updater. // Searchbox updater with debouncing.
searchbox_str (s: string) { searchbox_str (s: string) {
var v = _.debounce((s) => { var v = _.debounce((s) => {
Dyt.search_videos(s).then(e => this.Videos = e); Dyt.search_videos(s).then(videos => {
this.$emit('search_complete', videos)
});
}, 400) }, 400)
v(s); v(s);
} }
@ -36,7 +37,7 @@ export default Vue.extend({
<style scoped> <style scoped>
.searchbox { .searchbox {
font-size: 1.2em; font-size: 1.2em;
max-width: 70em; max-width: 40em;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
margin-top: 2em; margin-top: 2em;

View File

@ -1,6 +1,5 @@
<template> <template>
<div> <div>
<input id="searchbox0" class="searchbox" type="text" v-model="searchbox_str" placeholder="Search String goes here, for example: >5m,c++"/>
<div class="grid-x large-up-6"> <div class="grid-x large-up-6">
<div v-for="video in Videos" :key="video.ID" class="cell"> <div v-for="video in Videos" :key="video.ID" class="cell">
<div class="card ytcard"> <div class="card ytcard">
@ -16,32 +15,16 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from "vue"; import Vue, {PropOptions} from "vue";
import * as _ from "lodash";
import * as Dyt from "../dumbyt"; import * as Dyt from "../dumbyt";
// Vue class for keeping state of the videos. // Vue class for keeping state of the videos.
export default Vue.extend({ export default Vue.extend({
data() { props: {
return { Videos: {
searchbox_str: "", type: Array,
Videos: Array<Dyt.Video>() } as PropOptions<Dyt.Video[]>,
} }
},
// Manually attaching functions to watchers of data.
watch: {
// Searchbox updater.
searchbox_str (s: string) {
var v = _.debounce((s) => {
Dyt.search_videos(s).then(e => this.Videos = e);
})
v(s);
}
},
// Ugh, vue doesn't have async support for computed, wow ...
mounted() { Dyt.search_videos("").then(e => this.Videos = e ); }
}); });
</script> </script>
@ -66,12 +49,4 @@ export default Vue.extend({
font-size: 10px; font-size: 10px;
text-align: right; text-align: right;
} }
.searchbox {
font-size: 1.2em;
max-width: 70em;
margin-left: auto;
margin-right: auto;
margin-top: 2em;
}
</style> </style>

View File

@ -22,20 +22,16 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from "vue"; import Vue, {PropOptions} from "vue";
import * as Dyt from "../dumbyt"; import * as Dyt from "../dumbyt";
// Vue class for keeping state of the videos. // Vue class for keeping state of the videos.
export default Vue.extend({ export default Vue.extend({
data() { props: {
return { Videos: {
Videos: Array<Dyt.Video>() type: Array,
} } as PropOptions<Dyt.Video[]>,
}, }
mounted (){
Dyt.search_videos("").then(v => this.Videos = v);
},
}); });
</script> </script>

View File

@ -1,7 +1,7 @@
import Axios from "axios"; import Axios from "axios";
// Base URL for API queries. // Base URL for API queries.
const API_BASE_URL = "http://localhost:62214/api"; const API_BASE_URL = "/api";
// How many chars at most for the description. // How many chars at most for the description.
const max_description_length = 100; const max_description_length = 100;

View File

@ -5,16 +5,30 @@ import VTBL from "./components/Video_Table.vue";
import CTBL from "./components/Channel_Table.vue"; import CTBL from "./components/Channel_Table.vue";
import CADD from "./components/Channel_Add.vue"; import CADD from "./components/Channel_Add.vue";
import './index.css'; import './index.css';
import { Video, search_videos, Channel, search_channels } from "./dumbyt";
let MainApp = new Vue({ let MainApp = new Vue({
el: "#app", el: "#app",
template: ` template: `
<div> <div>
<VGC/> <SCH v-on:search_complete="search_completed"/>
<VGC v-bind:Videos="Videos"/>
</div> </div>
`, `,
components: { components: {
SCH,
VGC VGC
},
data() {
return {
Videos: Array<Video>()
}
},
methods: {
// Callback for when the search component got results back.
search_completed(videos : Array<Video>) : void {
this.Videos = videos;
}
} }
}); });
@ -22,10 +36,10 @@ let AdminApp = new Vue({
el: "#admin_app", el: "#admin_app",
template: ` template: `
<div> <div>
<SCH style="max-width:800px; padding-left:100px;" /> <SCH v-on:search_complete="search_completed"/>
<CADD/> <CADD/>
<CTBL/> <CTBL v-bind:Channels="Channels"/>
<VTBL/> <VTBL v-bind:Videos="Videos"/>
</div> </div>
`, `,
components: { components: {
@ -34,7 +48,20 @@ let AdminApp = new Vue({
CTBL, CTBL,
VTBL VTBL
}, },
data() {
return {
Videos: Array<Video>(),
Channels: Array<Channel>()
}
},
methods: { methods: {
// Callback for when the search component got results back.
search_completed(videos : Array<Video>) : void {
this.Videos = videos;
}
},
mounted(){
// Populate the channels field immediatly on start up.
search_channels("").then(channels => this.Channels = channels);
} }
}); });