mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: remove /user/search
This commit is contained in:
1 parent
6762e22bae
commit
5c97bbf1ba
8 files changed
+74
-48
No files matched your search
@@ -1,11 +1,17 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import request from 'vj/utils/request';
|
||||
import api, { e } from 'vj/utils/api';
|
||||
import AutoComplete from './AutoComplete';
|
||||
|
||||
// eslint-disable-next-line prefer-arrow-callback
|
||||
const UserSelectAutoComplete = forwardRef(function UserSelectAutoComplete(props, ref) {
|
||||
const itemsFn = (query) => request.get('/user/search', { q: query });
|
||||
const itemsFn = (query) => api(e`
|
||||
users(search: ${query}) {
|
||||
_id
|
||||
uname
|
||||
avatarUrl
|
||||
}
|
||||
`, ['data', 'users']);
|
||||
|
||||
const itemText = (user) => user.uname || user;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
||||
import list from 'emojis-list';
|
||||
import keyword from 'emojis-keywords';
|
||||
import request from 'vj/utils/request';
|
||||
import api from 'vj/utils/api';
|
||||
import api, { e } from 'vj/utils/api';
|
||||
|
||||
const qqEmojies = [
|
||||
'weixiao',
|
||||
@@ -168,7 +167,13 @@ monaco.languages.registerCompletionItemProvider('markdown', {
|
||||
endColumn: word.endColumn,
|
||||
};
|
||||
if (prefix === '@') {
|
||||
const users = await request.get(`/user/search?q=${word.word}`);
|
||||
const users = await api(e`
|
||||
users(search: ${word.word}) {
|
||||
_id
|
||||
uname
|
||||
avatarUrl
|
||||
}
|
||||
`, ['data', 'users']);
|
||||
return {
|
||||
suggestions: users.map((i) => ({
|
||||
label: `@${i.uname} (UID=${i._id})`,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.21.5",
|
||||
"version": "4.21.6",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NamedPage } from 'vj/misc/Page';
|
||||
import request from 'vj/utils/request';
|
||||
import api, { e } from 'vj/utils/api';
|
||||
import loadReactRedux from 'vj/utils/loadReactRedux';
|
||||
import parseQueryString from 'vj/utils/parseQueryString';
|
||||
|
||||
@@ -79,16 +79,16 @@ const page = new NamedPage('home_messages', () => {
|
||||
*/
|
||||
async function loadSendTarget() {
|
||||
const queryString = parseQueryString();
|
||||
if (!queryString.target) {
|
||||
return;
|
||||
}
|
||||
const user = await request.get('/user/search', {
|
||||
q: queryString.target,
|
||||
exact_match: true,
|
||||
});
|
||||
if (!user || user.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (!queryString.target) return;
|
||||
const user = await api(e`
|
||||
users(search: ${queryString.target}, exact: true) {
|
||||
_id
|
||||
uname
|
||||
avatarUrl
|
||||
mail
|
||||
}
|
||||
`, ['data', 'users']);
|
||||
if (!user?.length) return;
|
||||
createDialog(user[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<span class="icon icon-edit"></span>
|
||||
</a>
|
||||
{% endif %}
|
||||
<a class="profile-header__contact-item" href="{{ url('home_messages', query={target_uid:udoc._id}) }}" target="_blank" data-tooltip="{{ _('Send Message') }}">
|
||||
<a class="profile-header__contact-item" href="{{ url('home_messages', query={target:udoc._id}) }}" target="_blank" data-tooltip="{{ _('Send Message') }}">
|
||||
<span class="icon icon-comment--multiple"></span>
|
||||
</a>
|
||||
{% if udoc['mail'] %}
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
import request from './request';
|
||||
|
||||
export default (q: string) => request.post('/api', { query: q.trim() });
|
||||
export default async (q: string, path: string[] = []) => {
|
||||
let query = q.trim();
|
||||
if (!query.startsWith('query')) query = `query{${query}}`;
|
||||
const res = await request.post('/api', { query });
|
||||
if (res.errors) throw new Error(res.errors[0].message);
|
||||
let cursor = res;
|
||||
for (const p of path) {
|
||||
cursor = cursor[p];
|
||||
if (!cursor) return undefined;
|
||||
}
|
||||
return cursor;
|
||||
};
|
||||
|
||||
export const e = (
|
||||
pieces: TemplateStringsArray,
|
||||
...templates: (string | number)[]
|
||||
) => {
|
||||
let res = '';
|
||||
for (let i = 0; i < pieces.length; i++) {
|
||||
res += pieces[i];
|
||||
if (templates[i]) res += JSON.stringify(templates[i]);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
Reference in new issue
Block a user