core&ui: add problems gql to fix autocomplete (#389)

pull/392/head
panda 2 years ago committed by GitHub
parent 4b3c57549a
commit a52c488e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.14.16",
"version": "3.14.17",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",

@ -80,6 +80,11 @@ registerResolver(
return pdoc;
},
);
registerResolver('Query', 'problems(ids: [Int])', '[Problem]', async (arg, ctx) => {
const res = await problem.getList(ctx.args.domainId, arg.ids, ctx.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || ctx.user._id,
ctx.user.group, undefined, undefined, true);
return Object.keys(res).map((id) => res[+id]);
}, 'Get a list of problem by ids');
registerResolver(
'Problem', 'manage', 'ProblemManage',
(arg, ctx) => {

@ -488,7 +488,8 @@ export async function get(domainId: string, tid: ObjectID): Promise<Tdoc<30>> {
}
export async function getRelated(domainId: string, pid: number) {
return await document.getMulti(domainId, document.TYPE_CONTEST, { pids: pid }).toArray();
const rules = Object.keys(RULES).filter((i) => !RULES[i].hidden);
return await document.getMulti(domainId, document.TYPE_CONTEST, { pids: pid, rule: { $in: rules } }).toArray();
}
export async function getStatus(domainId: string, tid: ObjectID, uid: number) {

@ -1,5 +1,6 @@
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import api, { gql } from 'vj/utils/api';
import request from 'vj/utils/request';
import type { ProblemDoc } from 'hydrooj/src/interface';
import AutoComplete, { AutoCompleteHandle, AutoCompleteProps } from './AutoComplete';
@ -9,8 +10,13 @@ const ProblemSelectAutoComplete = forwardRef<AutoCompleteHandle<ProblemDoc>, Aut
ref={ref as any}
cacheKey={`problem-${UiContext.domainId}`}
queryItems={(query) => request.get(`/d/${UiContext.domainId}/problem/list`, { prefix: query })}
// FIXME fetch items
fetchItems={(ids) => ids.map((id) => ({ docId: id, pid: id, title: id }) as any)}
fetchItems={(ids) => api(gql`
problems(ids: ${ids.map((i) => +i)}) {
docId
pid
title
}
`, ['data', 'problems'])}
itemText={(pdoc) => `${`${pdoc.docId} ${pdoc.title}`}`}
itemKey={(pdoc) => `${pdoc.docId || pdoc}`}
renderItem={(pdoc) => (

@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.38.16",
"version": "4.38.17",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",

Loading…
Cancel
Save