1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-03 02:37:55 +01:00

refs #326 Open the manage lists window of an account on account profile

This commit is contained in:
AkiraFukushima 2018-06-16 01:08:34 +09:00
parent f843d3aa2f
commit 1546a728fe
7 changed files with 240 additions and 35 deletions

66
package-lock.json generated
View File

@ -419,7 +419,7 @@
"async": "2.6.0",
"buffer-crc32": "0.2.13",
"glob": "7.1.2",
"lodash": "4.17.5",
"lodash": "4.17.10",
"readable-stream": "2.3.5",
"tar-stream": "1.5.5",
"zip-stream": "1.2.0"
@ -434,7 +434,7 @@
"glob": "7.1.2",
"graceful-fs": "4.1.11",
"lazystream": "1.0.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"normalize-path": "2.1.1",
"readable-stream": "2.3.5"
}
@ -639,7 +639,7 @@
"resolved": "https://registry.npmjs.org/async/-/async-2.6.0.tgz",
"integrity": "sha512-xAfGg1/NTLBBKlHFmnd7PlmUW9KhVQIUuSrYem9xzFUZy13ScvtyGGejaae9iAVRiRq9+Cx7DPFaAAhCpyxyPw==",
"requires": {
"lodash": "4.17.5"
"lodash": "4.17.10"
}
},
"async-each": {
@ -781,7 +781,7 @@
"convert-source-map": "1.5.1",
"debug": "2.6.9",
"json5": "0.5.1",
"lodash": "4.17.5",
"lodash": "4.17.10",
"minimatch": "3.0.4",
"path-is-absolute": "1.0.1",
"private": "0.1.8",
@ -823,7 +823,7 @@
"babel-types": "6.26.0",
"detect-indent": "4.0.0",
"jsesc": "1.3.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"source-map": "0.5.7",
"trim-right": "1.0.1"
}
@ -871,7 +871,7 @@
"babel-helper-function-name": "6.24.1",
"babel-runtime": "6.26.0",
"babel-types": "6.26.0",
"lodash": "4.17.5"
"lodash": "4.17.10"
}
},
"babel-helper-evaluate-path": {
@ -978,7 +978,7 @@
"requires": {
"babel-runtime": "6.26.0",
"babel-types": "6.26.0",
"lodash": "4.17.5"
"lodash": "4.17.10"
}
},
"babel-helper-remap-async-to-generator": {
@ -1337,7 +1337,7 @@
"babel-template": "6.26.0",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"lodash": "4.17.5"
"lodash": "4.17.10"
}
},
"babel-plugin-transform-es2015-classes": {
@ -1826,7 +1826,7 @@
"babel-runtime": "6.26.0",
"core-js": "2.5.3",
"home-or-tmp": "2.0.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"mkdirp": "0.5.1",
"source-map-support": "0.4.18"
}
@ -1850,7 +1850,7 @@
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"lodash": "4.17.5"
"lodash": "4.17.10"
}
},
"babel-traverse": {
@ -1867,7 +1867,7 @@
"debug": "2.6.9",
"globals": "9.18.0",
"invariant": "2.2.3",
"lodash": "4.17.5"
"lodash": "4.17.10"
},
"dependencies": {
"debug": {
@ -1889,7 +1889,7 @@
"requires": {
"babel-runtime": "6.26.0",
"esutils": "2.0.2",
"lodash": "4.17.5",
"lodash": "4.17.10",
"to-fast-properties": "1.0.3"
}
},
@ -3204,7 +3204,7 @@
"integrity": "sha1-RYwH4J4NkA/Ci3Cj/sLazR0st/Y=",
"dev": true,
"requires": {
"lodash": "4.17.5"
"lodash": "4.17.10"
}
},
"combined-stream": {
@ -5069,7 +5069,7 @@
"integrity": "sha1-wNZizNAbxlZ9YHjxemhCrHQyjOQ=",
"requires": {
"async": "2.6.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"mkdirp": "0.5.1",
"rimraf": "2.6.2",
"rwlock": "5.0.0"
@ -5655,7 +5655,7 @@
"js-yaml": "3.11.0",
"json-stable-stringify-without-jsonify": "1.0.1",
"levn": "0.3.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"minimatch": "3.0.4",
"mkdirp": "0.5.1",
"natural-compare": "1.4.0",
@ -5856,7 +5856,7 @@
"eslint-import-resolver-node": "0.3.2",
"eslint-module-utils": "2.1.1",
"has": "1.0.1",
"lodash": "4.17.5",
"lodash": "4.17.10",
"minimatch": "3.0.4",
"read-pkg-up": "2.0.0"
},
@ -7616,7 +7616,7 @@
"dev": true,
"requires": {
"glob": "7.1.2",
"lodash": "4.17.5",
"lodash": "4.17.10",
"minimatch": "3.0.4"
}
},
@ -7950,7 +7950,7 @@
"dev": true,
"optional": true,
"requires": {
"lodash": "4.17.5",
"lodash": "4.17.10",
"request": "2.85.0"
}
},
@ -8049,7 +8049,7 @@
"bluebird": "3.5.1",
"html-minifier": "3.5.12",
"loader-utils": "0.2.17",
"lodash": "4.17.5",
"lodash": "4.17.10",
"pretty-error": "2.1.1",
"toposort": "1.0.6"
},
@ -8142,7 +8142,7 @@
"requires": {
"http-proxy": "1.16.2",
"is-glob": "3.1.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"micromatch": "2.3.11"
},
"dependencies": {
@ -8387,7 +8387,7 @@
"cli-width": "2.2.0",
"external-editor": "2.1.0",
"figures": "2.0.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"mute-stream": "0.0.7",
"run-async": "2.3.0",
"rx-lite": "4.0.8",
@ -9241,7 +9241,7 @@
"graceful-fs": "4.1.11",
"http-proxy": "1.16.2",
"isbinaryfile": "3.0.2",
"lodash": "4.17.5",
"lodash": "4.17.10",
"log4js": "2.6.1",
"mime": "1.6.0",
"minimatch": "3.0.4",
@ -9284,7 +9284,7 @@
"requires": {
"dateformat": "1.0.12",
"istanbul": "0.4.5",
"lodash": "4.17.5",
"lodash": "4.17.10",
"minimatch": "3.0.4",
"source-map": "0.5.7"
}
@ -9354,7 +9354,7 @@
"async": "2.6.0",
"babel-runtime": "6.26.0",
"loader-utils": "1.1.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"source-map": "0.5.7",
"webpack-dev-middleware": "1.12.2"
}
@ -9597,9 +9597,9 @@
}
},
"lodash": {
"version": "4.17.5",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw=="
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
},
"lodash._arraycopy": {
"version": "3.0.0",
@ -11659,7 +11659,7 @@
"cli-width": "2.2.0",
"external-editor": "2.1.0",
"figures": "2.0.0",
"lodash": "4.17.5",
"lodash": "4.17.10",
"mute-stream": "0.0.7",
"run-async": "2.3.0",
"rx": "4.1.0",
@ -13674,7 +13674,7 @@
"optional": true,
"requires": {
"extend": "3.0.1",
"lodash": "4.17.5",
"lodash": "4.17.10",
"request": "2.85.0",
"when": "3.7.8"
}
@ -13886,7 +13886,7 @@
"dev": true,
"requires": {
"glob": "7.1.2",
"lodash": "4.17.5",
"lodash": "4.17.10",
"scss-tokenizer": "0.2.3",
"yargs": "7.1.0"
},
@ -15148,7 +15148,7 @@
"ajv": "5.5.2",
"ajv-keywords": "2.1.1",
"chalk": "2.3.2",
"lodash": "4.17.5",
"lodash": "4.17.10",
"slice-ansi": "1.0.0",
"string-width": "2.1.1"
},
@ -17646,7 +17646,7 @@
"integrity": "sha512-/0QYwW/H1N/CdXYA2PNPVbsxO3u2Fpz34vs72xm03SRfg6bMNGfMJIQEpQjKRvkG2JvT6oRJFpDtSrwbX8Jzvw==",
"dev": true,
"requires": {
"lodash": "4.17.5"
"lodash": "4.17.10"
}
},
"webpack-obfuscator": {
@ -17999,7 +17999,7 @@
"requires": {
"archiver-utils": "1.3.0",
"compress-commons": "1.2.2",
"lodash": "4.17.5",
"lodash": "4.17.10",
"readable-stream": "2.3.5"
}
}

View File

@ -96,6 +96,7 @@
"hawk": "^7.0.7",
"hoek": "^5.0.3",
"is-empty": "^1.2.0",
"lodash": "^4.17.10",
"megalodon": "^0.1.1",
"moment": "^2.21.0",
"mousetrap": "^1.6.2",

View File

@ -30,6 +30,9 @@
<li role="button" @click="openBrowser(account)">
Open in Browser
</li>
<li role="button" @click="addToList(account)">
Manage List Memeberships
</li>
</ul>
</div>
@ -157,6 +160,10 @@ export default {
},
openBrowser (account) {
shell.openExternal(account.url)
},
addToList (account) {
this.$store.dispatch('TimelineSpace/Modals/ListMembership/setAccount', account)
this.$store.dispatch('TimelineSpace/Modals/ListMembership/changeModal', true)
}
}
}

View File

@ -3,6 +3,7 @@
<new-toot></new-toot>
<jump></jump>
<image-viewer></image-viewer>
<list-membership></list-membership>
</div>
</template>
@ -10,13 +11,15 @@
import NewToot from './Modals/NewToot'
import Jump from './Modals/Jump'
import ImageViewer from './Modals/ImageViewer'
import ListMembership from './Modals/ListMembership'
export default {
name: 'modals',
components: {
NewToot,
Jump,
ImageViewer
ImageViewer,
ListMembership
}
}
</script>

View File

@ -0,0 +1,112 @@
<template>
<el-dialog
title="List Memberships"
:visible.sync="listMembershipModal"
width="400px"
class="list-membership-modal"
>
<el-checkbox-group v-model="belongToLists" v-loading="loading">
<table class="lists">
<tbody>
<tr v-for="list in lists" :key="list.id">
<td>
<el-checkbox :label="list.id">{{ list.title }}</el-checkbox>
</td>
</tr>
</tbody>
</table>
</el-checkbox-group>
</el-dialog>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'list-membership',
data () {
return {
loading: false
}
},
computed: {
...mapState({
account: state => state.TimelineSpace.Modals.ListMembership.account,
lists: state => state.TimelineSpace.Modals.ListMembership.lists
}),
listMembershipModal: {
get () {
return this.$store.state.TimelineSpace.Modals.ListMembership.modalOpen
},
set (value) {
this.$store.dispatch('TimelineSpace/Modals/ListMembership/changeModal', value)
}
},
belongToLists: {
get () {
return this.$store.state.TimelineSpace.Modals.ListMembership.belongToLists
},
set (value) {
return this.$store.dispatch('TimelineSpace/Modals/ListMembership/changeBelongToLists', value)
.catch(() => {
this.$message({
message: 'Failed to update list memberships',
type: 'error'
})
})
}
}
},
watch: {
listMembershipModal: function (newState, oldState) {
if (!oldState && newState) {
this.init()
}
}
},
methods: {
async init () {
this.loading = true
try {
await this.$store.dispatch('TimelineSpace/Modals/ListMembership/fetchListMembership', this.account)
await this.$store.dispatch('TimelineSpace/Modals/ListMembership/fetchLists')
} catch (err) {
this.$message({
message: 'Failed to fetch list',
type: 'error'
})
} finally {
this.loading = false
}
}
}
}
</script>
<style lang="scss" scoped>
.lists {
text-align: left;
border-collapse: collapse;
width: 100%;
tr {
border-bottom: solid 1px #ebeef5;
&:first-child {
border-top: solid 1px #ebeef5;
}
&:nth-child(even) {
background-color: #fafafa;
}
&:hover {
background-color: #f2f6fc;
}
td {
padding: 4px 8px;
}
}
}
</style>

View File

@ -1,13 +1,15 @@
import NewToot from './Modals/NewToot'
import ImageViewer from './Modals/ImageViewer'
import Jump from './Modals/Jump'
import ListMembership from './Modals/ListMembership'
const Modals = {
namespaced: true,
modules: {
ImageViewer,
NewToot,
Jump
Jump,
ListMembership
}
}

View File

@ -0,0 +1,80 @@
import Mastodon from 'megalodon'
import _ from 'lodash'
const ListMembership = {
namespaced: true,
state: {
modalOpen: false,
account: null,
lists: [],
belongToLists: []
},
mutations: {
changeModal (state, value) {
state.modalOpen = value
},
changeAccount (state, account) {
state.account = account
},
changeBelongToLists (state, lists) {
state.belongToLists = lists
},
changeLists (state, lists) {
state.lists = lists
}
},
actions: {
changeModal ({ commit }, value) {
commit('changeModal', value)
},
setAccount ({ commit }, account) {
commit('changeAccount', account)
},
fetchListMembership ({ commit, rootState }, account) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/accounts/${account.id}/lists`)
.then(data => {
commit('changeBelongToLists', data.map(l => l.id))
return data
})
},
fetchLists ({ commit, rootState }) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/lists')
.then(data => {
commit('changeLists', data)
return data
})
},
async changeBelongToLists ({ rootState, commit, state }, belongToLists) {
// Calcurate diff
const removedLists = _.difference(state.belongToLists, belongToLists)
const addedLists = _.difference(belongToLists, state.belongToLists)
commit('changeBelongToLists', belongToLists)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const removedPromise = removedLists.map(id => {
return client.del(`/lists/${id}/accounts`, {
account_ids: [state.account.id]
})
})
const addedPromise = addedLists.map(id => {
return client.post(`/lists/${id}/accounts`, {
account_ids: [state.account.id]
})
})
const res = await Promise.all(removedPromise.concat(addedPromise))
return res
}
}
}
export default ListMembership