Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2021-03-22 09:03:57 +0300
committerdartcafe <github@dartcafe.de>2021-03-22 09:03:57 +0300
commitc165ee20f9f840087fa56346d716e41163c262fa (patch)
tree78bceba699d4be9cf2e3db830c21f6bde8aa16a3 /src/js/store/modules/settings.js
parentcfa138e12f20994543bc6aca809847ad636a79c8 (diff)
drill down actions to components and move some logic to store
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src/js/store/modules/settings.js')
-rw-r--r--src/js/store/modules/settings.js75
1 files changed, 74 insertions, 1 deletions
diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js
index 53d3441d..f71802ab 100644
--- a/src/js/store/modules/settings.js
+++ b/src/js/store/modules/settings.js
@@ -36,6 +36,10 @@ const defaultSettings = () => {
defaultViewTextPoll: 'list-view',
defaultViewDatePoll: 'table-view',
},
+ session: {
+ manualViewDatePoll: '',
+ manualViewTextPoll: '',
+ },
availableCalendars: [],
viewModes: [
'list-view',
@@ -71,12 +75,65 @@ const mutations = {
state.user[key] = payload[key]
})
},
+
setCalendars(state, payload) {
state.availableCalendars = payload.calendars
},
+
addCheckCalendar(state, payload) {
state.user.checkCalendars.push(payload.calendar.key)
},
+
+ setViewDatePoll(state, payload) {
+ state.session.manualViewDatePoll = payload
+ },
+ setViewTextPoll(state, payload) {
+ state.session.manualViewTextPoll = payload
+ },
+}
+
+const getters = {
+ viewTextPoll(state) {
+ if (state.session.manualViewTextPoll) {
+ return state.session.manualViewTextPoll
+ } else {
+ if (window.innerWidth > 480) {
+ return state.user.defaultViewTextPoll
+ } else {
+ return 'list-view'
+ }
+ }
+ },
+
+ getNextViewMode(state, getters) {
+ if (state.viewModes.indexOf(getters.viewMode) < 0) {
+ return state.viewModes[1]
+ } else {
+ return state.viewModes[(state.viewModes.indexOf(getters.viewMode) + 1) % state.viewModes.length]
+ }
+ },
+
+ viewDatePoll(state) {
+ if (state.session.manualViewDatePoll) {
+ return state.session.manualViewDatePoll
+ } else {
+ if (window.innerWidth > 480) {
+ return state.user.defaultViewDatePoll
+ } else {
+ return 'list-view'
+ }
+ }
+ },
+
+ viewMode(state, getters, rootState) {
+ if (rootState.poll.type === 'textPoll') {
+ return getters.viewTextPoll
+ } else if (rootState.poll.type === 'datePoll') {
+ return getters.viewDatePoll
+ } else {
+ return 'table-view'
+ }
+ },
}
const actions = {
@@ -102,6 +159,22 @@ const actions = {
}
},
+ changeView(context) {
+ if (context.rootState.poll.type === 'datePoll') {
+ if (context.state.manualViewDatePoll) {
+ context.commit('setViewDatePoll', '')
+ } else {
+ context.commit('setViewDatePoll', context.getters.getNextViewMode)
+ }
+ } else if (context.rootState.poll.type === 'textPoll') {
+ if (context.state.manualViewTextPoll) {
+ context.commit('setViewTextPoll', '')
+ } else {
+ context.commit('setViewTextPoll', context.getters.getNextViewMode)
+ }
+ }
+ },
+
async write(context) {
const endPoint = 'apps/polls/preferences/write'
try {
@@ -121,4 +194,4 @@ const actions = {
},
}
-export default { namespaced, state, mutations, actions }
+export default { namespaced, state, mutations, getters, actions }