From d5f2db098a08e2df299b90defa2aa41ed2c94f1d Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Wed, 23 Jan 2019 22:25:18 +0900 Subject: [PATCH] refs #825 Add preferences to change cw and nfsw --- .../store/Preferences/General.spec.js | 54 +++++++++++++------ src/config/locales/en/translation.json | 6 +++ src/main/preferences.js | 4 ++ .../components/Preferences/General.vue | 38 +++++++++++++ src/renderer/store/Preferences/General.js | 28 ++++++++++ 5 files changed, 115 insertions(+), 15 deletions(-) diff --git a/spec/integration/store/Preferences/General.spec.js b/spec/integration/store/Preferences/General.spec.js index 2ed26472..9a35e2cf 100644 --- a/spec/integration/store/Preferences/General.spec.js +++ b/spec/integration/store/Preferences/General.spec.js @@ -3,21 +3,28 @@ import Vuex from 'vuex' import { ipcMain } from '~/spec/mock/electron' import General from '@/store/Preferences/General' -const state = { - general: { - sound: { - fav_rb: true, - toot: true - } - }, - loading: false +const state = () => { + return { + general: { + sound: { + fav_rb: true, + toot: true + }, + timeline: { + cw: false, + nfsw: false + } + }, + loading: false + } } - -const Preferences = { - namespaced: true, - state: state, - actions: General.actions, - mutations: General.mutations +const initStore = () => { + return { + namespaced: true, + state: state(), + actions: General.actions, + mutations: General.mutations + } } describe('Preferences/General', () => { @@ -29,7 +36,7 @@ describe('Preferences/General', () => { localVue.use(Vuex) store = new Vuex.Store({ modules: { - Preferences + Preferences: initStore() } }) }) @@ -71,4 +78,21 @@ describe('Preferences/General', () => { expect(store.state.Preferences.loading).toEqual(false) }) }) + + describe('updateTimeline', () => { + beforeEach(() => { + ipcMain.once('update-preferences', (event, config) => { + event.sender.send('response-update-preferences', config) + }) + }) + it('should be updated', async () => { + await store.dispatch('Preferences/updateTimeline', { + cw: true, + nfsw: true + }) + expect(store.state.Preferences.general.timeline.cw).toEqual(true) + expect(store.state.Preferences.general.timeline.nfsw).toEqual(true) + expect(store.state.Preferences.loading).toEqual(false) + }) + }) }) diff --git a/src/config/locales/en/translation.json b/src/config/locales/en/translation.json index 79f7592a..c9e2590c 100644 --- a/src/config/locales/en/translation.json +++ b/src/config/locales/en/translation.json @@ -116,6 +116,12 @@ "description": "Please set feedback sounds.", "fav_rb": "When you favorite or boost the toot", "toot": "When you post toot" + }, + "timeline": { + "title": "Timeline", + "description": "Customize view in your timelines.", + "cw": "Always ignore contents warnings", + "nfsw": "Always ignore NFSW of medias" } }, "appearance": { diff --git a/src/main/preferences.js b/src/main/preferences.js index 62f83cf8..2f74ac1d 100644 --- a/src/main/preferences.js +++ b/src/main/preferences.js @@ -12,6 +12,10 @@ const Base = { sound: { fav_rb: true, toot: true + }, + timeline: { + cw: false, + nfsw: false } }, state: { diff --git a/src/renderer/components/Preferences/General.vue b/src/renderer/components/Preferences/General.vue index 003fe908..e207bb73 100644 --- a/src/renderer/components/Preferences/General.vue +++ b/src/renderer/components/Preferences/General.vue @@ -19,6 +19,24 @@ + +

{{ $t('preferences.general.timeline.title') }}

+

{{ $t('preferences.general.timeline.description') }}

+ + + + + + + + +
@@ -50,6 +68,26 @@ export default { toot: value }) } + }, + timeline_cw: { + get () { + return this.$store.state.Preferences.General.general.timeline.cw + }, + set (value) { + this.$store.dispatch('Preferences/General/updateTimeline', { + cw: value + }) + } + }, + timeline_nfsw: { + get () { + return this.$store.state.Preferences.General.general.timeline.nfsw + }, + set (value) { + this.$store.dispatch('Preferences/General/updateTimeline', { + nfsw: value + }) + } } }, created () { diff --git a/src/renderer/store/Preferences/General.js b/src/renderer/store/Preferences/General.js index 56cf8ac5..3b188b6c 100644 --- a/src/renderer/store/Preferences/General.js +++ b/src/renderer/store/Preferences/General.js @@ -7,6 +7,10 @@ const General = { sound: { fav_rb: true, toot: true + }, + timeline: { + cw: false, + nfsw: false } }, loading: false @@ -60,6 +64,30 @@ const General = { resolve(conf) }) }) + }, + updateTimeline ({ commit, state }, timeline) { + commit('changeLoading', true) + const newTimeline = Object.assign({}, state.general.timeline, timeline) + const newGeneral = Object.assign({}, state.general, { + timeline: newTimeline + }) + const config = { + general: newGeneral + } + return new Promise((resolve, reject) => { + ipcRenderer.once('error-update-preferences', (event, err) => { + ipcRenderer.removeAllListeners('response-update-preferences') + commit('changeLoading', false) + reject(err) + }) + ipcRenderer.once('response-update-preferences', (event, conf) => { + ipcRenderer.removeAllListeners('error-update-preferences') + commit('updateGeneral', conf.general) + commit('changeLoading', false) + resolve(conf) + }) + ipcRenderer.send('update-preferences', config) + }) } } }