refs #610 Store hashtags and auto insert pined hashtags

This commit is contained in:
AkiraFukushima 2018-09-19 21:24:06 +09:00
parent a9e21af750
commit 2c7d12e7e0
4 changed files with 61 additions and 17 deletions

View File

@ -152,7 +152,8 @@
"add_image": "Add images",
"change_visibility": "Change visibility",
"add_cw": "Add contents warning",
"change_sensitive": "Change sensitive"
"change_sensitive": "Change sensitive",
"pined_hashtag": "Pin the hashtag"
},
"jump": {
"jump_to": "Jump to..."

View File

@ -12,6 +12,7 @@
<Status
v-model="status"
:opened="newTootModal"
:fixCursorPos="hashtagInserting"
@paste="onPaste"
@toot="toot"
/>
@ -79,7 +80,7 @@
</template>
<script>
import { mapState } from 'vuex'
import { mapState, mapGetters } from 'vuex'
import { clipboard } from 'electron'
import Visibility from '~/src/constants/visibility'
import Status from './NewToot/Status'
@ -92,26 +93,25 @@ export default {
data () {
return {
showContentWarning: false,
visibilityList: Visibility,
pinedHashtag: false
visibilityList: Visibility
}
},
computed: {
...mapState({
...mapState('TimelineSpace/Modals/NewToot', {
replyToId: (state) => {
if (state.TimelineSpace.Modals.NewToot.replyToMessage !== null) {
return state.TimelineSpace.Modals.NewToot.replyToMessage.id
if (state.replyToMessage !== null) {
return state.replyToMessage.id
} else {
return null
}
},
attachedMedias: state => state.TimelineSpace.Modals.NewToot.attachedMedias,
attachedMediaId: state => state.TimelineSpace.Modals.NewToot.attachedMediaId,
blockSubmit: state => state.TimelineSpace.Modals.NewToot.blockSubmit,
visibility: state => state.TimelineSpace.Modals.NewToot.visibility,
sensitive: state => state.TimelineSpace.Modals.NewToot.sensitive,
attachedMedias: state => state.attachedMedias,
attachedMediaId: state => state.attachedMediaId,
blockSubmit: state => state.blockSubmit,
visibility: state => state.visibility,
sensitive: state => state.sensitive,
visibilityIcon: (state) => {
switch (state.TimelineSpace.Modals.NewToot.visibility) {
switch (state.visibility) {
case Visibility.Public.value:
return 'globe'
case Visibility.Unlisted.value:
@ -125,6 +125,9 @@ export default {
}
}
}),
...mapGetters('TimelineSpace/Modals/NewToot', [
'hashtagInserting'
]),
newTootModal: {
get () {
return this.$store.state.TimelineSpace.Modals.NewToot.modalOpen
@ -152,6 +155,14 @@ export default {
set (value) {
this.$store.commit('TimelineSpace/Modals/NewToot/updateSpoiler', value)
}
},
pinedHashtag: {
get () {
return this.$store.state.TimelineSpace.Modals.NewToot.pinedHashtag
},
set (value) {
this.$store.commit('TimelineSpace/Modals/NewToot/changePinedHashtag', value)
}
}
},
watch: {
@ -167,7 +178,7 @@ export default {
this.$store.dispatch('TimelineSpace/Modals/NewToot/resetMediaId')
this.$store.dispatch('TimelineSpace/Modals/NewToot/closeModal')
},
toot () {
async toot () {
if (!this.newTootModal) {
return
}
@ -203,13 +214,14 @@ export default {
})
}
this.$store.dispatch('TimelineSpace/Modals/NewToot/postToot', form)
const status = await this.$store.dispatch('TimelineSpace/Modals/NewToot/postToot', form)
.catch(() => {
this.$message({
message: this.$t('message.toot_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/Modals/NewToot/updateHashtags', status.tags)
this.close()
},
selectImage () {

View File

@ -50,6 +50,10 @@ export default {
opened: {
type: Boolean,
default: false
},
fixCursorPos: {
type: Boolean,
default: false
}
},
data () {
@ -82,12 +86,18 @@ export default {
// When change account, the new toot modal is recreated.
// So can not catch open event in watch.
this.$refs.status.focus()
if (this.fixCursorPos) {
this.$refs.status.setSelectionRange(0, 0)
}
},
watch: {
opened: function (newState, oldState) {
if (!oldState && newState) {
this.$nextTick(function () {
this.$refs.status.focus()
if (this.fixCursorPos) {
this.$refs.status.setSelectionRange(0, 0)
}
})
} else if (oldState && !newState) {
this.closeSuggest()

View File

@ -17,7 +17,9 @@ const NewToot = {
visibility: Visibility.Public.value,
sensitive: false,
spoiler: '',
attachedMediaId: 0
attachedMediaId: 0,
pinedHashtag: false,
hashtags: []
},
mutations: {
changeModal (state, value) {
@ -58,6 +60,17 @@ const NewToot = {
},
updateMediaId (state, value) {
state.attachedMediaId = value
},
changePinedHashtag (state, value) {
state.pinedHashtag = value
},
updateHashtags (state, tags) {
state.hashtags = tags
}
},
getters: {
hashtagInserting (state) {
return !state.replyToMessage && state.pinedHashtag
}
},
actions: {
@ -91,8 +104,11 @@ const NewToot = {
})
commit('changeVisibilityValue', value)
},
openModal ({ dispatch, commit, rootState }) {
openModal ({ dispatch, commit, state, rootState }) {
commit('changeModal', true)
if (!state.replyToMessage && state.pinedHashtag) {
commit('updateStatus', state.hashtags.map(t => ` #${t.name}`).join())
}
commit('changeVisibilityValue', rootState.App.tootVisibility)
},
closeModal ({ commit }) {
@ -134,6 +150,11 @@ const NewToot = {
},
resetMediaId ({ commit }) {
commit('updateMediaId', 0)
},
updateHashtags ({ commit, state }, tags) {
if (state.pinedHashtag) {
commit('updateHashtags', tags)
}
}
}
}