Add channel-creator

This commit is contained in:
Peter Stuifzand 2018-09-01 14:09:11 +02:00
parent a74af5b91a
commit 7c0545874a
4 changed files with 95 additions and 3 deletions

View File

@ -0,0 +1,59 @@
<template>
<div :class="modalClasses">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Create Channel</p>
<button class="delete" aria-label="close" @click="close"></button>
</header>
<section class="modal-card-body">
<div class="field">
<label for="name" class="label">Name</label>
<div class="control"><input type="text" v-model="name" id="name" class="input"/></div>
</div>
</section>
<footer class="modal-card-foot">
<button class="button is-success" @click="create">Add channel</button>
<button class="button" @click="close">Cancel</button>
</footer>
</div>
</div>
</template>
<script>
export default {
name: "ChannelCreator",
props:['isOpen'],
data() {
return {
'name': ''
}
},
computed: {
modalClasses() {
return {'modal': true, 'is-active': this.isOpen}
}
},
methods: {
close() {
this.$store.dispatch('closeChannelCreator')
this.name = ''
},
create() {
this.$store.dispatch('createChannel', this.name)
.then(() => {
this.close()
})
}
}
}
</script>
<style scoped>
</style>

View File

@ -3,13 +3,21 @@
<div class="channels--channel" v-for="channel in channels" :key="channel.uid"> <div class="channels--channel" v-for="channel in channels" :key="channel.uid">
<slot :channel="channel"></slot> <slot :channel="channel"></slot>
</div> </div>
<button class="button is-primary" @click="open">+ New Channel</button>
</div> </div>
</template> </template>
<script> <script>
import ChannelCreator from "./ChannelCreator";
export default { export default {
name: "Channels", name: "Channels",
props: ['className', 'channels'] components: {ChannelCreator},
props: ['className', 'channels'],
methods: {
open() {
this.$store.dispatch('openChannelCreator')
}
}
} }
</script> </script>

View File

@ -13,7 +13,8 @@ export default new Vuex.Store({
debug: false, debug: false,
logged_in: false, logged_in: false,
micropubEndpoint: '', micropubEndpoint: '',
microsubEndpoint: '' microsubEndpoint: '',
channelCreatorIsOpen: false
}; };
let loginData = JSON.parse(window.localStorage.getItem('login_data')) let loginData = JSON.parse(window.localStorage.getItem('login_data'))
if (loginData) { if (loginData) {
@ -47,6 +48,9 @@ export default new Vuex.Store({
items: [], items: [],
paging: {} paging: {}
} }
},
setChannelCreatorState(state, open) {
state.channelCreatorIsOpen = open
} }
}, },
@ -119,6 +123,23 @@ export default new Vuex.Store({
'like-of': [url] 'like-of': [url]
} }
}) })
},
openChannelCreator({commit}) {
commit('setChannelCreatorState', true)
},
closeChannelCreator({commit}) {
commit('setChannelCreatorState', false)
},
createChannel(x, name) {
let url = this.state.microsubEndpoint + '?action=channels&name=' + encodeURIComponent(name)
return fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + this.state.access_token
}
}).then(() => {
this.dispatch('fetchChannels')
})
} }
} }
}) })

View File

@ -8,6 +8,8 @@
<Timeline class="timeline" :timeline="this.$store.state.timeline" :channel="this.$store.state.channel" <Timeline class="timeline" :timeline="this.$store.state.timeline" :channel="this.$store.state.channel"
@getPage="getPage"></Timeline> @getPage="getPage"></Timeline>
<channel-creator :is-open="this.$store.state.channelCreatorIsOpen"></channel-creator>
</div> </div>
</template> </template>
@ -16,13 +18,15 @@
import Timeline from '@/components/Timeline.vue' import Timeline from '@/components/Timeline.vue'
import Channels from '@/components/Channels.vue' import Channels from '@/components/Channels.vue'
import Channel from '@/components/Channel.vue' import Channel from '@/components/Channel.vue'
import ChannelCreator from '@/components/ChannelCreator.vue'
export default { export default {
name: 'home', name: 'home',
components: { components: {
Timeline, Timeline,
Channels, Channels,
Channel Channel,
ChannelCreator
}, },
computed: { computed: {