Skip to content

Commit

Permalink
Merge pull request #469 from h3poteto/iss-461
Browse files Browse the repository at this point in the history
closes #461 Add toot visibility setting and use it in new toot modal
  • Loading branch information
h3poteto authored Aug 3, 2018
2 parents 036c10a + af43064 commit bc0f320
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 49 deletions.
18 changes: 18 additions & 0 deletions src/constants/visibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
Public: {
name: 'public',
value: 0
},
Unlisted: {
name: 'unlisted',
value: 1
},
Private: {
name: 'private',
value: 2
},
Direct: {
name: 'direct',
value: 3
}
}
4 changes: 3 additions & 1 deletion src/main/preferences.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import storage from 'electron-json-storage'
import objectAssignDeep from 'object-assign-deep'
import Visibility from '../constants/visibility'

const Base = {
general: {
Expand All @@ -9,7 +10,8 @@ const Base = {
},
theme: 'white',
fontSize: 14,
displayNameStyle: 0
displayNameStyle: 0,
tootVisibility: Visibility.Public.value
},
state: {
collapse: false
Expand Down
92 changes: 57 additions & 35 deletions src/renderer/components/Preferences/General.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@
</tbody>
</table>
</div>
<div class="toot">
<h3>Toot</h3>
<table>
<tbody>
<tr>
<td class="title">Default Visibility:</td>
<td class="status">
<el-select v-model="tootVisibility" placeholder="visibility">
<el-option
v-for="v in visibilities"
:key="v.value"
:label="v.name"
:value="v.value">
</el-option>
</el-select>
</td>
</tr>
</tbody>
</table>
</div>
<div class="sounds">
<h3>Sounds</h3>
<table>
Expand Down Expand Up @@ -64,6 +84,7 @@

<script>
import { mapState } from 'vuex'
import Visibility from '../../../constants/visibility'
export default {
name: 'general',
Expand All @@ -82,6 +103,11 @@ export default {
name: 'username',
value: 2
}
],
visibilities: [
Visibility.Public,
Visibility.Unlisted,
Visibility.Private
]
}
},
Expand All @@ -106,6 +132,14 @@ export default {
this.$store.dispatch('Preferences/General/updateDisplayNameStyle', value)
}
},
tootVisibility: {
get () {
return this.$store.state.Preferences.General.general.tootVisibility
},
set (value) {
this.$store.dispatch('Preferences/General/updateTootVisibility', value)
}
},
sound_fav_rb: {
get () {
return this.$store.state.Preferences.General.general.sound.fav_rb
Expand Down Expand Up @@ -146,52 +180,40 @@ export default {

<style lang="scss" scoped>
#general {
.appearance {
color: var(--theme-secondary-color);
table {
width: 100%;
box-sizing: border-box;
table {
width: 100%;
}
}
td {
padding: 16px 0;
}
td {
padding: 16px 0;
}
.title {
text-align: right;
width: 50%;
}
.title {
text-align: right;
width: 50%;
}
.status {
width: 50%;
text-align: center;
}
.status {
width: 50%;
text-align: center;
}
.sounds {
.appearance {
color: var(--theme-secondary-color);
width: 100%;
box-sizing: border-box;
}
table {
width: 100%;
}
td {
padding: 16px 0;
}
.title {
text-align: right;
width: 50%;
}
.toot {
color: var(--theme-secondary-color);
width: 100%;
box-sizing: border-box;
}
.status {
width: 50%;
text-align: center;
}
.sounds {
color: var(--theme-secondary-color);
width: 100%;
box-sizing: border-box;
}
}
</style>
16 changes: 10 additions & 6 deletions src/renderer/components/TimelineSpace/Modals/NewToot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

<script>
import { mapState } from 'vuex'
import Visibility from '../../../../constants/visibility'
export default {
name: 'new-toot',
Expand All @@ -79,13 +80,13 @@ export default {
sensitive: state => state.TimelineSpace.Modals.NewToot.sensitive,
visibilityIcon: (state) => {
switch (state.TimelineSpace.Modals.NewToot.visibility) {
case 'public':
case Visibility.Public.value:
return 'globe'
case 'unlisted':
case Visibility.Unlisted.value:
return 'unlock'
case 'private':
case Visibility.Private.value:
return 'lock'
case 'direct':
case Visibility.Direct.value:
return 'envelope'
default:
return 'globe'
Expand Down Expand Up @@ -146,9 +147,12 @@ export default {
type: 'error'
})
}
const visibilityKey = Object.keys(Visibility).find((key) => {
return Visibility[key].value === this.visibility
})
let form = {
status: this.status,
visibility: this.visibility,
visibility: Visibility[visibilityKey].name,
sensitive: this.sensitive,
spoiler_text: this.spoiler
}
Expand Down Expand Up @@ -209,7 +213,7 @@ export default {
this.$store.commit('TimelineSpace/Modals/NewToot/removeMedia', media)
},
changeVisibility (level) {
this.$store.commit('TimelineSpace/Modals/NewToot/changeVisibility', level)
this.$store.dispatch('TimelineSpace/Modals/NewToot/changeVisibility', level)
},
changeSensitive () {
this.$store.commit('TimelineSpace/Modals/NewToot/changeSensitive', !this.sensitive)
Expand Down
21 changes: 20 additions & 1 deletion src/renderer/store/Preferences/General.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ipcRenderer } from 'electron'
import Visibility from '../../../constants/visibility'

const General = {
namespaced: true,
Expand All @@ -10,7 +11,8 @@ const General = {
},
theme: 'white',
fontSize: 14,
displayNameStyle: 0
displayNameStyle: 0,
tootVisibility: Visibility.Public.value
},
loading: false
},
Expand Down Expand Up @@ -94,6 +96,23 @@ const General = {
commit('updateGeneral', conf.general)
})
},
updateTootVisibility ({ dispatch, commit, state }, value) {
const newGeneral = Object.assign({}, state.general, {
tootVisibility: value
})
const config = {
general: newGeneral
}
ipcRenderer.send('save-preferences', config)
ipcRenderer.once('error-save-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-save-preferences')
})
ipcRenderer.once('response-save-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-save-preferences')
dispatch('App/loadPreferences', null, { root: true })
commit('updateGeneral', conf.general)
})
},
updateSound ({ commit, state }, sound) {
commit('changeLoading', true)
const newSound = Object.assign({}, state.general.sound, sound)
Expand Down
44 changes: 38 additions & 6 deletions src/renderer/store/TimelineSpace/Modals/NewToot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Mastodon from 'megalodon'
import { ipcRenderer } from 'electron'
import Visibility from '../../../../constants/visibility'

const NewToot = {
namespaced: true,
Expand All @@ -9,7 +10,7 @@ const NewToot = {
replyToMessage: null,
blockSubmit: false,
attachedMedias: [],
visibility: 'public',
visibility: Visibility.Public.value,
sensitive: false,
spoiler: '',
attachedMediaId: 0
Expand All @@ -36,7 +37,22 @@ const NewToot = {
removeMedia (state, media) {
state.attachedMedias = state.attachedMedias.filter(m => m.id !== media.id)
},
changeVisibility (state, value) {
/**
* changeVisibility
* Update visibility using Visibility constants
* @param state vuex state object
* @param visibility Visibility constants object
**/
changeVisibility (state, visibility) {
state.visibility = visibility.value
},
/**
* changeVisibilityValue
* Update visibility using direct value
* @param state vuex state object
* @param value visibility value
**/
changeVisibilityValue (state, value) {
state.visibility = value
},
changeSensitive (state, value) {
Expand Down Expand Up @@ -64,17 +80,21 @@ const NewToot = {
return res.data
})
},
openReply ({ commit, rootState }, message) {
openReply ({ dispatch, commit, rootState }, message) {
commit('setReplyTo', message)
const mentionAccounts = [message.account.acct].concat(message.mentions.map(a => a.acct))
.filter((a, i, self) => self.indexOf(a) === i)
.filter((a) => a !== rootState.TimelineSpace.account.username)
commit('changeModal', true)
commit('updateStatus', `${mentionAccounts.map(m => `@${m}`).join(' ')} `)
commit('changeVisibility', message.visibility)
dispatch('changeVisibility', message.visibility)
},
openModal ({ commit }) {
openModal ({ dispatch, commit }) {
commit('changeModal', true)
ipcRenderer.send('get-preferences')
ipcRenderer.once('response-get-preferences', (event, conf) => {
commit('changeVisibilityValue', conf.general.tootVisibility)
})
},
closeModal ({ commit }) {
commit('changeModal', false)
Expand All @@ -84,7 +104,7 @@ const NewToot = {
commit('clearAttachedMedias')
commit('changeSensitive', false)
commit('updateSpoiler', '')
commit('changeVisibility', 'public')
commit('changeVisibility', Visibility.Public)
},
uploadImage ({ state, commit, rootState }, image) {
commit('changeBlockSubmit', true)
Expand Down Expand Up @@ -115,6 +135,18 @@ const NewToot = {
},
resetMediaId ({ commit }) {
commit('updateMediaId', 0)
},
/**
* changeVisibility
* @param commit vuex commit object
* @param level visibility level string object
**/
changeVisibility ({ commit }, level) {
Object.keys(Visibility).map((key, index) => {
if (Visibility[key].name === level) {
commit('changeVisibility', Visibility[key])
}
})
}
}
}
Expand Down

0 comments on commit bc0f320

Please sign in to comment.