parent
609ad40736
commit
c34eebff6c
@ -0,0 +1,33 @@
|
||||
import UserCard from '../user_card/user_card.vue'
|
||||
import userSearchApi from '../../services/new_api/user_search.js'
|
||||
const userSearch = {
|
||||
components: {
|
||||
UserCard
|
||||
},
|
||||
props: [
|
||||
'query'
|
||||
],
|
||||
data () {
|
||||
return {
|
||||
users: []
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.search(this.query)
|
||||
},
|
||||
watch: {
|
||||
query (newV) {
|
||||
this.search(newV)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
search (query) {
|
||||
userSearchApi.search({query, store: this.$store})
|
||||
.then((res) => {
|
||||
this.users = res
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default userSearch
|
@ -0,0 +1,12 @@
|
||||
<template>
|
||||
<div class="user-seach panel panel-default">
|
||||
<div class="panel-heading">
|
||||
{{$t('nav.user_search')}}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<user-card v-for="user in users" :key="user.id" :user="user" :showFollows="true"></user-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script src="./user_search.js"></script>
|
@ -0,0 +1,16 @@
|
||||
import utils from './utils.js'
|
||||
|
||||
const search = ({query, store}) => {
|
||||
return utils.request({
|
||||
store,
|
||||
url: '/api/pleroma/search_user',
|
||||
params: {
|
||||
query
|
||||
}
|
||||
}).then((data) => data.json())
|
||||
}
|
||||
const UserSearch = {
|
||||
search
|
||||
}
|
||||
|
||||
export default UserSearch
|
@ -0,0 +1,36 @@
|
||||
const queryParams = (params) => {
|
||||
return Object.keys(params)
|
||||
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
|
||||
.join('&')
|
||||
}
|
||||
|
||||
const headers = (store) => {
|
||||
const accessToken = store.state.oauth.token
|
||||
if (accessToken) {
|
||||
return {'Authorization': `Bearer ${accessToken}`}
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
const request = ({method = 'GET', url, params, store}) => {
|
||||
const instance = store.state.instance.server
|
||||
let fullUrl = `${instance}${url}`
|
||||
|
||||
if (method === 'GET' && params) {
|
||||
fullUrl = fullUrl + `?${queryParams(params)}`
|
||||
}
|
||||
|
||||
return window.fetch(fullUrl, {
|
||||
method,
|
||||
headers: headers(store),
|
||||
credentials: 'same-origin'
|
||||
})
|
||||
}
|
||||
|
||||
const utils = {
|
||||
queryParams,
|
||||
request
|
||||
}
|
||||
|
||||
export default utils
|
Loading…
Reference in new issue