mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-01-29 00:29:46 +01:00
refs #52 Use own vuex store in NewTootModal
This commit is contained in:
parent
b5020bafcf
commit
615c767019
@ -14,7 +14,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="content" v-html="message.content" @click.capture.prevent="tootClick"></div>
|
<div class="content" v-html="message.content" @click.capture.prevent="tootClick"></div>
|
||||||
<div class="tool-box">
|
<div class="tool-box">
|
||||||
<el-button type="text"><icon name="reply" scale="0.9"></icon></el-button>
|
<el-button type="text" @click="openReply(message)"><icon name="reply" scale="0.9"></icon></el-button>
|
||||||
<el-button type="text"><icon name="retweet" scale="0.9"></icon></el-button>
|
<el-button type="text"><icon name="retweet" scale="0.9"></icon></el-button>
|
||||||
<el-button type="text" @click="changeFavourite(message)" :class="message.favourited ? 'favourited' : ''"><icon name="star" scale="0.9"></icon></el-button>
|
<el-button type="text" @click="changeFavourite(message)" :class="message.favourited ? 'favourited' : ''"><icon name="star" scale="0.9"></icon></el-button>
|
||||||
</div>
|
</div>
|
||||||
@ -41,6 +41,9 @@ export default {
|
|||||||
shell.openExternal(link)
|
shell.openExternal(link)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
openReply (message) {
|
||||||
|
this.$store.dispatch('TimelineSpace/openReply', message)
|
||||||
|
},
|
||||||
changeFavourite (message) {
|
changeFavourite (message) {
|
||||||
if (message.favourited) {
|
if (message.favourited) {
|
||||||
this.$store.dispatch('TimelineSpace/Cards/Toot/removeFavourite', message)
|
this.$store.dispatch('TimelineSpace/Cards/Toot/removeFavourite', message)
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
width="400px"
|
width="400px"
|
||||||
class="new-toot-modal" v-on:submit.prevent="toot">
|
class="new-toot-modal" v-on:submit.prevent="toot">
|
||||||
<el-form :model="tootForm">
|
<el-form :model="tootForm">
|
||||||
<div class="body">
|
<div class="status">
|
||||||
<textarea v-model="tootForm.body" ref="body" @keyup.ctrl.enter.exact="toot" @keyup.meta.enter.exact="toot"></textarea>
|
<textarea v-model="tootForm.status" ref="status" @keyup.ctrl.enter.exact="toot" @keyup.meta.enter.exact="toot"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
<span slot="footer" class="dialog-footer">
|
<span slot="footer" class="dialog-footer">
|
||||||
<span class="text-count">{{ 500 - tootForm.body.length }}</span>
|
<span class="text-count">{{ 500 - tootForm.status.length }}</span>
|
||||||
<el-button @click="close">Cancel</el-button>
|
<el-button @click="close">Cancel</el-button>
|
||||||
<el-button type="primary" @click="toot">Toot</el-button>
|
<el-button type="primary" @click="toot">Toot</el-button>
|
||||||
</span>
|
</span>
|
||||||
@ -23,39 +23,39 @@ export default {
|
|||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
tootForm: {
|
tootForm: {
|
||||||
body: ''
|
status: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
newTootModal: {
|
newTootModal: {
|
||||||
get () {
|
get () {
|
||||||
return this.$store.state.TimelineSpace.newTootModal
|
return this.$store.state.TimelineSpace.NewTootModal.modalOpen
|
||||||
},
|
},
|
||||||
set (value) {
|
set (value) {
|
||||||
this.$store.commit('TimelineSpace/changeNewTootModal', value)
|
this.$store.commit('TimelineSpace/NewTootModal/changeModal', value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updated () {
|
updated () {
|
||||||
if (this.newTootModal) {
|
if (this.newTootModal) {
|
||||||
this.$refs.body.focus()
|
this.$refs.status.focus()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
close () {
|
close () {
|
||||||
this.$store.commit('TimelineSpace/changeNewTootModal', false)
|
this.$store.commit('TimelineSpace/NewTootModal/changeModal', false)
|
||||||
},
|
},
|
||||||
toot () {
|
toot () {
|
||||||
if (this.tootForm.body.length <= 0 || this.tootForm.body.length >= 500) {
|
if (this.tootForm.status.length <= 0 || this.tootForm.status.length >= 500) {
|
||||||
return this.$message({
|
return this.$message({
|
||||||
message: 'Toot length should be 1 to 500',
|
message: 'Toot length should be 1 to 500',
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.$store.dispatch('TimelineSpace/postToot', this.tootForm.body)
|
this.$store.dispatch('TimelineSpace/NewTootModal/postToot', this.tootForm)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.tootForm.body = ''
|
this.tootForm.status = ''
|
||||||
this.$message({
|
this.$message({
|
||||||
message: 'Toot',
|
message: 'Toot',
|
||||||
type: 'success'
|
type: 'success'
|
||||||
@ -85,7 +85,7 @@ export default {
|
|||||||
.el-dialog__body {
|
.el-dialog__body {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
.body {
|
.status {
|
||||||
textarea {
|
textarea {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 5px 15px;
|
padding: 5px 15px;
|
||||||
|
@ -5,6 +5,7 @@ import Favourites from './TimelineSpace/Favourites'
|
|||||||
import Local from './TimelineSpace/Local'
|
import Local from './TimelineSpace/Local'
|
||||||
import Public from './TimelineSpace/Public'
|
import Public from './TimelineSpace/Public'
|
||||||
import Cards from './TimelineSpace/Cards'
|
import Cards from './TimelineSpace/Cards'
|
||||||
|
import NewTootModal from './TimelineSpace/NewTootModal'
|
||||||
import router from '../router'
|
import router from '../router'
|
||||||
|
|
||||||
const TimelineSpace = {
|
const TimelineSpace = {
|
||||||
@ -14,7 +15,8 @@ const TimelineSpace = {
|
|||||||
Favourites,
|
Favourites,
|
||||||
Local,
|
Local,
|
||||||
Public,
|
Public,
|
||||||
Cards
|
Cards,
|
||||||
|
NewTootModal
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
account: {
|
account: {
|
||||||
@ -24,7 +26,7 @@ const TimelineSpace = {
|
|||||||
username: '',
|
username: '',
|
||||||
homeTimeline: [],
|
homeTimeline: [],
|
||||||
notifications: [],
|
notifications: [],
|
||||||
newTootModal: false
|
replyToMessage: null
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
updateAccount (state, account) {
|
updateAccount (state, account) {
|
||||||
@ -45,9 +47,6 @@ const TimelineSpace = {
|
|||||||
insertNotifications (state, notifications) {
|
insertNotifications (state, notifications) {
|
||||||
state.notifications = state.notifications.concat(notifications)
|
state.notifications = state.notifications.concat(notifications)
|
||||||
},
|
},
|
||||||
changeNewTootModal (state, modal) {
|
|
||||||
state.newTootModal = modal
|
|
||||||
},
|
|
||||||
updateToot (state, message) {
|
updateToot (state, message) {
|
||||||
// Replace target message in homeTimeline and notifications
|
// Replace target message in homeTimeline and notifications
|
||||||
state.homeTimeline = state.homeTimeline.map((toot) => {
|
state.homeTimeline = state.homeTimeline.map((toot) => {
|
||||||
@ -68,6 +67,9 @@ const TimelineSpace = {
|
|||||||
return notification
|
return notification
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
setReplyTo (state, message) {
|
||||||
|
state.replyToMessage = message
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -124,7 +126,7 @@ const TimelineSpace = {
|
|||||||
},
|
},
|
||||||
watchShortcutEvents ({ commit }) {
|
watchShortcutEvents ({ commit }) {
|
||||||
ipcRenderer.on('CmdOrCtrl+N', () => {
|
ipcRenderer.on('CmdOrCtrl+N', () => {
|
||||||
commit('changeNewTootModal', true)
|
commit('TimelineSpace/NewTootModal/changeModal', true, { root: true })
|
||||||
})
|
})
|
||||||
ipcRenderer.on('CmdOrCtrl+R', () => {
|
ipcRenderer.on('CmdOrCtrl+R', () => {
|
||||||
// TODO: reply window
|
// TODO: reply window
|
||||||
@ -165,33 +167,15 @@ const TimelineSpace = {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
postToot ({ commit, state }, body) {
|
openReply ({ commit }, message) {
|
||||||
return new Promise((resolve, reject) => {
|
commit('setReplyTo', message)
|
||||||
if (state.account.accessToken === undefined || state.account.accessToken === null) {
|
commit('changeNewTootModal', true)
|
||||||
return reject(new AuthenticationError())
|
|
||||||
}
|
|
||||||
const client = new Mastodon(
|
|
||||||
{
|
|
||||||
access_token: state.account.accessToken,
|
|
||||||
api_url: state.account.baseURL + '/api/v1'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
client.post('/statuses', {
|
|
||||||
status: body
|
|
||||||
}, (err, data, res) => {
|
|
||||||
if (err) return reject(err)
|
|
||||||
commit('changeNewTootModal', false)
|
|
||||||
resolve(res)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TimelineSpace
|
export default TimelineSpace
|
||||||
|
|
||||||
class AuthenticationError {}
|
|
||||||
|
|
||||||
function buildNotification (notification) {
|
function buildNotification (notification) {
|
||||||
switch (notification.type) {
|
switch (notification.type) {
|
||||||
case 'favourite':
|
case 'favourite':
|
||||||
|
37
src/renderer/store/TimelineSpace/NewTootModal.js
Normal file
37
src/renderer/store/TimelineSpace/NewTootModal.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import Mastodon from 'mastodon-api'
|
||||||
|
|
||||||
|
const NewTootModal = {
|
||||||
|
namespaced: true,
|
||||||
|
state: {
|
||||||
|
modalOpen: false
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
changeModal (state, value) {
|
||||||
|
state.modalOpen = value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
postToot ({ state, commit, rootState }, form) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
|
||||||
|
return reject(new AuthenticationError())
|
||||||
|
}
|
||||||
|
const client = new Mastodon(
|
||||||
|
{
|
||||||
|
access_token: rootState.TimelineSpace.account.accessToken,
|
||||||
|
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
client.post('/statuses', form, (err, data, res) => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
commit('changeModal', false)
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NewTootModal
|
||||||
|
|
||||||
|
class AuthenticationError {}
|
Loading…
x
Reference in New Issue
Block a user