initial import

This commit is contained in:
2021-05-05 19:17:01 +00:00
commit 09e1d643b6
54 changed files with 14073 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
<template>
<div id="app">
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item" href="https://bulma.io">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28" />
</a>
<a
role="button"
class="navbar-burger burger"
aria-label="menu"
aria-expanded="false"
data-target="navbarBasicExample"
>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">Home</a>
</div>
<div class="navbar-end"></div>
</div>
</div>
</nav>
<router-view />
</div>
</template>
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

+7
View File
@@ -0,0 +1,7 @@
@import "~bulma/sass/utilities/initial-variables";
$scheme-main: $black-ter;
$scheme-invert: $white-ter;
$text: $grey-lightest;
@import "~bulma/bulma";
+24
View File
@@ -0,0 +1,24 @@
<template>
<div class="notification" v-bind:class="active ? 'is-success' : 'is-danger'">
<span v-if="active">Connected as {{ channel }}</span>
<span v-else>Disconnected</span>
</div>
</template>
<script>
import eventSource from "@/eventsource";
export default {
name: "Connection",
computed: {
active() {
return eventSource.isConnected()
},
},
props: {
channel: String,
active: Boolean,
},
};
</script>
+14
View File
@@ -0,0 +1,14 @@
<template>
<div class="hello">
<h1>{{ msg }}</h1>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String
}
}
</script>
@@ -0,0 +1,7 @@
import store from '@/store'
export default {
handle(data) {
store.setCreditsAction(data.content)
}
}
@@ -0,0 +1,13 @@
import credits from './credits'
var handlers = {
'credits': credits
}
export default {
handle(data) {
if(handlers[data.type]) {
handlers[data.type].handle(data)
}
}
}
+56
View File
@@ -0,0 +1,56 @@
import store from "../store"
import handler from './handlers'
var connection = null
var onOpenCallback = null
var onCloseCallback = null
const eventSource = {
connect(channel) {
if(connection != null) {
connection.close();
}
connection = new EventSource('/feed/updates/' + channel)
connection.addEventListener("message", function(message) {
var data = JSON.parse(message.data)
handler.handle(data)
store.setRawMessageAction(message.data)
})
connection.addEventListener("open", function () {
if(typeof onOpenCallback === 'function') {
onOpenCallback()
}
})
connection.addEventListener("close", function () {
if(typeof onCloseCallback === 'function') {
onCloseCallback()
}
})
connection.addEventListener("error", function () {
if(connection.readyState !== EventSource.CONNECTING) {
if(typeof onCloseCallback === 'function') {
onCloseCallback()
}
}
})
},
isConnected() {
return connection.readyState === EventSource.OPEN
},
isConnecting() {
return connection.readyState === EventSource.CONNECTING
},
onOpen(callback) {
onOpenCallback = callback
},
onClose(callback) {
onCloseCallback = callback
}
}
export default eventSource
+17
View File
@@ -0,0 +1,17 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import store from './store'
import router from './router'
import './assets/main.scss'
Vue.config.productionTip = false
Vue.use(VueRouter)
new Vue({
data: store.state,
router,
render: h => h(App)
}).$mount('#app')
+27
View File
@@ -0,0 +1,27 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/:channel?',
name: 'Home',
component: Home
}
// {
// path: '/about',
// name: 'About',
// // route level code-splitting
// // this generates a separate chunk (about.[hash].js) for this route
// // which is lazy-loaded when the route is visited.
// component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
// }
]
const router = new VueRouter({
routes
})
export default router
+20
View File
@@ -0,0 +1,20 @@
const store = {
state: {
credits: 0,
message: 'Hello World!',
},
setCreditsAction(newValue) {
this.state.credits = newValue
},
setRawMessageAction(newValue) {
this.state.message = newValue
},
setMessageAction(newValue) {
this.state.message = newValue
},
clearMessageAction() {
this.state.message = ''
}
}
export default store
+61
View File
@@ -0,0 +1,61 @@
<template>
<div class="home">
<Connection v-bind:active="active" v-bind:channel="currentChannel" />
<HelloWorld v-bind:msg="message" />
<div>
Credits: {{ credits }}
</div>
</div>
</template>
<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
import Connection from "@/components/Connection.vue";
import eventSource from "@/eventsource";
var connect = function (channel) {
if (channel != "undefined" && channel != data.currentChannel) {
data.currentChannel = channel;
eventSource.connect(channel);
}
};
var data = {
active: false,
currentChannel: "",
};
export default {
name: "Home",
data() {
return data;
},
computed: {
message() {
return this.$root.message;
},
credits() {
return this.$root.credits;
}
},
watch: {
$route(to) {
connect(to.params.channel);
},
},
created() {
eventSource.onOpen(function () {
data.active = true;
});
eventSource.onClose(function () {
data.active = false;
});
connect(this.$route.params.channel);
},
components: {
HelloWorld,
Connection,
},
};
</script>