added updateServer and updateChannel

This commit is contained in:
supertiger1234 2019-07-15 20:20:43 +01:00
parent 2e1b75d654
commit 49f4bf7c5e
7 changed files with 60 additions and 4 deletions

View file

@ -22,7 +22,7 @@
@change="changeEvent('default_channel_id', $event.channelID)" @change="changeEvent('default_channel_id', $event.channelID)"
/> />
</div> </div>
<div class="button save-button" v-if="changed">Save Changes</div> <div class="button save-button" v-if="changed" @click="updateServer()">Save Changes</div>
</div> </div>
</div> </div>
</template> </template>
@ -49,10 +49,19 @@ export default {
}, },
changeEvent(name, value) { changeEvent(name, value) {
this.$set(this.update, name, value); this.$set(this.update, name, value);
},
async updateServer() {
const {ok, error, result} = await ServerService.updateServer(this.server.server_id, this.update);
if (ok) {
this.update = {};
}
} }
}, },
watch: { watch: {
update(test) { update(obj) {
if ( Object.keys(obj).length === 0 ){
return this.changed = false
}
this.changed = true; this.changed = true;
} }
}, },

View file

@ -10,6 +10,7 @@
<input type="text" ref="name" placeholder="Channel Name" :default-value.prop="channels[selectedChannelIndex].name" @input="inputEvent('name', $event)"> <input type="text" ref="name" placeholder="Channel Name" :default-value.prop="channels[selectedChannelIndex].name" @input="inputEvent('name', $event)">
</div> </div>
<div class="button" v-if="update.name" @click="updateChannel">Save Changes</div> <div class="button" v-if="update.name" @click="updateChannel">Save Changes</div>
<div class="button warn delete-server disabled" v-if="server.default_channel_id === channels[selectedChannelIndex].channelID">Cannot delete default channel</div>
<div class="button warn delete-server" :class="{disabled: deleteClicked}" v-if="server.default_channel_id !== channels[selectedChannelIndex].channelID" @click="deleteChannel">{{deleteButtonConfirmed ? 'ARE YOU SURE?' : 'Delete Channel' }}</div> <div class="button warn delete-server" :class="{disabled: deleteClicked}" v-if="server.default_channel_id !== channels[selectedChannelIndex].channelID" @click="deleteChannel">{{deleteButtonConfirmed ? 'ARE YOU SURE?' : 'Delete Channel' }}</div>
</div> </div>
</div> </div>

View file

@ -4,6 +4,9 @@ export default {
post ( data ) { post ( data ) {
return wrapper(instance().post('/server', data)); return wrapper(instance().post('/server', data));
}, },
updateServer (serverID, data) {
return wrapper(instance().patch(`/server/${serverID}`, data));
},
getChannels(serverID) { getChannels(serverID) {
return wrapper(instance().get(`/server/channels/${serverID}`)); return wrapper(instance().get(`/server/channels/${serverID}`));
}, },

View file

@ -30,7 +30,7 @@ const actions = {
context.commit('removeChannel', channelID) context.commit('removeChannel', channelID)
}, },
updateChannel(context, data) { updateChannel(context, data) {
const update = Object.assign(context.state.channels[data.channelID], data); const update = Object.assign({}, context.state.channels[data.channelID], data);
context.commit('channel', update) context.commit('channel', update)
}, },
selectedChannelID(context, channelID) { selectedChannelID(context, channelID) {

View file

@ -34,6 +34,10 @@ const actions = {
setServer(context, server) { setServer(context, server) {
context.commit('SET_SERVER', server); context.commit('SET_SERVER', server);
}, },
updateServer(context, {server_id, server}) {
const update = Object.assign({}, context.state.servers[server_id], server)
context.commit('SET_SERVER', update);
},
removeServer(context, serverID) { removeServer(context, serverID) {
context.commit('REMOVE_SERVER', serverID); context.commit('REMOVE_SERVER', serverID);
}, },

View file

@ -268,6 +268,10 @@ const actions = {
context.dispatch('servers/removeServerChannel', {server_id, channelID}); context.dispatch('servers/removeServerChannel', {server_id, channelID});
// context.dispatch('removeChannel', {channelID}); // context.dispatch('removeChannel', {channelID});
}, },
['socket_server:updateServer'](context, data) {
context.dispatch('servers/updateServer', {server_id: data.server_id, server: data});
// context.dispatch('removeChannel', {channelID});
},
} }
export default { export default {

View file

@ -13,10 +13,45 @@
} }
const config = [ const config = [
{
version: 5.0,
title: "Change server name and default server channel",
shortTitle: "Change server name and default server channel",
date: "15/07/2019",
headColor: "rgba(255, 0, 0, 0.77)",
new: [
"You can now change the name of your server.",
"You can now change the default channel to something else.",
],
fix: ['Some bugs have been fixed.'],
next: ["Change servers avatar."],
},
{ {
version: 4.9, version: 4.9,
title: "Color codeblocks and create multiple channels!", title: "Color codeblocks and create multiple channels!",
shortTitle: "", shortTitle: "Color codeblocks and create multiple channels!",
date: "12/07/2019", date: "12/07/2019",
headColor: "rgba(190, 40, 40, 0.77)", headColor: "rgba(190, 40, 40, 0.77)",
new: [ new: [