-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from h3poteto/iss-165
closes #165 Search page to find account
- Loading branch information
Showing
9 changed files
with
222 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/renderer/components/TimelineSpace/Contents/Search.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<template> | ||
<div id="search" :style="theme"> | ||
<div class="search-header" v-loading="loading" :element-loading-background="loadingBackground"> | ||
<el-form :inline="true"> | ||
<el-select v-model="target" placeholder="search" class="search-target"> | ||
<el-option | ||
v-for="item in searchTargets" | ||
:key="item.target" | ||
:label="item.label" | ||
:value="item.target"> | ||
</el-option> | ||
</el-select> | ||
<input v-model="query" placeholder="keyword" class="search-keyword" v-shortkey="['enter']" @shortkey="search" autofocus></input> | ||
<div class="clearfix"></div> | ||
</el-form> | ||
</div> | ||
<div class="search-result"> | ||
<search-account></search-account> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapState } from 'vuex' | ||
import SearchAccount from './Search/Account' | ||
export default { | ||
name: 'search', | ||
components: { SearchAccount }, | ||
data () { | ||
return { | ||
target: 'account', | ||
searchTargets: [ | ||
{ | ||
target: 'account', | ||
label: 'Account' | ||
} | ||
], | ||
query: '' | ||
} | ||
}, | ||
computed: { | ||
...mapState({ | ||
loading: state => state.TimelineSpace.Contents.Search.loading, | ||
loadingBackground: state => state.App.theme.wrapper_mask_color, | ||
theme: (state) => { | ||
return { | ||
'--theme-background-color': state.App.theme.background_color, | ||
'--theme-selected-background-color': state.App.theme.selected_background_color, | ||
'--theme-primary-color': state.App.theme.primary_color | ||
} | ||
} | ||
}) | ||
}, | ||
methods: { | ||
search () { | ||
switch (this.target) { | ||
case 'account': | ||
this.$store.dispatch('TimelineSpace/Contents/Search/Account/search', this.query) | ||
.catch(() => { | ||
this.$message({ | ||
message: 'Could not search', | ||
type: 'error' | ||
}) | ||
}) | ||
break | ||
default: | ||
break | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
#search { | ||
--theme-background-color: #ffffff; | ||
--theme-selected-background-color: #f2f6fc; | ||
--theme-primary-color: #303133; | ||
--theme-border-color: #ebeef5; | ||
border-top: 1px solid var(--theme-border-color); | ||
.search-header { | ||
background-color: var(--theme-selected-background-color); | ||
padding: 8px 12px; | ||
.search-target /deep/ { | ||
float: left; | ||
width: 20%; | ||
.el-input__inner { | ||
background-color: var(--theme-background-color); | ||
border: none; | ||
border-radius: 4px 0 0 4px; | ||
color: var(--theme-primary-color); | ||
} | ||
} | ||
.search-keyword { | ||
float: left; | ||
width: 80%; | ||
background-color: var(--theme-background-color); | ||
border: none; | ||
border-radius: 0 4px 4px 0; | ||
color: var(--theme-primary-color); | ||
line-height: 40px; | ||
height: 40px; | ||
padding: 0 15px; | ||
outline: 0; | ||
font-size: 14px; | ||
box-sizing: border-box; | ||
} | ||
} | ||
} | ||
</style> |
25 changes: 25 additions & 0 deletions
25
src/renderer/components/TimelineSpace/Contents/Search/Account.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<template> | ||
<div id="search_account"> | ||
<template v-for="account in results"> | ||
<user :user="account"></user> | ||
</template> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapState } from 'vuex' | ||
import User from '../Cards/User' | ||
export default { | ||
name: 'search-account', | ||
components: { User }, | ||
computed: { | ||
...mapState({ | ||
results: state => state.TimelineSpace.Contents.Search.Account.results | ||
}) | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Account from './Search/Account' | ||
|
||
const Search = { | ||
namespaced: true, | ||
modules: { Account }, | ||
state: { | ||
loading: false | ||
}, | ||
mutations: { | ||
changeLoading (state, loading) { | ||
state.loading = loading | ||
} | ||
}, | ||
actions: {} | ||
} | ||
|
||
export default Search |
33 changes: 33 additions & 0 deletions
33
src/renderer/store/TimelineSpace/Contents/Search/Account.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Mastodon from 'mastodon-api' | ||
|
||
const Account = { | ||
namespaced: true, | ||
state: { | ||
results: [] | ||
}, | ||
mutations: { | ||
updateResults (state, results) { | ||
state.results = results | ||
} | ||
}, | ||
actions: { | ||
search ({ state, commit, rootState }, query) { | ||
return new Promise((resolve, reject) => { | ||
commit('TimelineSpace/Contents/Search/changeLoading', true, { root: true }) | ||
const client = new Mastodon( | ||
{ | ||
access_token: rootState.TimelineSpace.account.accessToken, | ||
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1' | ||
}) | ||
client.get('/search', { q: query }, (err, data, res) => { | ||
if (err) return reject(err) | ||
commit('updateResults', data.accounts) | ||
commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true }) | ||
resolve(res) | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
export default Account |