Working room & client refactor
This commit is contained in:
@@ -5,10 +5,12 @@ const state = {
|
||||
roomCode: '',
|
||||
player: {
|
||||
timeCode: 0,
|
||||
timeLength: 0,
|
||||
playing: true
|
||||
},
|
||||
current: {
|
||||
link: '',
|
||||
linkID: '',
|
||||
title: '',
|
||||
votes: 0,
|
||||
voters: []
|
||||
@@ -33,28 +35,30 @@ const actions = {
|
||||
setAdmin ({ commit }) {
|
||||
commit('SET_ADMIN')
|
||||
},
|
||||
vote ({ commit, dispatch, state }, { link, isPositive, voterName }) {
|
||||
console.log('vote on ' + link + ' (' + isPositive + ') by ' + voterName)
|
||||
vote ({ commit, dispatch, state }, { link, linkID, isPositive, voterName }) {
|
||||
console.log('vote on ' + link + ' | ' + linkID + ' (' + isPositive + ') by ' + voterName)
|
||||
if (isPositive) {
|
||||
commit('ADD_VOTE', {
|
||||
linkID: linkID,
|
||||
link: link,
|
||||
voterName: voterName
|
||||
})
|
||||
} else {
|
||||
commit('REMOVE_VOTE', {
|
||||
link: link,
|
||||
linkID: linkID,
|
||||
voterName: voterName
|
||||
})
|
||||
}
|
||||
dispatch('rtc/broadcast', { message: state.roomStatus, type: 'status' }, { root: true })
|
||||
},
|
||||
setCurrent ({ commit, dispatch }, { playerStatus, timeCode }) {
|
||||
setCurrent ({ commit, dispatch }, { playerStatus, timeCode, title }) {
|
||||
switch (playerStatus) {
|
||||
case 0:
|
||||
commit('CURRENT_END')
|
||||
break
|
||||
case 1:
|
||||
commit('CURRENT_PLAY', timeCode)
|
||||
commit('SET_CURRENTTITLE', title)
|
||||
break
|
||||
case 2:
|
||||
commit('CURRENT_PAUSE', timeCode)
|
||||
@@ -77,11 +81,15 @@ const mutations = {
|
||||
SET_ADMIN (state) {
|
||||
state.admin = true
|
||||
},
|
||||
ADD_VOTE (state, { link, voterName }) {
|
||||
var play = state.roomStatus.playlist.find(play => play.link === link)
|
||||
SET_CURRENTTITLE (state, title) {
|
||||
state.roomStatus.current.title = title
|
||||
},
|
||||
ADD_VOTE (state, { link, linkID, voterName }) {
|
||||
var play = state.roomStatus.playlist.find(play => play.linkID === linkID)
|
||||
if (play === undefined) {
|
||||
play = {
|
||||
link: link,
|
||||
linkID: linkID,
|
||||
votes: 1,
|
||||
voters: [
|
||||
voterName
|
||||
@@ -94,8 +102,8 @@ const mutations = {
|
||||
play.voters.push(voterName)
|
||||
}
|
||||
},
|
||||
REMOVE_VOTE (state, { link, voterName }) {
|
||||
var play = state.roomStatus.playlist.find(play => play.link === link)
|
||||
REMOVE_VOTE (state, { linkID, voterName }) {
|
||||
var play = state.roomStatus.playlist.find(play => play.linkID === linkID)
|
||||
play.votes--
|
||||
const index = play.voters.indexOf(voterName)
|
||||
if (index > -1) {
|
||||
@@ -111,10 +119,13 @@ const mutations = {
|
||||
},
|
||||
CURRENT_END (state) {
|
||||
if (state.roomStatus.playlist.length === 0) {
|
||||
state.roomStatus.current.link = ''
|
||||
state.roomStatus.current.title = ''
|
||||
state.roomStatus.current.votes = 0
|
||||
state.roomStatus.current.voters = []
|
||||
state.roomStatus.current = {
|
||||
link: '',
|
||||
linkID: '',
|
||||
title: '',
|
||||
votes: 0,
|
||||
voters: []
|
||||
}
|
||||
} else {
|
||||
state.roomStatus.playlist.sort((a, b) => {
|
||||
return b.votes - a.votes
|
||||
|
||||
Reference in New Issue
Block a user