From e941846c015dc0a068ed4404e9e2479a2dbc11bd Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sat, 6 Apr 2019 23:32:52 +0900
Subject: [PATCH] refs #850 Replace Toot with typescript
---
src/renderer/store/molecules/Toot.js | 74 ----------------------------
src/renderer/store/molecules/Toot.ts | 70 ++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 74 deletions(-)
delete mode 100644 src/renderer/store/molecules/Toot.js
create mode 100644 src/renderer/store/molecules/Toot.ts
diff --git a/src/renderer/store/molecules/Toot.js b/src/renderer/store/molecules/Toot.js
deleted file mode 100644
index aac7ab27..00000000
--- a/src/renderer/store/molecules/Toot.js
+++ /dev/null
@@ -1,74 +0,0 @@
-import Mastodon from 'megalodon'
-import { ipcRenderer } from 'electron'
-
-const Toot = {
- namespaced: true,
- state: {},
- mutations: {},
- actions: {
- reblog ({ rootState }, message) {
- const client = new Mastodon(
- rootState.TimelineSpace.account.accessToken,
- rootState.TimelineSpace.account.baseURL + '/api/v1'
- )
- return client.post(`/statuses/${message.id}/reblog`)
- .then(res => {
- // API returns new status when reblog.
- // Reblog target status is in the data.reblog.
- // So I send data.reblog as status for update local timeline.
- ipcRenderer.send('fav-rt-action-sound')
- return res.data.reblog
- })
- },
- unreblog ({ rootState }, message) {
- const client = new Mastodon(
- rootState.TimelineSpace.account.accessToken,
- rootState.TimelineSpace.account.baseURL + '/api/v1'
- )
- return client.post(`/statuses/${message.id}/unreblog`)
- .then(res => {
- return res.data
- })
- },
- addFavourite ({ rootState }, message) {
- const client = new Mastodon(
- rootState.TimelineSpace.account.accessToken,
- rootState.TimelineSpace.account.baseURL + '/api/v1'
- )
- return client.post(`/statuses/${message.id}/favourite`)
- .then(res => {
- ipcRenderer.send('fav-rt-action-sound')
- return res.data
- })
- },
- removeFavourite ({ rootState }, message) {
- const client = new Mastodon(
- rootState.TimelineSpace.account.accessToken,
- rootState.TimelineSpace.account.baseURL + '/api/v1'
- )
- return client.post(`/statuses/${message.id}/unfavourite`)
- .then(res => {
- return res.data
- })
- },
- deleteToot ({ rootState }, message) {
- const client = new Mastodon(
- rootState.TimelineSpace.account.accessToken,
- rootState.TimelineSpace.account.baseURL + '/api/v1'
- )
- return client.del(`/statuses/${message.id}`)
- .then(() => {
- return message
- })
- },
- block ({ rootState }, account) {
- const client = new Mastodon(
- rootState.TimelineSpace.account.accessToken,
- rootState.TimelineSpace.account.baseURL + '/api/v1'
- )
- return client.post(`/accounts/${account.id}/block`)
- }
- }
-}
-
-export default Toot
diff --git a/src/renderer/store/molecules/Toot.ts b/src/renderer/store/molecules/Toot.ts
new file mode 100644
index 00000000..a997facf
--- /dev/null
+++ b/src/renderer/store/molecules/Toot.ts
@@ -0,0 +1,70 @@
+import Mastodon, { Response, Status, Account } from 'megalodon'
+import { ipcRenderer } from 'electron'
+import { Module, ActionTree } from 'vuex'
+
+export interface TootState {}
+
+const state = (): TootState => ({})
+
+const actions: ActionTree = {
+ reblog: async ({ rootState }, message: Status) => {
+ const client = new Mastodon(
+ rootState.TimelineSpace.account.accessToken,
+ rootState.TimelineSpace.account.baseURL + '/api/v1'
+ )
+ const res: Response = await client.post(`/statuses/${message.id}/reblog`)
+ // API returns new status when reblog.
+ // Reblog target status is in the data.reblog.
+ // So I send data.reblog as status for update local timeline.
+ ipcRenderer.send('fav-rt-action-sound')
+ return res.data.reblog
+ },
+ unreblog: async ({ rootState }, message: Status) => {
+ const client = new Mastodon(
+ rootState.TimelineSpace.account.accessToken,
+ rootState.TimelineSpace.account.baseURL + '/api/v1'
+ )
+ const res: Response = await client.post(`/statuses/${message.id}/unreblog`)
+ return res.data
+ },
+ addFavourite: async ({ rootState }, message: Status) => {
+ const client = new Mastodon(
+ rootState.TimelineSpace.account.accessToken,
+ rootState.TimelineSpace.account.baseURL + '/api/v1'
+ )
+ const res: Response = await client.post(`/statuses/${message.id}/favourite`)
+ ipcRenderer.send('fav-rt-action-sound')
+ return res.data
+ },
+ removeFavourite: async ({ rootState }, message: Status) => {
+ const client = new Mastodon(
+ rootState.TimelineSpace.account.accessToken,
+ rootState.TimelineSpace.account.baseURL + '/api/v1'
+ )
+ const res: Response = await client.post(`/statuses/${message.id}/unfavourite`)
+ return res.data
+ },
+ deleteToot: async ({ rootState }, message: Status) => {
+ const client = new Mastodon(
+ rootState.TimelineSpace.account.accessToken,
+ rootState.TimelineSpace.account.baseURL + '/api/v1'
+ )
+ await client.del(`/statuses/${message.id}`)
+ return message
+ },
+ block: async ({ rootState }, account: Account) => {
+ const client = new Mastodon(
+ rootState.TimelineSpace.account.accessToken,
+ rootState.TimelineSpace.account.baseURL + '/api/v1'
+ )
+ return client.post(`/accounts/${account.id}/block`)
+ }
+}
+
+const Toot: Module = {
+ namespaced: true,
+ state: state,
+ actions: actions
+}
+
+export default Toot