commit: 3263aa323c8b1bfa6375251eca66d9de6956a1d6
parent: 609ad407362844977746babdd088b7600af5982d
Author: lambda <pleromagit@rogerbraun.net>
Date: Fri, 16 Nov 2018 18:14:16 +0000
Merge branch 'feature/user-search' into 'develop'
Add actual user search.
See merge request pleroma/pleroma-fe!376
Diffstat:
8 files changed, 103 insertions(+), 22 deletions(-)
diff --git a/src/boot/after_store.js b/src/boot/after_store.js
@@ -15,6 +15,7 @@ import Registration from '../components/registration/registration.vue'
import UserSettings from '../components/user_settings/user_settings.vue'
import FollowRequests from '../components/follow_requests/follow_requests.vue'
import OAuthCallback from '../components/oauth_callback/oauth_callback.vue'
+import UserSearch from '../components/user_search/user_search.vue'
const afterStoreSetup = ({store, i18n}) => {
window.fetch('/api/statusnet/config.json')
@@ -95,7 +96,8 @@ const afterStoreSetup = ({store, i18n}) => {
{ name: 'registration', path: '/registration/:token', component: Registration },
{ name: 'friend-requests', path: '/friend-requests', component: FollowRequests },
{ name: 'user-settings', path: '/user-settings', component: UserSettings },
- { name: 'oauth-callback', path: '/oauth-callback', component: OAuthCallback, props: (route) => ({ code: route.query.code }) }
+ { name: 'oauth-callback', path: '/oauth-callback', component: OAuthCallback, props: (route) => ({ code: route.query.code }) },
+ { name: 'user-search', path: '/user-search', component: UserSearch, props: (route) => ({ query: route.query.query }) }
]
const router = new VueRouter({
diff --git a/src/components/user_finder/user_finder.js b/src/components/user_finder/user_finder.js
@@ -7,25 +7,10 @@ const UserFinder = {
}),
methods: {
findUser (username) {
- username = username[0] === '@' ? username.slice(1) : username
- this.loading = true
- this.$store.state.api.backendInteractor.externalProfile(username)
- .then((user) => {
- this.loading = false
- this.hidden = true
- if (!user.error) {
- this.$store.commit('addNewUsers', [user])
- this.$router.push({name: 'user-profile', params: {id: user.id}})
- } else {
- this.error = true
- }
- })
+ this.$router.push({ name: 'user-search', query: { query: username } })
},
toggleHidden () {
this.hidden = !this.hidden
- },
- dismissError () {
- this.error = false
}
}
}
diff --git a/src/components/user_finder/user_finder.vue b/src/components/user_finder/user_finder.vue
@@ -1,9 +1,5 @@
<template>
<span class="user-finder-container">
- <span class="alert error" v-if="error">
- <i class="icon-cancel user-finder-icon" @click="dismissError"/>
- {{$t('finder.error_fetching_user')}}
- </span>
<i class="icon-spin4 user-finder-icon animate-spin-slow" v-if="loading" />
<a href="#" v-if="hidden"><i class="icon-user-plus user-finder-icon" @click.prevent.stop="toggleHidden"/></a>
<span v-else>
diff --git a/src/components/user_search/user_search.js b/src/components/user_search/user_search.js
@@ -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
diff --git a/src/components/user_search/user_search.vue b/src/components/user_search/user_search.vue
@@ -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>
diff --git a/src/i18n/en.json b/src/i18n/en.json
@@ -35,7 +35,8 @@
"dms": "Direct Messages",
"public_tl": "Public Timeline",
"timeline": "Timeline",
- "twkn": "The Whole Known Network"
+ "twkn": "The Whole Known Network",
+ "user_search": "User Search"
},
"notifications": {
"broken_favorite": "Unknown status, searching for it...",
diff --git a/src/services/new_api/user_search.js b/src/services/new_api/user_search.js
@@ -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
diff --git a/src/services/new_api/utils.js b/src/services/new_api/utils.js
@@ -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