Merge pull request #759 from amyspark/add-search-toot

Enable searching toots by link
This commit is contained in:
AkiraFukushima 2018-12-01 23:09:50 +09:00 committed by GitHub
commit f020f2e553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 90 additions and 8 deletions

View File

@ -274,7 +274,8 @@
"search": {
"search": "Suche",
"account": "Konto",
"keyword": "stichwort"
"keyword": "stichwort",
"toot": "Toot"
},
"lists": {
"index": {

View File

@ -295,7 +295,8 @@
"search": "Search",
"account": "Account",
"tag": "Hashtag",
"keyword": "keyword"
"keyword": "keyword",
"toot": "Toot"
},
"lists": {
"index": {

View File

@ -274,7 +274,8 @@
"search": {
"search": "Rechercher",
"account": "Compte",
"keyword": "mot clé"
"keyword": "mot clé",
"toot": "Pouets"
},
"lists": {
"index": {

View File

@ -288,7 +288,8 @@
"search": "検索",
"account": "アカウント",
"tag": "ハッシュタグ",
"keyword": "キーワード"
"keyword": "キーワード",
"toot": "トゥート時"
},
"lists": {
"index": {

View File

@ -274,7 +274,8 @@
"search": {
"search": "검색",
"account": "계정",
"keyword": "키워드"
"keyword": "키워드",
"toot": "툿"
},
"lists": {
"index": {

View File

@ -274,7 +274,8 @@
"search": {
"search": "Szukaj",
"account": "Konta",
"keyword": "Słowo kluczowe"
"keyword": "Słowo kluczowe",
"toot": "Wpisy"
},
"lists": {
"index": {

View File

@ -17,6 +17,7 @@
<div class="search-result">
<search-account v-if="target==='account'"></search-account>
<search-tag v-else-if="target==='tag'"></search-tag>
<search-toots v-else-if="target==='toot'"></search-toots>
</div>
</div>
</template>
@ -25,10 +26,11 @@
import { mapState } from 'vuex'
import SearchAccount from './Search/Account'
import SearchTag from './Search/Tag'
import SearchToots from './Search/Toots'
export default {
name: 'search',
components: { SearchAccount, SearchTag },
components: { SearchAccount, SearchTag, SearchToots },
data () {
return {
target: 'account',
@ -50,6 +52,10 @@ export default {
{
target: 'tag',
label: this.$t('search.tag')
},
{
target: 'toot',
label: this.$t('search.toot')
}
]
}
@ -76,6 +82,15 @@ export default {
})
})
break
case 'toot':
this.$store.dispatch('TimelineSpace/Contents/Search/Toots/search', this.query)
.catch(() => {
this.$message({
message: this.$t('message.search_error'),
type: 'error'
})
})
break
default:
break
}

View File

@ -0,0 +1,28 @@
<template>
<div id="search_account">
<div v-bind:key="message.uri + message.id" v-for="message in results">
<toot :message="message"></toot>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import Toot from '~/src/renderer/components/molecules/Toot'
export default {
name: 'search-account',
components: { Toot },
computed: {
...mapState({
results: state => state.TimelineSpace.Contents.Search.Toots.results
})
},
destroyed () {
this.$store.commit('TimelineSpace/Contents/Search/Toots/updateResults', [])
}
}
</script>
<style lang="scss" scoped>
</style>

View File

@ -1,9 +1,10 @@
import Account from './Search/Account'
import Tag from './Search/Tag'
import Toots from './Search/Toots'
const Search = {
namespaced: true,
modules: { Account, Tag },
modules: { Account, Tag, Toots },
state: {
loading: false
},

View File

@ -0,0 +1,32 @@
import Mastodon from 'megalodon'
const Toots = {
namespaced: true,
state: {
results: []
},
mutations: {
updateResults (state, results) {
state.results = results
}
},
actions: {
search ({ state, commit, rootState }, query) {
commit('TimelineSpace/Contents/Search/changeLoading', true, { root: true })
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/search', { q: query, resolve: true })
.then(res => {
commit('updateResults', res.data.statuses)
return res.data
})
.finally(() => {
commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
})
}
}
}
export default Toots